The last layer
gets the last word.
Every transformer ends the same way: a stack of blocks that understands the prompt, then one small linear layer — the LM head — that turns that understanding into a score for every word in the vocabulary. Walk the pipeline from tokens to probabilities.
Sixteen scores,
one matmul.
The head is a linear layer with no activation and usually no bias. Each column of its weight matrix is one word’s direction in hidden space, and each logit is one dot product. Slide along the columns and watch the multiply happen.
Raw scores become
an honest bet.
Logits are unbounded and mean nothing on their own. Softmax shifts, exponentiates and normalises them into a probability for every word — and one temperature knob decides whether the model plays it safe or takes risks.
A “small head” that is
the biggest matrix.
Two numbers fix the head’s size: the backbone’s width and the tokeniser’s vocabulary. In GPT-2 their product is 31% of the whole model — which is why heads get tied to embeddings, and why “head” really means “swappable last layer”.