spaCy 词汇表
词向量(word embeddings — 词的向量表示)是词语的数值化表示,使计算机能够基于文本数据执行复杂任务。许多 spaCy 模型都包含词向量,但也有少数模型不包含词向量。
在本练习中,您将练习访问 spaCy 的词汇表信息。关于词向量的一些元信息存储在每个 spaCy 模型中。您可以访问这些信息来了解词汇量、词向量维度等。
spaCy 包已为您导入。在 spaCy 模型的元数据中,词汇量存储在键 "vectors" 对应的元素中,词向量的维度存储在键 "width" 对应的元素中。
本练习是课程的一部分
使用 spaCy 的自然语言处理
练习说明
- 加载
en_core_web_md模型。 - 打印
en_core_web_md模型词汇表中的词数。 - 打印
en_core_web_md模型的词向量维度。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Load the en_core_web_md model
md_nlp = ____
# Print the number of words in the model's vocabulary
print("Number of words: ", md_nlp.____["vectors"]["vectors"], "\n")
# Print the dimensions of word vectors in en_core_web_md model
print("Dimension of word vectors: ", md_nlp.____["vectors"]["width"])