Summary: The final step of a transformer that takes the refined last-token vector out of the residual stream and projects it into a score (logits) for every possible next token, ready for softmax to produce a probability distribution.

The operation

After all attention and MLP blocks have run, the last vector in the sequence, , is multiplied by an unembedding matrix :

has one row per vocabulary token and one column per embedding dimension (unlike , which has one column per token — it’s the transposed shape):

For GPT-3: parameters, symmetric in size to .

Each entry of the output is the dot product of one row of with — i.e. how aligned the final vector is with each token’s “unembedding direction”. These raw alignment scores are the logits, which then get passed through softmax to produce the next-token probability distribution.

Image of unembedding matrix and softmax operation in GPT-3

  • maps a single residual stream vector (i.e. of length )
  • to a logits vector (i.e. one score per vocabulary token)
  • via a matrix multiply.

💡 Why only the last vector?

The transformer computes a full vector for every position in the context, but at inference time we only care about the prediction for position (the next token after the input). So we only unembed position .

During training things are different: every position simultaneously predicts its next token. So training runs the unembedding step at every position in the sequence, producing loss signals per forward pass rather than one. This is what makes training efficient — a length- sequence yields training examples for the cost of one forward pass through the stack.

At inference, the other positions’ output vectors are computed but discarded. They did their job earlier, when they contributed context to the positions after them through attention.

Tied vs untied weights

In some implementations, is tied to — they share parameters. This:

  • Halves the parameter count spent on embeddings/unembeddings.
  • Encodes the prior that “the direction for embedding a token” and “the direction for predicting it” should be the same.

Other implementations (GPT-3 included, per 3b1b’s tally) keep them untied — two independent matrices of the same shape, ~1.2B total parameters between them.

Intuition via dot products

Recall from above:

Each entry of the output is the dot product of one row of with — i.e. how aligned the final vector is with each token’s “unembedding direction”.

Because unembedding is literally “dot product against each row”, you can read as a bank of learned “if you see this direction in the residual stream, it’s likely to be followed by this token” detectors. The final-layer vector is a weighted cocktail of meanings; the row for “Snape” gives a high logit when that cocktail points toward “villainous Hogwarts potions master who is the hero’s least favourite professor”.

This also means any concept the model wants to make predictable must be a direction the unembedding can read — a nontrivial constraint on how the model uses its embedding space.

See also