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:

ModelV × dEmbeddingShareHead
SmolLM2 135M49,152 × 57628.3M21.0%tied
Gemma 2 2B256,000 × 2,304590M22.6%tied
DeepSeek-R1-Distill-Qwen-7B152,064 × 3,584545M7.2%545M
Mistral Small 3 (24B)131,072 × 5,120671M2.8%671M
Llama 3.1 405B128,256 × 16,3842.1B0.52%2.1B

Related

Vocabulary and tokenizer · Tied embeddings · FLOPs per token · every term