gpt4 book ai didi

python - NLTK POS tagger 要求我下载什么?

转载 作者:IT老高 更新时间:2023-10-28 22:06:38 25 4
gpt4 key购买 nike

我刚开始使用词性标注器,我遇到了很多问题。

我开始使用以下内容进行 POS 标记:

import nltk
text=nltk.word_tokenize("We are going out.Just you and me.")

当我想打印 'text' 时,会发生以下情况:

print nltk.pos_tag(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "F:\Python26\lib\site-packages\nltk\tag\__init__.py", line 63, in pos_tag
tagger = nltk.data.load(_POS_TAGGER)
File "F:\Python26\lib\site-packages\nltk\data.py", line 594, in load
resource_val = pickle.load(_open(resource_url))
File "F:\Python26\lib\site-packages\nltk\data.py", line 673, in _open
return find(path).open()
File "F:\Python26\lib\site-packages\nltk\data.py", line 455, in find
raise LookupError(resource_not_found)`
LookupError:
Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not
found. Please use the NLTK Downloader to obtain the resource:

>>> nltk.download().

Searched in:
- 'C:\\Documents and Settings\\Administrator/nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- 'F:\\Python26\\nltk_data'
- 'F:\\Python26\\lib\\nltk_data'
- 'C:\\Documents and Settings\\Administrator\\Application Data\\nltk_data'

我使用了 nltk.download() 但它不起作用。

最佳答案

NLTK版本高于v3.2,请使用:

>>> import nltk
>>> nltk.__version__
'3.2.1'
>>> nltk.download('averaged_perceptron_tagger')
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] /home/alvas/nltk_data...
[nltk_data] Package averaged_perceptron_tagger is already up-to-date!
True

NLTK版本使用旧MaxEnt模型,即v3.1及以下,请使用:

>>> import nltk
>>> nltk.download('maxent_treebank_pos_tagger')
[nltk_data] Downloading package maxent_treebank_pos_tagger to
[nltk_data] /home/alvas/nltk_data...
[nltk_data] Package maxent_treebank_pos_tagger is already up-to-date!
True

有关更改默认pos_tag的更多详细信息,请参阅https://github.com/nltk/nltk/pull/1143

关于python - NLTK POS tagger 要求我下载什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8590370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com