﻿# From hidden states to vocabulary logits in a language model

How an LLM turns its hidden state into vocabulary logits, why output rows matter, and where probability normalization and token selection begin.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/language-model-logits-output-projection/
Language: en

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

- [Attention Is All You Need](https://arxiv.org/abs/1706.03762).

- [Using the Output Embedding to Improve Language Models](https://arxiv.org/abs/1608.05859).

- [Hugging Face Transformers PreTrainedModel](https://huggingface.co/docs/transformers/main_classes/model).

## Related engineering context

[Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/); [A GPU inference benchmark you can trust](/journal/inference-benchmark-method/).
