gpt4 book ai didi

python-3.x - Python NLTK pos_tag 抛出 URLError

转载 作者:行者123 更新时间:2023-12-04 10:48:30 26 4
gpt4 key购买 nike

我试图使用 pos_tag NLTK 3 中的函数(在 Windows 上),但出现此错误:

>>> import nltk
>>> tokens = nltk.word_tokenize("This is a sentence!")
>>> tokens
['This', 'is', 'a', 'sentence', '!']
>>> tags = nltk.pos_tag(tokens)
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
tags = nltk.pos_tag(tokens)
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\tag\__init__.py", line 110, in pos_tag
tagger = PerceptronTagger()
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\tag\perceptron.py", line 141, in __init__
self.load(AP_MODEL_LOC)
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\tag\perceptron.py", line 209, in load
self.model.weights, self.tagdict, self.classes = load(loc)
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\data.py", line 801, in load
opened_resource = _open(resource_url)
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\data.py", line 924, in _open
return urlopen(resource_url)
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 465, in open
response = self._open(req, data)
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 488, in _open
'unknown_open', req)
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 1310, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: c>

所有的包都安装成功(包括 maxent_treebank_pos_tagger),我也安装了 Numpy。

难道我做错了什么?

最佳答案

已编辑

此问题已从 NLTK v3.2.1 解决。升级您的 NLTK 将解决该问题,例如pip install -U nltk .

您可能正在使用 nltk 版本 3.2 。将其降级到 3.1 版,它会正常工作。我自己现在使用了下面提到的方法,URL 错误消失了。似乎是 nltk_version-3.2 的问题

浏览到您计算机上的此目录

C:\Users\USERNAME\AppData\Local\Continuum\Anaconda2\Lib\site-packages
OR
C:\python2.7\site-packages\

基本上目的是进入 site-packages 目录,该目录包含已安装的软件包。

搜索并删除这些文件和目录:
nltk-3.1.dist-info
nltk

删除强制安装旧版本后: -
pip install nltk==3.1

关于python-3.x - Python NLTK pos_tag 抛出 URLError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35827859/

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