存储和加载模型
存储、加载模型的方法如下:
>>>model.save('/tmp/mymodel')
>>>new_model = gensim.models.Word2Vec.load('/tmp/mymodel')
保存为txt格式:
model.wv.save_word2vec_format('wordvec.txt')
可以直接加载由C生成的模型:
model = Word2Vec.load_word2vec_format('/tmp/vectors.txt', binary=False)
#using gzipped/bz2 input works too, no need to unzip:
model=Word2Vec.load_word2vec_format('/tmp/vectors.bin.gz', binary=True)
可以在加载模型之后使用另外的句子来进一步训练模型
model = gensim.models.Word2Vec.load('/tmp/mymodel')
model.train(more_sentences)
不能对C生成的模型再训练
model.most_similar(positive=['woman','king'], negative=['man'], topn=1)
[('queen',0.50882536)]
model.doesnt_match("breakfast cereal dinner lunch".split())
'cereal'
model.similarity('woman','man')
.73723527
网友评论