为 doc2vec 加载预训练的 word2vec 模型

load pre-trained word2vec model for doc2vec

我正在使用 gensim 从文档中提取特征向量。 我已经从 Google 下载了名为 GoogleNews-vectors-negative300.bin 的预训练模型,并使用以下命令加载了该模型:

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

我的目的是从文档中获取特征向量。一句话,很容易得到对应的向量:

vector = model[word]

但是,我不知道如何为文档做这件事。你能帮忙吗?

一组词向量(例如GoogleNews-vectors-negative300.bin)对于Doc2Vec [=23=创建的那种文本向量(Le/Mikolov 'Paragraph Vectors')既不是必需的也不是充分的].相反,它希望通过示例文本进行训练以学习 per-document 向量。然后,经过训练的模型也可用于 'infer' 其他新文档的向量。

(Doc2Vec class 仅支持 load_word2vec_format() 方法,因为它继承自 Word2Vec class – 不是因为它需要该功能。)

还有另一种简单的文本向量,可以通过简单地对文档中的所有单词进行平均来创建,也许还可以根据一些 per-word 重要性权重。但这不是 Doc2Vec 提供的。

我试过这个:

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

它给我一个错误,doc to vec 不包含任何 word2vec 格式。