如何通过word2vec获取反义词? [英] How to obtain antonyms through word2vec?

查看:286
本文介绍了如何通过word2vec获取反义词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用gensim在Python中开发word2vec模型,并希望编写一个函数来帮助我找到给定单词的反义词和同义词. 例如: antonym("sad")="happy" synonym("upset")=被激怒"

I am currently working on word2vec model using gensim in Python, and want to write a function that can help me find the antonyms and synonyms of a given word. For example: antonym("sad")="happy" synonym("upset")="enraged"

在word2vec中有办法做到这一点吗?

Is there a way to do that in word2vec?

推荐答案

在word2vec中,您可以通过以下方式找到类比

In word2vec you can find analogies, the following way

model = gensim.models.Word2Vec.load_word2vec_format('GoogleNews-vectors-negative300.bin', binary=True)

model.most_similar(positive=['good', 'sad'], negative=['bad'])
[(u'wonderful', 0.6414928436279297),
 (u'happy', 0.6154338121414185),
 (u'great', 0.5803680419921875),
 (u'nice', 0.5683973431587219),
 (u'saddening', 0.5588893294334412),
 (u'bittersweet', 0.5544661283493042),
 (u'glad', 0.5512036681175232),
 (u'fantastic', 0.5471092462539673),
 (u'proud', 0.530515193939209),
 (u'saddened', 0.5293528437614441)]

现在使用一些标准的反义词,例如(好,坏),(有钱,很差),找到多个最接近的反义词列表.之后,您可以使用此列表的向量的平均值.

Now using some standard antonyms like (good, bad), (rich, poor), find multiple such lists of nearest antonyms. After that you can use average of vectors of this list.

这篇关于如何通过word2vec获取反义词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆