word2vec - 加载 GoogleNews-vectors-negative300.bin 和 predict_output_word
问题描述
我尝试加载 GoogleNews-vectors-negative300.bin 并尝试 predict_output_word 方法,
我测试了三种方式,但都失败了,每种方式的代码和错误如下所示。
import gensim
from gensim.models import Word2Vec
- 首先:
我首先使用了这一行:
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.
- 第二:
然后我尝试了:
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'
- 第三个:model = 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 所在的命名空间。
有人可以帮忙吗?
谢谢。
解决方案
这GoogleNews
组向量只是原始向量——没有完整的训练模型(包括内部权重)。所以:
- 无法作为全功能
gensim
Word2Vec
模型加载 - 可以作为仅查找加载
KeyedVectors
,但该对象本身没有进一步模型训练或其他功能所需的数据或协议
Google 尚未发布用于创建GoogleNews
向量集的完整模型。
另请注意,predict_output_word()
函数 ingensim
应被视为实验好奇心。它在分层-softmax 模型中不起作用(因为生成排名预测并不那么简单)。它与训练期间使用的上下文窗口权重不完全匹配。
预测单词并不是 word2vec 算法的真正重点——许多实现不提供任何接口来在稀疏批量训练过程之外进行单个单词预测。相反,word2vec 使用(草率地)尝试进行预测来训练词向量,这些词向量被证明对其他非词预测目的有用。
推荐阅读
- javascript - Slick 滑块错误:TypeError: o[i].slick is undefined
- javascript - 选择元素单击时的 JQuery 单击事件在 chrome 中不起作用(在 windows 环境中不会出现问题)
- python - 如何为 C 代码创建 python 接口?
- lua - LUA:如何从字符串创建二维数组/表
- python - 获取训练集标签的问题
- typescript - 如何从firestore获取当前用户数据?
- c# - 在 Puppeter sharp 中提取 iframe 源
- import - 熊猫导入:ModuleNotFoundError:没有名为“pandas.api.extensions”的模块
- r - 在 R / RStudio 中的每行末尾添加 #-Symbol 的快捷方式
- ansible - 通过嵌套循环迭代