What the model actually produces
A text-generation system scores possible next tokens and uses a decoding method to select one. Some APIs expose sampling settings. Others manage decoding without exposing those controls. The following is a simplified sampler for a model that supports these settings.
A common sampling pipeline works as follows:
- Divide every logit by the temperature.
- Apply softmax to turn the scores into probabilities summing to 1.
- Optionally cut the tail: top_k keeps the k highest, top_p (nucleus) keeps the smallest set whose probabilities sum to at least p.
- Draw one token at random from what is left.
Temperature divides before the softmax, so it stretches or flattens the distribution. At temperature=2 the gaps between candidates shrink and unlikely tokens become reachable. At temperature=0.1 the top candidate dominates. At exactly 0, most implementations skip sampling and take the argmax.
Temperature changes the relative probabilities in this simplified sampler. It does not establish whether a generated claim is true. Hosted implementations and supported controls vary by model.
Check which controls the model supports
Claude Sonnet 5.5, used in this chapter’s request examples, rejects temperature, top_p and top_k. Leave them out of those requests. Current model controls.
For a model that exposes temperature, compare low settings for a repeatable classification task and higher settings for varied drafts. Treat ranges as experiment settings. Measure task accuracy and output variety separately. A low temperature cannot guarantee factuality or a valid schema.
Change one supported control at a time, record its value and compare results on a fixed test set. This makes the effect easier to interpret.
Temperature 0 is not deterministic
For a model that accepts zero temperature, repeated requests can still differ. Numerical computation, serving behavior or a changed model version are possible causes. Different answers alone do not identify the cause.
Floating-point addition is not associative. Summing a batch of numbers on a GPU in a different order gives a very slightly different result. Two logits that are nearly tied can swap places. One swapped token at position 40 can change the tokens after it, because each token conditions the next. A rounding difference in the twelfth decimal place becomes a different paragraph.
Batching can affect computation. Some serving systems group concurrent requests. Depending on the kernels and their reproducibility guarantees, changes to batch shape can affect numerical results.
Some mixture-of-experts implementations have capacity-dependent routing. Such routing may introduce another source of variation. Its relevance depends on the model and serving implementation.
Some providers expose a seed or a serving-version identifier. Follow that provider’s reproducibility contract and log the supported metadata. A seed alone does not establish that every part of inference is deterministic.
What to do about it
Choose checks that match the task. Exact strings can be appropriate for an enumerated label. Structured fields are useful when several phrasings are acceptable.
The following illustrative fixtures compare exact prose matching with checks on selected structured fields. The production test still needs the expected values for its own case.
import json
prose = "The refund window is 30 days."
assert prose == "The refund window is 30 days."
structured = '{"days": 30, "currency": "INR"}'
data = json.loads(structured)
assert data["days"] == 30
assert data["currency"] in {"INR", "USD"}Three habits follow from that:
- Where you can, make the model emit structured output and assert on the fields. A number in a field is checkable; a sentence is an argument.
- Where you cannot, assert on invariants: it cited at least one source, it did not mention a competitor, it stayed under 200 words, it refused an out-of-scope question.
- To reuse a reviewed answer, cache it under the relevant inputs, prompt version, model version and access scope. Set an expiry or invalidation rule when its source data can change.
The uncomfortable consequence
A single success or failure is limited evidence. Under an illustrative model of independent attempts with a 95% success probability, four attempts all succeed about 81% of the time. Repeated evaluations on representative cases help estimate performance, and failures reveal cases that need investigation.
This is the reason the evaluation module later in this course exists, and it is why builders who skip it end up debugging by anecdote.
Check your understanding
The model weights, request input and greedy decoding rule are confirmed unchanged. Which numerical mechanism can still change the selected token when scores are nearly tied?
Pick the one you would defend. Your answer stays private.
Your place and first choices stay on this browser. Classroom credit is recorded separately.
Every lesson here is open. Your progress is recorded once you pass the Python, from Zero, for AI exam.
Stuck on something?Ask Sayali, your AI tutor