Training wordvec in Tensorflow, importing to Gensim

自闭症网瘾萝莉.ら 提交于 2019-12-06 02:35:41

One way to is save the file in the non-binary Word2Vec format, which essentially looks like this:

num_words vector_size  # this is the header
label0 x00 x01 ... x0N
label1 x10 x11 ... x1N
...

Example:

2 3
word0 -0.000737 -0.002106 0.001851
word1 -0.000878 -0.002106 0.002834

Save the file and then load with kwarg binary=False:

model = Word2Vec.load_word2vec_format(filename, binary=False)

print(model['word0'])

Update

New way to load model is:

from gensim.models.keyedvectors import KeyedVectors

model = KeyedVectors.load_word2vec_format(model_path, binary=False)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!