Reputation: 189
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"
Is there a way to do that in word2vec?
Upvotes: 11
Views: 6797
Reputation: 1
I think it is possible to obtain antonym using king-men+women=queen analogies. in here queen (antonym of king and synonym of women) is the result that return from word2vec trained model. let we say there is a word X and its synonym Y. and also have antonym of Y which is Z. then we can say X-Y + Z = antonym of (X) and synonym of(Z).
Upvotes: 0
Reputation: 4898
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.
Upvotes: 9