def check_word2vec(embed_dict, embeds, key_words = ['of', 'is', 'a', 'yellow', 'circle', 'box']):
KN = KNeighborsClassifier(n_neighbors=3)
print('fitting pseudo-KNN...')
KN.fit(embeds, [1]*len(embeds))
inds = KN.kneighbors(embeds, return_distance=False)
# print(inds)
embeds_list = embeds.tolist()
for word in key_words:
req_words = []
ind = embeds_list.index(embed_dict[word].tolist())
req_inds = inds[ind]
for idx in req_inds:
for w in embed_dict:
if (embed_dict[w] == embeds[idx]).all()==True:
req_words.append(w)
print('for:', word, ', the 3nn are:', req_words)
embeddings_maker.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录