我是NLTK的新手。我收到此错误,并且我一直在搜索编码/解码,尤其是UnicodeDecodeError,但是此错误似乎特定于NLTK源代码。

这是错误:

Traceback (most recent call last):
  File "A:\Python\Projects\Test\main.py", line 2, in <module>
    print(pos_tag(word_tokenize("John's big idea isn't all that bad.")))
  File "A:\Python\Python\lib\site-packages\nltk\tag\__init__.py", line 100, in pos_tag
    tagger = load(_POS_TAGGER)
  File "A:\Python\Python\lib\site-packages\nltk\data.py", line 779, in load
    resource_val = pickle.load(opened_resource)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcb in position 0: ordinal not in range(128)

如何解决该错误?
导致错误的原因如下:
from nltk import pos_tag, word_tokenize
print(pos_tag(word_tokenize("John's big idea isn't all that bad.")))

最佳答案

试试这个... NLTK 3.0.1和Python 2.7.x

import io
f = io.open(txtFile, 'rU', encoding='utf-8')

10-05 21:22
查看更多