Spacy的解析器根据词向量计算两个词的相似度没有结果?

No result after calculating the similarity of two words based on word vectors via Spacy's parser?

我有一个spacy代码的例子:

    from numpy import dot
    from numpy.linalg import norm
    from spacy.lang.en import English

    parser = English()
    # you can access known words from the parser's vocabulary
    nasa = parser.vocab[u'NASA']

    # cosine similarity
    cosine = lambda v1, v2: dot(v1, v2) / (norm(v1) * norm(v2))

    # gather all known words, take only the lowercased versions
    allWords = list({w for w in parser.vocab if w.has_vector and 
    w.orth_.islower() and w.lower_ != unicode("nasa")})

    # sort by similarity to NASA
    allWords.sort(key=lambda w: cosine(w.vector, nasa.vector))
    allWords.reverse()
    print("Top 10 most similar words to NASA:")
    for word in allWords[:10]:
         print(word.orth_)

结果是这样的:

    Top 10 most similar words to NASA:

    Process finished with exit code 0

所以没有类似的话出来。 我尝试通过 cmd 安装解析器和手套:

    python -m spacy.en.download parser
    python -m spacy.en.download glove

但是失败了,原来是:

    C:\Python\python.exe: No module named en

顺便说一句,我使用:

    Python 2.7.9
    Spacy  2.0.9

有什么问题吗?谢谢

您正在实例化的解析器不包含词向量。检查 https://spacy.io/models/ 以了解模型概览。