我需要使用gensim来获取单词的向量表示,并且我认为使用的最好的东西是在英语维基百科语料库上预训练的word2vec模块.有谁知道在哪里下载,如何安装,以及如何使用gensim创建向量?
似乎格式是,对于每一行,字符串就像“字号……”。所以很容易分裂。但是当我用下面的脚本分割它们时
import numpy as np
def loadGloveModel(gloveFile):
print "Loading Glove Model"
f = open(gloveFile,'r')
model = {}
for line in f:
splitLine = line.split()
word = splitLine[0]
embedding = np.array([float(val) for val in splitLine[1:]])
model[word] = embedding
print "Done.",len(model)," words loaded!"
return model
Run Code Online (Sandbox Code Playgroud)
我加载手套 840B 300d.txt。但是得到错误,我打印了我得到的 splitLine
['contact', 'name@domain.com', '0.016426', '0.13728', '0.18781', '0.75784', '0.44012', '0.096794' ... ]
Run Code Online (Sandbox Code Playgroud)
或者
['.', '.', '.', '.', '0.033459', '-0.085658', '0.27155', ...]
Run Code Online (Sandbox Code Playgroud)
请注意,此脚本在 glove.6b.* 中运行良好
我为我的幼稚而感到抱歉,但我不明白为什么NN训练过程(word2vec)产生的词嵌入实际上是向量。
嵌入是降维的过程,在训练过程中,NN将词的1/0数组缩小为较小的数组,该过程不执行任何应用矢量算法的过程。
因此,结果是我们只有数组而不是向量。为什么将这些数组视为向量?
即使我们得到矢量,为什么每个人都将它们描述为来自原点(0,0)的矢量?
再次,对不起,如果我的问题看起来很愚蠢。