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

2024-04-24 16:19:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用预先训练过的word2vec模型,但我不知道如何在python中加载它。

此文件是模型文件(703 MB)。 可在此处下载:
http://devmount.github.io/GermanWordEmbeddings/


Tags: 文件io模型githubhttpmbword2vecgermanwordembeddings
1条回答
网友
1楼 · 发布于 2024-04-24 16:19:23

只是为了装东西

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")

相关问题 更多 >