问题描述
使用 dataset
函数从文本文件读取数据时,出现以下错误-
read_corpus
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 7525: character maps to <undefined>
我还定义了 destination = read_corpus('./travel_data.txt')
print("Example:\n"," Text: ",destination[0][0],"\n Label: ",destination[0][1])
print("Total number of documents =",len(destination))
函数如下-
read_corpus
请告诉如何避免错误?我试图更改编码,但似乎它不适用于 def read_corpus(corpus_file):
out = []
with open(corpus_file) as f:
for line in f:
tokens = line.strip().split()
out.append((' '.join(tokens[3:]),tokens[1]))
return out
函数。我不想用其他一些 read_corpus
函数更改 read_corpus
函数。如果我使用 read
函数,是否可以避免此错误?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)