Skip to content

Block 04 / 07

Probability and uncertainty

The model outputs a probability distribution over tokens.

At each step the model assigns mass to every token, then you draw. GreedyGreedy decoding: picking the single highest-probability token at every step, with no search over alternative paths., temperatureA scalar that rescales a model’s logits before the softmax. Values below 1 sharpen the distribution toward the top tokens; values above 1 flatten it toward the tail., top-pNucleus sampling. Sorts tokens by probability and samples from the smallest set whose cumulative mass passes a threshold p, so the pool size adapts to the shape of the distribution instead of staying fixed., constrained decodingRestricting which tokens can be sampled at each step, with a grammar or schema, so the output is guaranteed to be well-formed.: those are policies over a distribution. There is no hidden true answer behind the softmaxThe function that turns a vector of logits into a probability distribution: exponentiate each score and divide by the sum, so the outputs are positive and add to 1.. Hallucination is mass on a fluent lie. Useful variation is mass you wanted. Calibration is whether “0.8” means 80% on a held-out set.

Accuracy is specified as a distribution, a decoding policy, and a verification procedure. TemperatureA scalar that rescales a model’s logits before the softmax. Values below 1 sharpen the distribution toward the top tokens; values above 1 flatten it toward the tail., schemas, and evaluations follow from that specification rather than from ad hoc preference.

Figure

P(next token | “The weather tomorrow will be…”)0.250.50.751.0044%sunny24%cloudy18%rainy7%mild3%cold2%windy1%terrible0%purple

Temperature 1.00 · calibrated, close to the training distribution

Drag the slider to change temperature. Toggle the cutoff to see which tokens survive nucleus sampling.

Eight candidate next tokens for the same prompt, ranked by the model’s logits. Temperature rescales those logits before the softmax: low values collapse the draw onto the top token, close to greedy decoding, and high values spread mass toward the tail, including a token like “purple” that has no business following this prompt. Nucleus sampling keeps a variable-size set of the most probable tokens instead of a fixed count, trimming the part of the tail a fixed temperature alone cannot always reach.

Algorithms

A decoding policy turns that distribution into one chosen token, repeated until the sequence ends. The three families below make the same choice, how much of the distribution’s tail to trust, in three different ways.

Reference

In practice

The model assigns mass to tokens. Sampling, calibration, and constrained decoding are policies over that distribution.

Laboratory

Decoding policy as an experiment

Pick one extraction task and one open-ended task. Run the same prompts twenty times at temperature 0 and at 0.8 (and at one constrained-decoding setting if the API allows). Score schema validity, exact match or a factual check, and disagreement across runs. Plot the tradeoff.