Pair each decoding strategy with its determinism and diversity profile.
Greedy picks the argmax token every step (deterministic). Temperature sampling draws stochastically (diverse). Temperature 0 collapses to greedy.
Imagine guessing the next word in a sentence. The safe strategy is to always pick the single most likely word. You get the same answer every time, but the writing feels stiff and repetitive. The creative strategy is to roll a weighted die over several likely words and pick based on the roll. The result varies and feels more natural, but you might roll an unlucky word once in a while. A knob called temperature controls how spread out the die is. Crank it to zero and the die only shows one face, the safe choice. Raise it and the die spreads out, getting wilder. Beam search keeps several whole sentences alive in parallel and picks the best at the end, which costs more time but finds smoother sequences.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: define greedy as argmax, walk through temperature scaling and why T=0 collapses to greedy, contrast top-p and top-k as tail-suppression filters, position beam search in its remaining niches, then close on production settings per task type.
Real products, models, and research that use this idea.
- OpenAI's GPT-5.5 API exposes temperature, top_p, and seed; setting temperature 0 and a fixed seed gives near-deterministic outputs for evals.
- Anthropic's Claude Opus 4.7 uses temperature, top_p, and top_k; defaults are tuned for chat at T=1.0 with top_p=0.999.
- vLLM and SGLang implement greedy as a special-case argmax to avoid divide-by-zero when temperature is exactly zero.
- DeepSeek V4 reasoning mode uses self-consistency sampling: 8 samples at T=0.7, majority vote for the final answer, used in chain-of-thought prompting.
- Hugging Face transformers generate API supports beam search with num_beams parameter, mostly used for translation models like MarianMT and NLLB.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does setting temperature exactly to zero collapse sampling to greedy?
QHow do top-p and top-k differ in failure modes?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating temperature as quality: low equals good, high equals bad. Temperature is a creativity vs determinism knob; the right value depends on the task, and zero is wrong for creative writing.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.