Skip to main content

Logits: scores before normalization

Why a model does not directly output probabilities

Lesson objective. Identify the shape and axes of the logits, then read the ranking of candidates at one position.

Lesson skeleton
  • Final hidden states → Logits · Assign a score to each vocabulary token

See the path

Review this lesson

A logit is an unnormalized real-valued score associated with a class or vocabulary token. In an LLM, the final projection usually produces a vector \(z\in\mathbb{R}^{V}\) at each prediction position.

The previous page showed how causal masking limits the positions accessible to attention. In the project’s GPT, the states from the final block pass through a final normalization. The output head then projects each normalized state into this score vector.

By the end of this page, you will be able to: - interpret a logit vector and explain why its values are not probabilities; - distinguish score-based candidate ranking from the probability distribution used for generation; - identify the vector dimension from the vocabulary size.

TipThe one-minute mental model

Logits are scores, not probabilities. At one position, the model produces one score per vocabulary token. The largest score identifies the top-ranked candidate; by itself, it is neither a probability nor a measure of truth.

First pass: follow “Transformer representation → output projection → vector of \(V\) logits”. The next page explains how these scores become a conditional distribution.

1. Final state 2. Vocabulary projection 3. Logits 4. Probabilities

From the final state to four scores

After the Transformer processes “What have the Romans ever done for us?”, the output head reads the final state of the last token in the prefix. It assigns one score per vocabulary token to predict the following position.

Take an illustrative state \(h=(1,-1)\) and a toy vocabulary of four tokens. The output matrix has four rows and two columns. In this example without a bias term, the score \(z_i\) is the dot product of row \(w_i\) and \(h\). Multiply corresponding coordinates and add the products.

Token Row \(w_i\) Score \(z_i\)
“They” \((\ln 3,-\ln 2)\) \(\ln 6\)
“Aqueducts” \((\ln 2,0)\) \(\ln 2\)
“Nothing” \((1,1)\) \(0\)
“Well” \((-1,-1)\) \(0\)

For “They”, the calculation gives \(\ln 3-(-\ln 2)=\ln 6\). “Nothing” and “Well” get the same score for this state from two different rows.

The calculation for these four candidates uses the same scores to obtain the first-step distribution.

Definition and dimensions

At a given position, write the score vector as: \[ z=(z_1,\ldots,z_V)\in\mathbb{R}^{V}, \] where \(V\) is the vocabulary size. Each component \(z_i\) is associated with token ID \(i\). Logits may be positive or negative; they are not constrained to \([0,1]\) and do not need to sum to one.

For a batch of sequences, the output head may produce a tensor of shape \((B,T,V)\): \(B\) sequences, \(T\) positions, and \(V\) scores per position. During autoregressive generation, the scores at the current position are typically used to choose the next token.

To connect the position axis to the vocabulary axis, compare two observed targets under the same prefix. Identify the shared logit row, then the column used in each case.

What logits tell us

  • Local ranking: within one vector, the largest logit identifies the maximum-score candidate (the argmax).
  • Score gaps: differences between scores describe their relative separation within that vector.
  • Not absolute confidence: a raw logit depends on the scores’ scale and offset. It is not a percentage and cannot, by itself, establish confidence or factual truth.

The vectors (2, 1) and (102, 101) have the same gap between their components. After softmax, each gives token A 73.1 percent and token B 26.9 percent. Adding 100 to every logit therefore leaves the distribution unchanged.

Two logit vectors that differ by a common offset produce the same softmax distribution.

The zero point of logits is arbitrary

Consider two vectors: \(z=(2,1)\) and \(z'=(102,101)\). Their scores differ greatly in absolute value, but the second vector is obtained by adding 100 to every component. Softmax gives exactly the same distribution for both vectors: the common offset cancels between numerator and denominator. Differences between logits determine probability ratios, not their absolute level.

By contrast, multiplying every logit by a positive factor can change the distribution’s concentration even when candidate ranking stays the same. Temperature uses precisely this property; the output probabilities page explains its effect.

Converting scores into a probability distribution is a separate operation. It is covered in Output probabilities, the canonical page for softmax, temperature, and distribution interpretation.

Practice

Compare the two softmax axes or explore the other practice questions.

Supplementary resources Experiment, explore further, and practise the ideas from this lesson.

In an LLM

The final hidden representation is projected to a vector of dimension \(V\), usually through a linear output layer. During training, logits can be passed directly to a loss function such as cross-entropy: an explicit softmax calculation is not required beforehand when the loss function incorporates it in a numerically stable way.

The PyTorch — CrossEntropyLoss documentation specifies unnormalized logits as the expected input.