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

重启jupyter

相关文章: