TECHNOLOGY

From hidden states to vocabulary logits in a language model

In this article
THE QUICK TAKE

The output projection scores every vocabulary entry; softmax and a decoding rule subsequently turn those scores into a selected token.

The final hidden state is not itself a word. A language model needs a learned mapping from its internal feature space to the tokenizer vocabulary. Understanding that mapping explains the difference between a hidden representation, a logit, a probability and the token ultimately emitted by a decoder.

Each vocabulary item receives a score

The output matrix has an axis corresponding to vocabulary entries and another corresponding to hidden features. Multiplying a final hidden vector by the appropriately oriented matrix produces one scalar per vocabulary entry. An architecture may include a bias or tie this matrix to input embeddings. These choices belong to the model definition. The important boundary is that the output vector now has token identities attached to its coordinates; an intermediate feature coordinate did not have that same direct vocabulary interpretation.

Follow a tiny projection by hand

Imagine a hidden state with two coordinates and a vocabulary containing cat, dog and an ending symbol. Let the rows of the output matrix represent a first-feature preference, a second-feature preference and a combination of both. Moving the hidden state toward the second feature changes the dog score according to its row. This illustrates a dot product, not an assertion that trained models allocate a single interpretable animal feature. Real hidden coordinates can participate in many distributed representations simultaneously.

Logits precede probability and sampling

A logit may be negative or greater than one; it is an unnormalized score. Softmax compares scores across the vocabulary to produce a probability distribution. A common additive shift to all logits leaves that distribution unchanged. Temperature or other decoding processors may modify scores before selection. Greedy decoding chooses a largest score, while sampling draws according to a distribution. Thus inspecting a raw logit without its competitors or the decoding configuration does not establish an emitted token’s likelihood.

Vocabulary alignment is part of correctness

When loading a checkpoint, preserve the mapping between output rows and tokenizer identifiers. A correctly shaped output matrix can still produce nonsense if those identifiers are permuted. For a controlled check, record the final hidden vector, projected logits and decoded candidate identifiers for the same input. Separate changes in the model projection from changes in sampling. This makes a porting discrepancy localizable: either the numerical scores differ, or the same scores are being interpreted or selected differently downstream.

Primary research and implementation references

Reproducible inference stacks: preserving a GPU pilot’s result; A GPU inference benchmark you can trust.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles