Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

LookupError Traceback (most recent call last) File…

  1. User

    LookupError Traceback (most recent call last) File /online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/lib/python3.10/site-packages/nltk/corpus/util.py:84, in LazyCorpusLoader.__load(self) 83 try: ---> 84 root = nltk.data.find(f"{self.subdir}/{zip_name}") 85 except LookupError:

    File /online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/lib/python3.10/site-packages/nltk/data.py:583, in find(resource_name, paths) 582 resource_not_found = f"\n{sep}\n{msg}\n{sep}\n" --> 583 raise LookupError(resource_not_found)

    LookupError:


    Resource stopwords not found. Please use the NLTK Downloader to obtain the resource:

    import nltk nltk.download('stopwords')

    For more information see: https://www.nltk.org/data.html

    Attempted to load corpora/stopwords.zip/stopwords/

    Searched in: - '/home/export/base/ycsc_qiuzhen/qiuzhen29/nltk_data' - '/online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/nltk_data' - '/online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/share/nltk_data' - '/online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/lib/nltk_data' - '/usr/share/nltk_data' - '/usr/local/share/nltk_data' - '/usr/lib/nltk_data' - '/usr/local/lib/nltk_data'


    During handling of the above exception, another exception occurred:

    LookupError Traceback (most recent call last) Cell In[1], line 16 14 from nltk.tokenize import word_tokenize, sent_tokenize 15 from nltk.corpus import stopwords ---> 16 stopwords = set(stopwords.words('english')) 17 from nltk.stem.wordnet import WordNetLemmatizer 19 # pytorch

    File /online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/lib/python3.10/site-packages/nltk/corpus/util.py:121, in LazyCorpusLoader.getattr(self, attr) 118 if attr == "bases": 119 raise AttributeError("LazyCorpusLoader object has no attribute 'bases'") --> 121 self.__load() 122 # This looks circular, but its not, since __load() changes our 123 # class to something new: 124 return getattr(self, attr)

    File /online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/lib/python3.10/site-packages/nltk/corpus/util.py:86, in LazyCorpusLoader.__load(self) 84 root = nltk.data.find(f"{self.subdir}/{zip_name}") 85 except LookupError: ---> 86 raise e 88 # Load the corpus. 89 corpus = self.__reader_cls(root, *self.__args, **self.__kwargs)

    File /online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/lib/python3.10/site-packages/nltk/corpus/util.py:81, in LazyCorpusLoader.__load(self) 79 else: 80 try: ---> 81 root = nltk.data.find(f"{self.subdir}/{self.__name}") 82 except LookupError as e: 83 try:

    File /online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/lib/python3.10/site-packages/nltk/data.py:583, in find(resource_name, paths) 581 sep = "*" * 70 582 resource_not_found = f"\n{sep}\n{msg}\n{sep}\n" --> 583 raise LookupError(resource_not_found)

    LookupError:


    Resource stopwords not found. Please use the NLTK Downloader to obtain the resource:

    import nltk nltk.download('stopwords')

    For more information see: https://www.nltk.org/data.html

    Attempted to load corpora/stopwords

    Searched in: - '/home/export/base/ycsc_qiuzhen/qiuzhen29/nltk_data' - '/online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/nltk_data' - '/online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/share/nltk_data' - '/online1/public/support/amd/miniconda3/4.9.2/envs/qiuzhen/lib/nltk_data' - '/usr/share/nltk_data' - '/usr/local/share/nltk_data' - '/usr/lib/nltk_data' - '/usr/local/lib/nltk_data'

  2. Assistant

    The error message you're seeing indicates that the NLTK stopwords corpus is not found on your system. This can be resolved by downloading the NLTK stopwords dataset. You can do this using NLTK's download function. Below, I've provided instructions and a snippet of code to help you fix this issue.

    1. Import NLTK and Download the Stopwords Dataset:

      You need to download the stopwords dataset from NLTK. To do this, run the following code:

      import nltk
      
      # Download the stopwords dataset
      nltk.download('stopwords')
      

      This should download the required dataset and resolve the lookup error.

    2. Update Your Existing Code:

      After downloading the stopwords dataset, your original code should work as expected.

    Here is how your existing code would integrate the download step:

    import nltk
    # Download the stopwords dataset
    nltk.download('stopwords')
    
    from nltk.tokenize import word_tokenize, sent_tokenize
    from nltk.corpus import stopwords
    
    # Load the stopwords for English
    stopwords = set(stopwords.words('english'))
    
    from nltk.stem.wordnet import WordNetLemmatizer
    
    # your other code...
    

    By including the nltk.download('stopwords') line, you ensure that the stopwords dataset is available no matter where the code is executed. This should resolve the LookupError you're encountering.