ng的 operations on word vectors 这个练习中在 读取 glove.6B.50d.txt时,报以下错误:
UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 3136: illegal multibyte sequence
解决方法:
将 w2v_utils.py中的read_glove_vecs方法修改为以下即可(标红部分即为不同):
import codecs
def read_glove_vecs(glove_file):
with open(glove_file, 'r',encoding='utf-8') as f:
words = set()
word_to_vec_map = {}
for line in f:
line = line.strip().split()
curr_word = line[0]
words.add(curr_word)
word_to_vec_map[curr_word] = np.array(line[1:], dtype=np.float64)
return words, word_to_vec_map
知乎: https://zhuanlan.zhihu.com/albertwang
微信公众号:AI-Research-Studio
下面是赞赏码