Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

附录:NumPy的应用—自然语言

虽然NumPy主要用于科学计算和数据分析领域,但它也可以在自然语言处理(NLP)等领域中发挥作用。

和音频、图像不同,如果需要表示语言,需要用数值表示一段文本需要构建一个词汇表(模型需要知道的所有的唯一词)以及一个词嵌入(embedding)过程。

让我们看看用数字表示这个谚语的步骤:”Have the bards who preceded me left any theme unsung?” 翻译:在我之前的吟游诗人有没有留下任何主题?

我们可以使用一个词汇数据集来构建一个词汇表(71,290个单词):

这个句子可以被划分为一系列词:

numpy-nlp-tokenization

然后我们用词汇表中单词的ID来替换它:

numpy-nlp-ids

然后进一步使用word2vec词嵌入、卷积向量等技术来处理文本,详见: https://jalammar.github.io/illustrated-word2vec/

参考: