如何加载预先训练好的Word2vec模型文件并重复使用?

时间:2016-09-17 16:40:54

标签: python file model word2vec gensim

我想使用预先训练的var div1_height = document.querySelector("#div1").getBoundingClientRect().height; document.querySelector("#div2").style.height = div1_height+"px"; 模型,但我不知道如何在python中加载它。

此文件是MODEL文件(703 MB)。 它可以在这里下载:
uniq Documentation

1 个答案:

答案 0 :(得分:6)

仅用于加载

import gensim

# Load pre-trained Word2Vec model.
model = gensim.models.Word2Vec.load("modelName.model")

现在您可以像往常一样训练模型。此外,如果您希望能够保存并重新训练多次,这就是您应该做的事情

model.train(//insert proper parameters here//)
"""
If you don't plan to train the model any further, calling
init_sims will make the model much more memory-efficient
If `replace` is set, forget the original vectors and only keep the normalized
ones = saves lots of memory!
replace=True if you want to reuse the model
"""
model.init_sims(replace=True)

# save the model for later use
# for loading, call Word2Vec.load()

model.save("modelName.model")