我正在实现来自此链接的代码Glove implementation 我正在使用 Python 中的 ArgumentParser 从指定路径读取文件。
parser.add_argument('corpus', metavar='corpus_path',
type=partial(codecs.open, encoding='utf-8'))
我在命令提示符下使用这个命令来传递参数
python Glove_python_bbc.py "C:/Users/JAYASHREE/Documents/NLP/text-corpus.txt" --vocab-path C:/Users/JAYASHREE/Documents/NLP/vocabulary --cooccur-path C:/Users/JAYASHREE/Documents/NLP/cooccur_matrix -w 10 --min-count 10 --vector-path C:/Users/JAYASHREE/Documents/NLP/word-vector -s 40 --iterations 10 --learning-rate 0.1 --save-often
但我收到以下错误
2017-08-06 23:03:46,171 Fetching vocab..
2017-08-06 23:03:46,171 Building vocab from corpus
Traceback (most recent call last):
File "Glove_python_bbc.py", line 383, in <module>
main(parse_args())
File "Glove_python_bbc.py", line 352, in main
vocab = get_or_build(arguments.vocab_path, build_vocab, corpus)
File "Glove_python_bbc.py", line 93, in get_or_build
obj = build_fn(*args, **kwargs)
File "Glove_python_bbc.py", line 112, in build_vocab
for line in corpus:
File "C:\Users\JAYASHREE\Anaconda2\lib\codecs.py", line 699, in next
return self.reader.next()
File "C:\Users\JAYASHREE\Anaconda2\lib\codecs.py", line 630, in next
line = self.readline()
File "C:\Users\JAYASHREE\Anaconda2\lib\codecs.py", line 545, in readline
data = self.read(readsize, firstline=True)
File "C:\Users\JAYASHREE\Anaconda2\lib\codecs.py", line 492, in read
newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xa3 in position 6898: invalid start byte