Python NLTK Wordnet Issue

119 views Asked by At

Code Used

augmenter = naw.SynonymAug(aug_src='wordnet', model_path=None, name='Synonym_Aug', aug_min=1, aug_max=10, aug_p=0.3, lang='eng', 
                         stopwords=stop_words, tokenizer=None, reverse_tokenizer=None, stopwords_regex=None, force_reload=False, verbose=0)

augmenter.augment("What is random swap")

Getting the error

Resource 'corpora/wordnet' not found.  Please use the NLTK
  Downloader to obtain the resource:  >>> nltk.download()
  Searched in:
    - '/root/nltk_data'
    - '/usr/share/nltk_data'
    - '/usr/local/share/nltk_data'
    - '/usr/lib/nltk_data'
    - '/usr/local/lib/nltk_data'
**********************************************************************

I've done everything- Updated the package, reinstalled this even checked this in corpora folder within nltk_data. Nothing is working. Same error comes again and again. Can someone please help me understand what I'm doing incorrectly.

Referred many documentation on this error which mostly talked about issue with the directory path or wordnet not being there. But these also did not help.

1

There are 1 answers

1
Faizan On

Error explains that you have installed nltk package but you've not downloaded 'wordnet' since you're using it in the code.

  1. Open python console
>>> import nltk
>>> nltk.download('wordnet')

and it will work .

OR

  1. In your code file:
import nltk

# Set the download directory
nltk.download('wordnet', download_dir='/path/to/download/directory')