【发布时间】:2017-02-22 18:33:14
【问题描述】:
我正在使用不同的数据训练我自己的 word2vec 模型。要将生成的模型实现到我的分类器中并将结果与原始预训练的 Word2vec 模型进行比较,我需要将模型保存在二进制扩展名 .bin 中。这是我的代码,sentences是一个短消息列表。
import gensim, logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
sentences = gensim.models.word2vec.LineSentence('dati.txt')
model = gensim.models.Word2Vec(
sentences, size=300, window=5, min_count=5, workers=5,
sg=1, hs=1, negative=0
)
model.save_word2vec_format('model.bin', binary=True)
最后一个方法,save_word2vec_format,给了我这个错误:
AttributeError: 'Word2Vec' object has no attribute 'save_word2vec_format'
我在这里缺少什么?我已经阅读了 gensim 和其他论坛的文档。这个repo on github 使用几乎相同的配置,所以我不明白出了什么问题。我尝试从 skipgram 切换到 cbow,从分层 softmax 切换到负采样,但没有结果。
提前谢谢你!
【问题讨论】:
标签: python attributes nlp gensim word2vec