如何加载经过预训练的Word2vec MODEL文件并重新使用它? [英] How to load a pre-trained Word2vec MODEL File and reuse it?

查看:840
本文介绍了如何加载经过预训练的Word2vec MODEL文件并重新使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use a pre-trained word2vec model, but I don't know how to load it in python.

此文件是MODEL文件(703 MB). 可以在这里下载:
http://devmount.github.io/GermanWordEmbeddings/

This file is a MODEL file (703 MB). It can be downloaded here:
http://devmount.github.io/GermanWordEmbeddings/

推荐答案

仅用于加载

import gensim

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

现在您可以像往常一样训练模型.另外,如果您希望能够保存它并对其进行多次培训,这就是您应该做的

now you can train the model as usual. also, if you want to be able to save it and retrain it multiple times, here's what you should do

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

这篇关于如何加载经过预训练的Word2vec MODEL文件并重新使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆