【问题标题】:How do I get a single vector for a single word using Word2Vec?如何使用 Word2Vec 获得单个单词的单个向量?
【发布时间】:2017-03-18 20:29:11
【问题描述】:

我正在尝试解决深度学习文本分类问题,因此我必须使用 Word2Vec 对文本输入进行矢量化,以将其输入神经网络。

所以我下载了一个谷歌预训练的 Word2Vec 模型:https://github.com/3Top/word2vec-api

并使用 gensim 加载它:

import gensim
model = gensim.models.KeyedVectors.load_word2vec_format('Word2Vec.bin', binary=True)

当我尝试打印特定单词时:

print(model['cat'])
# => expected output: 0.47385435 (or something)
# => actual output: array with hundreds of floats between -1 and 1

为什么我不只为一个词获得一个向量?这不是重点吗?

额外问题:我可以将 Google 预训练的 Word2Vec 模型中的 3M 词向量加载到 MongoDB 数据库中吗? (列:id - 字(字符串) - 向量(浮点数))。因为从 .bin 或 .txt 文件加载模型需要一分钟。

【问题讨论】:

  • 根据定义,一个向量将有多个值(除非我猜你有一个一维向量)。所以你确实每个单词都有一个向量,只是在这种情况下,向量 is 是一个数组。请参阅文档here 中的示例。

标签: python deep-learning word2vec


【解决方案1】:
When I try to print a specific word:

print(model['cat'])
# => expected output: 0.47385435 (or something)
# => actual output: array with hundreds of floats between -1 and 1
Why don't I just get one vector for one word? Isn't that the point?

“在 -1 和 1 之间有数百个浮点数的数组”是一个词向量。

当您想调用向量时,为什么会期望 scala (0.47385435)?

您需要阅读以下内容:https://www.tensorflow.org/tutorials/word2vec

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    • 2021-05-04
    • 2015-12-21
    • 2018-12-12
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    相关资源
    最近更新 更多