尽管成功下载资源,WordNet Lemmatizer 的 NLTK 中仍出现查找错误

问题描述 投票:0回答:1

我正在 Kaggle 笔记本中执行文本处理任务,并在使用 NLTK 的

LookupError
时面临
WordNetLemmatizer
。尽管我努力下载所需的 NLTK 资源,但错误仍然发生。下面,我提供了预处理函数的详细信息、错误消息以及解决问题所采取的步骤。

预处理功能:

def preprocess_str_ml(txt):
    tokenizer = TweetTokenizer()
    lemmatizer = WordNetLemmatizer()
    
    # convert all characters in the string to lower case
    txt = txt.lower()
    # remove non-english characters, punctuation and numbers
    txt = re.sub('[^a-zA-Z]', ' ', txt)
    
    # Tokenize the text
    tokens = tokenizer.tokenize(txt)

    # Lemmatization and removing stop words
    lemmatized_tokens = [lemmatizer.lemmatize(token) for token in tokens]
    
    txt = ' '.join(lemmatized_tokens)
    
    txt = remove_stop_words(txt)
    
    return txt

错误信息:

LookupError                               Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/nltk/corpus/util.py:80, in LazyCorpusLoader.__load(self)
     79 except LookupError as e:
---> 80     try: root = nltk.data.find('{}/{}'.format(self.subdir, zip_name))
     81     except LookupError: raise e

File /opt/conda/lib/python3.10/site-packages/nltk/data.py:653, in find(resource_name, paths)
    652 resource_not_found = '\n%s\n%s\n%s' % (sep, msg, sep)
--> 653 raise LookupError(resource_not_found)

LookupError: 
**********************************************************************
  Resource 'corpora/wordnet.zip/wordnet/.zip/' 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'
**********************************************************************
  1. 我尝试使用
    nltk.download("all")
    下载完整的 NLTK 包。
  2. 我还尝试下载
    "averaged_perceptron_tagger"
    ,正如一些论坛建议的那样。 这些尝试是在 Kaggle 笔记本环境中进行的。尽管做出了这些努力,错误仍然没有解决。

如何在 Kaggle Notebook 环境中有效解决这个问题

LookupError
?使用 Kaggle 中的 WordNet Lemmatizer 设置 NLTK 进行词形还原是否需要其他步骤或配置?

python nltk kaggle lemmatization
1个回答
0
投票

复制粘贴以下代码,因为源文件是压缩的,需要解压。因为笔记本目前还不能自动执行此操作。 代码 : !unzip /usr/share/nltk_data/corpora/wordnet.zip -d /usr/share/nltk_data/corpora/

© www.soinside.com 2019 - 2024. All rights reserved.