深度学习 operations on word vectors 读取词嵌入矩阵报错: 'gbk' codec can't decode byte 0x93 in position 3136

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

https://img-blog.csdnimg.cn/20190110102516916.png ​​

下面是赞赏码

深度学习 operations on word vectors 读取词嵌入矩阵报错: 'gbk' codec can't decode byte 0x93 in position 3136_第1张图片

你可能感兴趣的:(Deep,Learning,python)