Python NLTK 查找错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35861482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NLTK Lookup Error
提问by Shiv Shankar
While running a Python script using NLTK I got this:
在使用 NLTK 运行 Python 脚本时,我得到了这个:
Traceback (most recent call last):
File "cpicklesave.py", line 56, in <module>
pos = nltk.pos_tag(words)
File "/usr/lib/python2.7/site-packages/nltk/tag/__init__.py", line 110, in pos_tag
tagger = PerceptronTagger()
File "/usr/lib/python2.7/site-packages/nltk/tag/perceptron.py", line 140, in __init__
AP_MODEL_LOC = str(find('taggers/averaged_perceptron_tagger/'+PICKLE))
File "/usr/lib/python2.7/site-packages/nltk/data.py", line 641, in find
raise LookupError(resource_not_found)
LookupError:
**********************************************************************
Resource u'taggers/averaged_perceptron_tagger/averaged_perceptro
n_tagger.pickle' 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'
**********************************************************************
Can anyone explain the problem?
任何人都可以解释这个问题吗?
回答by user2314737
Use
用
>>> nltk.download()
to install the missing module (the Perceptron Tagger).
安装缺少的模块(感知器标记器)。
(check also the answers to Failed loading english.pickle with nltk.data.load)
回答by Posuer
First answer said the missing module is 'the Perceptron Tagger', actually its name in nltk.download is 'averaged_perceptron_tagger'
第一个答案说缺少的模块是“感知器标记器”,实际上它在 nltk.download 中的名称是“averaged_perceptron_tagger”
You can use this to fix the error
您可以使用它来修复错误
nltk.download('averaged_perceptron_tagger')
nltk.download('averaged_perceptron_tagger')
回答by alvas
TL;DR
TL; 博士
import nltk
nltk.download('averaged_perceptron_tagger')
Or to download all packages + data + docs:
或者下载所有包+数据+文档:
import nltk
nltk.download('all')
回答by Lucas Azevedo
Install all nltk resources in one line:
在一行中安装所有 nltk 资源:
python3 -c "import nltk; nltk.download('all')"
the data will be saved at ~/nltk_data
数据将保存在 ~/nltk_data
You can also substitute "all" for "averaged_perceptron_tagger" to install only this module.
您还可以将“all”替换为“averaged_perceptron_tagger”以仅安装此模块。
回答by ishwardgret
You can download NLTK missing module just by
您可以通过以下方式下载 NLTK 缺失的模块
import nltk
nltk.download()
This will shows the NLTK download screen. If it shows SSL Certificate verify failed error. Then it should works by disabling SSL check with below code!
这将显示 NLTK 下载屏幕。如果它显示 SSL 证书验证失败错误。然后它应该通过使用以下代码禁用 SSL 检查来工作!
import nltk
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
nltk.download()
回答by Rayudu Yarlagadda
Problem: Lookup error when extracting count vectorizer from scikit learn. Below is code snippet.
问题:从 scikit learn 中提取计数向量化器时出现查找错误。下面是代码片段。
from sklearn.feature_extraction.text import CountVectorizer
bow_transformer = CountVectorizer(analyzer=text_process).fit(X)
Solution: Try to run the below code and then try to install the stopwords from corpora natural language processing toolkit!!
解决方案:尝试运行以下代码,然后尝试安装语料库自然语言处理工具包中的停用词!!
import nltk
nltk.download()
回答by Lucky Sunda
Sometimes even by writing
nltk.download('module_name')
, it does not get downloaded. At those times, you can open python in interactive mode and then download by using nltk.download('module_name')
.
有时即使通过写入
nltk.download('module_name')
,也不会下载。那时,您可以在交互模式下打开 python,然后使用nltk.download('module_name')
.