【问题标题】:load the GoogleNews-vectors-negative300.bin and predict_output_word加载 GoogleNews-vectors-negative300.bin 和 predict_output_word
【发布时间】:2018-06-13 14:30:54
【问题描述】:

我尝试加载 GoogleNews-vectors-negative300.bin 并尝试 predict_output_word 方法,

我测试了三种方式,但都失败了,每种方式的代码和错误如下所示。

import gensim
from gensim.models import Word2Vec
  1. 第一个:

我第一次使用这一行:

model=Word2Vec.load_word2vec_format('GoogleNews-vectors-negative300.bin',binary=True)


print(model.wv.predict_output_word(['king','man'],topn=10))

错误:

DeprecationWarning: Deprecated. Use gensim.models.KeyedVectors.load_word2vec_format instead.
  1. 第二个:

然后我尝试了:

model = gensim.models.KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin',binary=True)


print(model.wv.predict_output_word(['king','man'],topn=10))

错误:

AttributeError: 'Word2VecKeyedVectors' object has no attribute 'predict_output_word'
  1. 第三个: 模型 = gensim.models.Word2Vec.load('GoogleNews-vectors-negative300.bin') print(model.wv.predict_output_word(['king','man'],topn=10))

错误: _pickle.UnpicklingError: 无效的加载键,'3'。

我在

阅读了文档

https://radimrehurek.com/gensim/models/word2vec.html

但仍然不知道 predict_output_word 所在的命名空间。

有人可以帮忙吗?

谢谢。

【问题讨论】:

    标签: word2vec


    【解决方案1】:

    GoogleNews 向量集只是原始向量——没有完整的训练模型(包括内部权重)。所以它:

    • 不能作为全功能gensimWord2Vec模型加载
    • 可以作为仅查找 KeyedVectors 加载,但该对象本身不具备进一步模型训练或其他功能所需的数据或协议

    Google 尚未发布用于创建 GoogleNews 向量集的完整模型。

    另请注意,gensim 中的 predict_output_word() 函数应被视为实验性好奇心。它在分层-softmax 模型中不起作用(因为生成排名预测并不那么简单)。它与训练期间使用的上下文窗口权重不完全匹配。

    预测单词并不是 word2vec 算法的真正重点——许多实现不提供任何接口来在稀疏批量训练过程之外进行单个单词预测。相反,word2vec 使用(草率地)尝试进行预测的练习来训练词向量,这些词向量被证明可用于其他非词预测目的。

    【讨论】:

      猜你喜欢
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 2016-03-02
      • 1970-01-01
      • 2020-06-04
      • 1970-01-01
      • 2016-05-09
      • 2015-11-24
      相关资源
      最近更新 更多