Ng深度学习第五课第二周Operations on word vectors中读取glove.6B.50d.txt报错解决

转至:https://blog.csdn.net/wwangfabei1989/article/details/80401272


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

你可能感兴趣的:(deep-learning)