第一个word2vec例子:woman+king-man=queen。
1、加载二进制模型
直接使用Google开源模型GoogleNews-vectors-negative300.bin,使用gensim库来加载这个二进制模型:
from gensim import models
w=models.KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin',binary=True)
2、打印结果
print('King-man+woman:')
print('')
print(w.wv.most_similar(positive=['woman','king'],negative=['man']))
输出:
3、woman和man的相似度
print('Similarity between man and woman:')
print(w.similarity('woman','man'))
输出:
来源:CSDN
作者:adureychloe
链接:https://blog.csdn.net/qq_21643227/article/details/104519196