What do temperature and top_p actually do, and how do you choose them per task?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Temperature divides the logits before the softmax. Below 1 it sharpens the distribution, above 1 it flattens it, and 0 collapses to greedy argmax. top_p (nucleus sampling) is a separate knob: it keeps the smallest set of tokens whose cumulative probability reaches p and renormalises. top_k keeps the k highest. Temperature changes the shape of the distribution, top_p and top_k change the size of the candidate pool.
Full worked answer with diagram
Temperature divides the logits before the softmax. Below 1 it sharpens the distribution, above 1 it flattens it, and 0 collapses to greedy argmax. top_p (nucleus sampling) is a separate knob: it keeps the smallest set of tokens whose cumulative probability reaches p and renormalises. top_k keeps the k highest. Temperature changes the shape of the distribution, top_p and top_k change the size of the candidate pool.
How I set them:
- Extraction, classification, tool calling, structured output: temperature 0, top_p 1. You want the most likely token, and you validate the output structurally anyway.
- Code generation: low, roughly 0 to 0.3. Higher buys nothing but plausible-looking bugs.
- Conversational or drafting: ~0.7 with top_p ~0.9 is a reasonable starting point, then tune on your eval.
- Self-consistency or any sample-and-vote scheme: you need temperature above 0, otherwise all k samples are identical and you have paid k times for one answer.
- Current frontier APIs: this table is for self-hosted open-weight models and older API models. The newest hosted models have removed the knobs: Anthropic's Opus 5.5 guide says to omit temperature, top_p and top_k, Sonnet 5 returns 400 on non-default values and Haiku 5.5 can too, GPT-6 Astra accepts no custom temperature, top_p or logprobs, and Gemini ignores them from 3.6 Flash with 400s planned for later generations. There the levers are effort level, structured outputs and system instructions. Open-weight cards still publish settings (Mistral Large 4 and Qwen3.8 recommend temperature 1.0 and top_p 0.95), so read the card rather than assuming 0.
Two things candidates get wrong. First, "temperature equals creativity" is a bad mental model. Temperature does not add knowledge or ideas, it just makes lower-probability tokens more likely to be picked, which on factual tasks mostly means more errors. Second, temperature 0 is not a determinism guarantee. Floating-point non-associativity, batching, and expert routing in MoE models mean identical requests can still diverge. If you need reproducibility, cache the response, pin the model snapshot and evaluate over multiple samples rather than trusting a single run, and treat a seed, where one is still offered, as best effort.
Do not aggressively tune temperature and top_p at the same time. Pick one as your primary knob, usually temperature, and leave the other at its neutral value so you can attribute changes.
Worth sketching. Putting the two knobs on either side of the softmax makes it obvious that one changes shape and the other changes the candidate pool.
flowchart LR
A["Logits"] --> B["Divide by temperature<br/>reshapes the distribution"]
B --> C["Softmax"]
C --> D["top_p keeps the smallest set<br/>reaching cumulative p"]
D --> E["Renormalise"]
E --> F["Sample one token"]
B -->|"T = 0"| G["Greedy argmax,<br/>pool of one"]
What a good answer covers
- Temperature divides the logits before the softmax
- Below 1 it sharpens the distribution, above 1 it flattens it, and 0 collapses to greedy argmax
- Extraction, classification, tool calling, structured output: temperature 0, top_p 1
- Code generation: low, roughly 0 to 0.3
- Conversational or drafting: ~0.7 with top_p ~0.9 is a reasonable starting point, then tune on your eval
Key terms: Code generation · Conversational or drafting · Self-consistency or any sample-and-vote scheme · Current frontier APIs
In the glossary: Temperature · Nucleus sampling (top-p) · Structured output · Self-consistency · Logprobs · MoE
Interviewer follow-ups to expect
Why does temperature 0 not guarantee identical outputs across identical requests?
If you had to raise diversity without raising error rate, what would you change instead of temperature?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep