gpt4 book ai didi

gensim - 更新 gensim word2vec 模型

转载 作者:行者123 更新时间:2023-12-03 09:20:14 25 4
gpt4 key购买 nike

我在 gensim 中有一个 word2vec 模型,训练了 98892 个文档。对于句子数组中不存在的任何给定句子(即我训练模型的集合),我需要用该句子更新模型,以便下次查询时给出一些结果。我这样做:

new_sentence = ['moscow', 'weather', 'cold']
model.train(new_sentence)

并将其打印为日志:
2014-03-01 16:46:58,061 : INFO : training model with 1 workers on 98892 vocabulary and 100 features
2014-03-01 16:46:58,211 : INFO : reached the end of input; waiting to finish 1 outstanding jobs
2014-03-01 16:46:58,235 : INFO : training on 10 words took 0.1s, 174 words/s

现在,当我使用类似的 new_sentence 查询大多数正面(如 model.most_similar(positive=new_sentence) )时,它会给出错误:
Traceback (most recent call last):
File "<pyshell#220>", line 1, in <module>
model.most_similar(positive=['moscow', 'weather', 'cold'])
File "/Library/Python/2.7/site-packages/gensim/models/word2vec.py", line 405, in most_similar
raise KeyError("word '%s' not in vocabulary" % word)
KeyError: "word 'cold' not in vocabulary"

这表明“冷”这个词不是我训练这件事的词汇的一部分(我是对的)?

所以问题是:如何更新模型,以便它给出给定新句子的所有可能的相似之处?

最佳答案

  • train()期待 序列 输入的句子,而不是 句子。
  • train()只有updates weights对于基于现有词汇表的现有特征向量。您不能使用 train() 添加新词汇(=新特征向量) .
  • 关于gensim - 更新 gensim word2vec 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22121028/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com