---
title: Explain greedy decoding, beam search, temperature, top-k, top-p and min-p. Which settings would you pick for (a) a JSON…
url: https://gurkanozkan.ai/learn/questions/applied-llm-fnd-07/
markdown: https://gurkanozkan.ai/learn/questions/applied-llm-fnd-07.md
kind: question
role: Applied LLM
stage: Technical
difficulty: Easy
json: https://gurkanozkan.ai/api/learn/questions/applied-llm-fnd-07.json
robots: noindex
---

# Explain greedy decoding, beam search, temperature, top-k, top-p and min-p. Which settings would you pick for (a) a JSON extraction endpoint, (b) a creative-writing feature, (c) code completion — and why?

Applied LLM · Technical · Easy

Theme reported publicly: [Cohere](https://www.aced.io/experiences/cohere-staff-machine-learning-engineer-interview-b49af6), [Google DeepMind](https://www.techinterview.org/post/3233474918/deepmind-interview-process-2026/)

## Answer

*Model answer, written in a candidate's voice*

### In short

- Temperature scales logits before softmax; lower T sharpens towards greedy, higher T flattens; top-k keeps k highest-probability tokens; top-p keeps smallest set with cumulative probability >= p; min-p keeps tokens above a fraction of the top token's probability.
- Greedy picks argmax each step; beam search keeps B highest-likelihood partial sequences and is good for short constrained outputs like translation/ASR but bland/repetitive and costly for open-ended text.
- (a) JSON extraction: greedy or very low temperature plus schema-constrained/structured decoding, stop sequences, max tokens, validation/retry.
- (b) Creative writing: moderate temperature with top-p (or min-p), repetition penalty, stop sequences, max tokens; avoid greedy.
- (c) Code completion: low temperature/greedy, optionally best-of-n samples ranked by tests/static checks/self-consistency, with stop sequences and max tokens.

### In full

Temperature divides logits before softmax, so T→0 approaches greedy decoding while T>1 flattens the distribution; top-k keeps only the k most likely tokens, top-p keeps the smallest set whose cumulative probability is at least p, and min-p keeps tokens whose probability is at least a fraction of the top token's probability. Greedy decoding chooses the argmax token each step and is deterministic in principle (floating-point and batching effects aside) but can be repetitive; beam search keeps B partial sequences and maximises sequence likelihood, which helps short constrained outputs like translation or ASR but is bland/repetitive and expensive for open-ended text. For (a) a JSON extraction endpoint I would use greedy or very low temperature with schema-constrained/structured decoding, stop sequences, a max-token cap, and validation/retry rather than sampling. For (b) creative writing I would use moderate temperature with top-p around 0.9 (or min-p), plus repetition penalty, stop sequences and max tokens, accepting some diversity. For (c) code completion I would use low temperature or greedy decoding, optionally best-of-n samples ranked by tests/static checks or self-consistency, with stop sequences and max tokens; I would not use high temperature or beam search for open-ended generation.

*Corrected by an independent AI reviewer.*

## What a strong answer covers

- Temperature scales logits before softmax (→0 approaches greedy); top-k keeps the k most likely tokens; top-p keeps the smallest set whose cumulative probability ≥ p; min-p keeps tokens above a fraction of the top token's probability
- Beam search maximises sequence likelihood — good for short, constrained outputs (translation, ASR), bland or repetitive for open-ended text, and costly
- (a) greedy/low temperature plus schema-constrained decoding; (b) moderate temperature with top-p; (c) low temperature, optionally several samples ranked by tests
- Mentions stop sequences, max tokens, repetition penalties, best-of-n/self-consistency

## Common mistakes

- Claiming temperature 0 guarantees correctness
- claiming beam search is always better because it finds higher-probability text

## Topic guides

- [LLM inference: decoding, batching, quantisation and speculative decoding](https://gurkanozkan.ai/learn/topics/inference.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
