【发布时间】:2017-10-12 03:59:07
【问题描述】:
我使用分布式 word2vec 算法创建了词向量。现在我有了单词和它们对应的向量。如何使用这些词和向量构建 gensim word2vec 模型?
【问题讨论】:
标签: nlp gensim word2vec text-analysis word-embedding
我使用分布式 word2vec 算法创建了词向量。现在我有了单词和它们对应的向量。如何使用这些词和向量构建 gensim word2vec 模型?
【问题讨论】:
标签: nlp gensim word2vec text-analysis word-embedding
我不确定您是否使用 gensim 或其他工具创建了 word2vec 模型,但如果正确理解您的问题,您只想使用 gensim 加载 word2vec 模型。这是通过以下方式完成的:
import gensim
w2v_file = codecs.open(WORD2VEC_PATH, encoding='utf-8')
model = gensim.models.KeyedVectors.load_word2vec_format(w2v_file, binary=True) # or binary=False if the model is not compressed
但是,如果您想做的是纯粹使用 gensim 从头开始(即从原始文本)训练 word2vec 模型,这里是 tutorial on how to train word2vec model using gensim。
【讨论】:
from gensim.models import word2vec model = word2vec.Word2Vec.load_word2vec_format('path/to/GoogleNews-vectors-negative300.bin', binary=False) 重要的部分是binary=False。