Glossary · Tokens in, tokens out
Embedding and output head
Also: embed_tokenslm_headunembeddinglogits
Read it at the depth you need: one sentence · a paragraph · the math · in the models here
1In one sentence
The table that turns each token id into a vector of d numbers at the start, and the matrix that turns the last vector back into a score for every token at the end.
2In a paragraph
The embedding is a lookup table with one row of d numbers per vocabulary entry; a token's row is where its journey through the model starts. At the top, the output head (lm_head) multiplies the final vector by a [V, d] matrix to give one score (logit) per token; a softmax over them is the prediction for the next token. In small models these two matrices can be a large share of all parameters.
3The math, shapes and parameters
x0 = E[token] (E: [V, d], a lookup, no multiply)
logits = Whead · Norm(xL) (Whead: [V, d], 2·V·d FLOPs per token)
The lookup costs no FLOPs, which is why this site's FLOPs leave the embedding out but keep the head, even when the two are tied. Gemma multiplies the embedding by √d on the way in.
Term by term on Notation Decoder, the sister site: Softmax · Cross-entropy loss
4In the 96 models on this site
The embedding's share falls fast with size:
| Model | V × d | Embedding | Share | Head |
|---|---|---|---|---|
| SmolLM2 135M | 49,152 × 576 | 28.3M | 21.0% | tied |
| Gemma 2 2B | 256,000 × 2,304 | 590M | 22.6% | tied |
| DeepSeek-R1-Distill-Qwen-7B | 152,064 × 3,584 | 545M | 7.2% | 545M |
| Mistral Small 3 (24B) | 131,072 × 5,120 | 671M | 2.8% | 671M |
| Llama 3.1 405B | 128,256 × 16,384 | 2.1B | 0.52% | 2.1B |
Related
Vocabulary and tokenizer · Tied embeddings · FLOPs per token · every term