> For the complete documentation index, see [llms.txt](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-wu-men-ke-xu-lie-mo-xing-sequence-models/di-wu-men-kexulie-mo-578b28-sequence-models/natural-language-processing-and-word-embeddings/24-qian-ru-ju-zhen-ff08-embedding-matrix.md).

# 2.4 嵌入矩阵（Embedding Matrix）

当应用算法来学习词嵌入时，实际上是学习一个**嵌入矩阵**

假设某个词汇库包含了10000个单词，每个单词包含的特征维度为300，那么表征所有单词的**embedding matrix**维度为300 x 10000，用$$E$$来表示。某单词$$w$$的one-hot向量表示为$$O\_w$$，维度为10000 x 1

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/ad1c7b1e85d39f56756c28787ccef892.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/ad1c7b1e85d39f56756c28787ccef892.png)

则该单词的嵌入向量(embedding vector)表达式为：

$$
e\_w=E\cdot O\_w
$$

只要知道了embedding matrix$$E$$，就能计算出所有单词的embedding vector $$e\_w$$

不过上述这种矩阵乘积运算$$E\cdot O\_w$$效率并不高，矩阵维度很大，且$$O\_w$$大部分元素为零。通常做法是直接从$$E$$中选取第$$w$$列作为$$e\_w$$
