Definition

The unembedding layer is the last step of a language model: a single matrix of shape (|V|, d_model) that turns the final Residual stream into one score (a logit) per token of the vocabulary. It is the mirror of the embedding layer , which maps a token id to a vector at the start of the model. Some models tie them (the same matrix serves as embedding and unembedding, e.g. Gemma), others learn them separately (e.g. Llama 3.1).

Formula

Let be the residual stream of the last position after the last block, the final normalization and the vocabulary size:

let’s break this formula step-by-step:

  • is the final stream, normalized once before the output.
  • each row of is a direction associated with one token, and the logit of this token is the dot product between the stream and this row: the more the stream points toward the row, the more likely the token.
  • the softmax turns the logits into next-token probabilities.

Usage

  • Reading a direction (logit lens): for a direction in the stream space, gives one value per token. The tokens with the highest values are those the direction promotes, the lowest those it suppresses.
  • Caveat: this reading is exact only at the last layer. For earlier layers it is an approximation, because later blocks still modify the stream, and it ignores the final normalization.