spaCy如何为短语生成向量?

问题描述 投票:0回答:1

spaCy的中,大型词汇可以生成单词和短语的向量。让我们考虑以下示例:

import spacy

nlp = spacy.load("en_core_web_md")
tokens = nlp("apple cat sky")

print(tokens.text, tokens.vector[:3], tokens.vector_norm) #just only first three conmponents of vector 

for token in tokens:
    print(token.text, token.vector[:3], token.vector_norm)

输出:

apple cat sky [-0.06734333  0.03672066 -0.13952099] 4.845729844425328
apple [-0.36391  0.43771 -0.20447] 7.1346846
cat [-0.15067  -0.024468 -0.23368 ] 6.6808186
sky [ 0.31255  -0.30308   0.019587] 6.617719

很明显,词汇表包含每个单词的向量,但是如何生成整个阶段的向量?可以看到,它不仅是向量的简单和。

nlp spacy word2vec
1个回答
0
投票

默认情况下,Doc的向量是令牌向量的平均值,比照https://spacy.io/usage/vectors-similarity

内置词向量附带的模型使它们可用作Token.vector属性。 Doc.vector和Span.vector将默认为其令牌向量的平均值。

© www.soinside.com 2019 - 2024. All rights reserved.