gpt4 book ai didi

Python (nltk) - UnicodeDecodeError : 'ascii' codec can't decode byte

转载 作者:太空狗 更新时间:2023-10-29 21:05:43 25 4
gpt4 key购买 nike

我是 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')

关于Python (nltk) - UnicodeDecodeError : 'ascii' codec can't decode byte,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25493720/

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