问题描述
我有一组经过神经网络训练的嵌入,与gensim的word2vec无关.
I have a set of embeddings trained with a neural network that has nothing to do with gensim's word2vec.
我想将这些嵌入用作gensim.Word2vec
中的初始权重.
I want to use these embeddings as the initial weights in gensim.Word2vec
.
现在我看到的是我可以model.load(SOME_MODEL)
,然后继续训练,但这需要使用gensim模型作为输入.另外reset_from()
似乎只接受其他gensim模型.但是就我而言,我没有一个gensim模型,而是一个word2vec嵌入格式的文本文件.
Now what I did see is that I can model.load(SOME_MODEL)
and then continue training, but it requires a gensim modle as input. Also reset_from()
seems to only accept other gensim model.But in my case, I don't have a gensim model to start from, but a text file in word2vec format of embeddings.
那么我如何开始将学习内容从word2vec文本文件传输到gensim.Word2vec
?
So how do I start transfer learning from an word2vec text file to gensim.Word2vec
?
推荐答案
您可以使用原始Word2Vec模型的键向量格式加载其他模型
You can load other models using the key vector format of the original Word2Vec model
import io
from gensim.models.keyedvectors import KeyedVectors
# first line is vocab size and vector dim
model_buf = io.StringIO("""
2 3
word0 -0.000737 -0.002106 0.001851
word1 -0.000878 -0.002106 0.002834
""".lstrip())
model = KeyedVectors.load_word2vec_format(model_buf, binary=False)
model['word0']
这篇关于gensim Word2vec转移学习(来自非gensim模型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!