def embeddings_to_dict(filename):
'''
:param filename: the file name of the word embeddings | file is assumed
to follow this format: "word[tab]dimension 1[space]dimension 2[space]...[space]dimension 50"
:return: a dictionary with keys that are words and values that are the embedding of a word
'''
with io.open(filename, 'r', encoding='utf-8') as f:
word_vecs = {}
for line in f:
line = line.strip('\n').split()
word_vecs[line[0]] = np.array([float(s) for s in line[1:]])
return word_vecs
评论列表
文章目录