WEW_E

W_E — the embedding matrix

Read "W E". It is a learned table with one row per token in the vocabulary; each row is that token's vector of d_model numbers.

WE∈R∣V∣×dmodelW_E \in \mathbb{R}^{|V| \times d_{\text{model}}}: ∣V∣|V| rows, each dmodeld_{\text{model}} numbers wide. Row ii is the vector the model uses for token ii. It is trained like any other weight.

Many models tie this matrix to the output layer: they reuse it (transposed) to turn the final hidden vector back into one score per vocabulary token. That saves a whole ∣V∣×dmodel|V| \times d_{\text{model}} block of parameters, which is a large share of a small model.

Example

∣V∣=50,257,  dmodel=768  ⟹  WE has about 38.6M numbers|V| = 50{,}257,\; d_{\text{model}} = 768 \;\Longrightarrow\; W_E \text{ has about } 38.6\text{M numbers}

GPT-2 small.

Where the course uses it

Related terms