embeddings_maker.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:nlvr_tau_nlp_final_proj 作者: udiNaveh 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号