word2Vec 获取训练好后所有的词

时间:2020-12-08 06:21:57
import gensim
sentences = [['first', 'sentence',], ['second', 'sentence'],['haha','sentence']]
# train word2vec on the two sentences
model = gensim.models.Word2Vec(sentences)

在gensim 1.0.0 以前的版本可以使用:

model.vocab

在 gensim 1.0以后的版本使用:

model.wv.vocab

结果:

[('sentence', -0.00658770278096199), ('haha', -0.03800702840089798), ('second', -0.10608357191085815)]
{'first': <gensim.models.keyedvectors.Vocab object at 0x0000017D329C4E10>,
'haha': <gensim.models.keyedvectors.Vocab object at 0x0000017D38D17358>,
'second': <gensim.models.keyedvectors.Vocab object at 0x0000017D3329BA20>,
'sentence': <gensim.models.keyedvectors.Vocab object at 0x0000017D3329B9B0>}