Skip to main content

Output probabilities: from logits to a distribution

Conditional distributions, normalization, and calibration

Lesson objective. Turn logits into probabilities over the vocabulary and distinguish a normalized distribution from a calibrated prediction.

Lesson skeleton

See the path

Review this lesson

Why does “They” get 60% in the first turn of the Romans example? Start with four illustrative scores and see how softmax turns them into a distribution over the vocabulary.

TipThe one-minute mental model

Softmax turns logits into a distribution conditioned on the prefix. It guarantees positive values that sum to one; it does not guarantee calibration or factual truth.

From logits to a categorical distribution

At a given position, the model produces a logit \(z_i\) for each vocabulary token \(i\). Logits are unnormalized scores: they may be positive or negative and do not sum to one.

Softmax transforms these scores into probabilities:

\[ p_i=\operatorname{softmax}(z)_i=\frac{e^{z_i}}{\sum_{j=1}^{V}e^{z_j}}. \]

Probabilities are positive and sum to one. This normalization does not prove that the values are calibrated or that the most probable token is factually correct. Numerical implementations use stable softmax/log-softmax forms to reduce overflow risk.

Numerical example

For the prefix “What have the Romans ever done for us?”, take a toy vocabulary of four tokens. The logits in the output projection example are chosen to reproduce the probabilities of the first step in the running example. The exponentials sum to 10, so softmax divides each by 10.

Candidate token Logit Exponential Probability
“They” \(\ln 6\) 6 0.6
“Aqueducts” \(\ln 2\) 2 0.2
“Nothing” \(0\) 1 0.1
“Well” \(0\) 1 0.1

The illustrative continuation takes “They”. Once this token is appended to the prefix, the next generation step uses a new distribution.

Conditional probability in an autoregressive model

The next-token distribution depends on the prefix:

\[ p_\theta(x_t\mid x_{<t}). \]

The same token can therefore receive different probabilities depending on the prefix. The likelihood of a complete sequence combines conditional probabilities position by position; the product and its logarithm are covered in the likelihood lesson. Tokenization also matters: probabilities are assigned to tokenized units, not directly to words or semantic propositions.

At the same position, a softmax is applied within attention and another after the output projection. In Two softmax operations, two axes, compute what each one normalizes and test whether an attention weight can recover the next-token probability.

Normalization, calibration, and truth

  • Normalization: the algebraic property that probabilities sum to one.
  • Calibration: the empirical property that, over a relevant population, events assigned a given probability occur at a compatible frequency.
  • Factual truth: a property of the output relative to the world and available evidence; it does not follow from either of the preceding properties.

A probability of 0.9 therefore does not automatically mean “a 90% chance that the answer is true.” Calibration must be evaluated on relevant held-out data, and good overall calibration does not guarantee that each individual answer is reliable.

WarningMisconceptions
  • “A positive logit means high probability.” No: the sign depends on the score reference level. A logit of 10 can be less probable than another logit of 12.
  • “The largest logit measures the confidence gap.” The maximum determines the argmax, but uncertainty depends on all logits and their scale.
  • “Logits are directly comparable across models.” Not necessarily: architectures, temperatures, and training can produce different scales.
Common Fallacy: “Two models outputting the exact same top logit score share the same prediction confidence”

Counterexample: Model A outputs logits \((10, 2, 1)\) while Model B outputs \((10, 9.9, 9.8)\). Both have the same maximum logit (\(z_1 = 10\)). After softmax, model A assigns over 99% probability to the first token, compared with about 36.7% for model B. The distribution depends on all score differences, not the absolute maximum. A high probability does not establish calibration or the truth of a prediction.

From the distribution to a selected token

The softmax distribution is the model’s base predictive output. For generation, an optional policy can transform the logits (temperature), filter candidates (top-k/top-p), and then select a token. The mechanisms and trade-offs are developed in advanced decoding strategies.

  1. Logits
  2. Temperature ÷ τ
  3. Softmax
  4. Top-k/top-p filters
  5. Argmax or sampling
  6. Append token

Temperature scaling and filtering are optional. Temperature acts on logits before softmax. In the project reference implementation, top-k and top-p then filter the distribution and renormalize it; library pipelines may use different orders. Even a filtered distribution is not yet a selected token. See advanced decoding strategies for details.

Selecting the argmax token at each position is not equivalent to globally searching for the best sequence, and can produce text different from sampling. Decoding strategy is distinct from training.

During training, a loss function compares the logits with target tokens.

This distribution is the starting point for three uses. Generation selects a token. Scoring reads an observed token’s probability. Training aggregates target penalties into a batch objective.

Practice

The questions and exercises for this lesson are collected on its dedicated practice page.

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

Further reading

Another example with two candidates

With two logits \(z=(0,\log 3)\), softmax gives \(p=(0.25,0.75)\). The second token is more probable, but this distribution does not mean that it is three times more true: it reflects the model’s scores in this context.

References