小编Lin*_* Xu的帖子

麻烦加载手套 840B 300d 矢量

似乎格式是,对于每一行,字符串就像“字号……”。所以很容易分裂。但是当我用下面的脚本分割它们时

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.* 中运行良好

python nlp stanford-nlp word2vec

5
推荐指数
1
解决办法
4824
查看次数

标签 统计

nlp ×1

python ×1

stanford-nlp ×1

word2vec ×1