A language model outputs one raw score ("logit") zi per vocabulary token. Temperature rescales the logits before the softmax turns them into a probability distribution:
P(i) = exp(z_i / T) / Σ_j exp(z_j / T)
T < 1 sharpens the distribution toward the top logit (more deterministic); T > 1 flattens it (more random). At the extreme T→0 it becomes greedy decoding — always the arg-max token.
Two truncation filters are then applied before sampling, exactly as real LLM APIs do:
- Top-k — keep only the k tokens with the highest probability, discard the rest.
- Top-p / nucleus — sort tokens by probability descending and keep the smallest prefix whose cumulative probability reaches p; this "nucleus" shrinks automatically when the model is confident and grows when it's unsure.
The surviving probabilities are renormalized to sum to 1, then a real random draw ("Sample next token") picks one token weighted by that final distribution. This 2D view lays the same math out as three linked panels instead of a 3D ring: a sorted bar chart of P(i), a cumulative-probability curve you can drag to scrub the nucleus threshold directly, and a temperature-response curve showing how the top token's probability would change across the whole T range for the current logits. Entropy H = −Σ P(i)·log₂P(i) measures how spread out the surviving distribution is.
Real-world relevance: every text-generating LLM (GPT, Claude, Gemini, LLaMA) exposes exactly these three knobs — temperature, top_k and top_p — to trade off creativity against reliability at each generation step.