
Model scoring (probabilities)
For each next-token step the model produces a probability distribution over possible tokens. For example, after the prompt “The sky is ___” the model might assign:- “blue” — 62%
- “clear” — 21%
- “gray” — 9%
- “falling” — 5%
- “purple” — 2%
Sampling: how a token is chosen
Sampling is the mechanism that picks a token from the scored list. Most implementations use weighted random sampling: each token’s probability becomes its chance of being selected. Because sampling can pick lower-probability tokens, repeated runs of the same prompt can produce different continuations. Once a different token is chosen, the subsequent context changes and the rest of the output can diverge significantly.
Temperature — the randomness dial
Temperature is a common control exposed in APIs and playgrounds that reshapes the model’s probability distribution before sampling. It doesn’t change the model’s knowledge; it changes how likely lower-scoring tokens are to get sampled.- Near 0.0: distribution sharpens so the highest-scoring tokens dominate. Outputs become very repeatable — useful for tasks requiring deterministic answers (parsing, extraction, classification).
- Moderate values (e.g., 0.7–1.0): produce more natural, varied text. Many chat interfaces default here for conversational balance.
- High values (>1.0): flatten the distribution, making low-probability tokens much more likely. This increases creativity and randomness but can produce incoherent or off-topic outputs.
- At
temperature = 0.0you’ll usually get a restrained, repeatable introduction. - At
temperature = 1.6or2.0outputs are often more creative — sometimes unexpectedly so (different language, emojis, or odd phrasing).
Note — top-k and top-p sampling
Temperature is only one knob. Two other widely used sampling strategies operate on the same scored list:- Top-k: keep only the top
ktokens by score and sample from that reduced set (a rank cutoff). - Top-p (nucleus sampling): keep the smallest set of top tokens whose cumulative probability ≥
p(e.g.,p = 0.90). This adapts the pool size based on model confidence: small when confident, larger when uncertain.

Practical guidelines
- Adjust one knob at a time (temperature, top-k, or top-p) to understand each effect.
- For deterministic extraction pipelines: prefer
temperature ≈ 0.0. Considertop-kortop-pto further constrain outputs. - For brainstorming or creative writing: increase temperature or relax
top-pto encourage variety. - Lowering temperature increases repeatability, not correctness. If the model’s highest-scoring answer is wrong,
temperature = 0.0will return the same wrong answer consistently.
Lower temperature improves repeatability but does not fix factual errors. Use grounding, verification, or retrieval-augmented techniques if you need correctness.
Temperature controls randomness (repeatability vs. diversity). It does not change what the model “knows” — it only changes which scored tokens are allowed to win more often.
Summary
- The model scores every candidate token at each step.
- Sampling (weighted random, top-k, top-p) chooses the actual token from that scored list.
- Temperature and sampling controls let you tune the trade-off between repeatability and creativity.