# Temperature, top-k, top-p and min-p explained: how LLMs pick the next token, with numbers

Every token an LLM writes is a draw from a probability distribution. Temperature reshapes that distribution and top-k, top-p and min-p cut off its tail. This guide computes each one on the same example and shows when to use which.

A language model does not write a word. It writes a list of scores, one for every token in its vocabulary, and something else has to turn that list into a single choice. That something is the sampler. Four settings control it in almost every engine: temperature, top-k, top-p and min-p. They decide whether a model sounds rigid or loose, whether it repeats itself, and whether two runs of the same prompt give the same answer.

Anthropic's Claude API version 2026-10-21 rejects any request that sends `temperature`, `top_p` or `top_k`, and its migration guide says Claude 4.7 and later models already accept only the defaults. At the same time, open-weight engines such as vLLM and Hugging Face Transformers keep all four settings, plus min-p. If you run your own models you still need to understand the knobs. If you use a hosted frontier model, you need to know what you lose when they go away. This article computes each method on one example, so you can see exactly what it does.

## What happened

### Holtzman et al. introduce nucleus (top-p) sampling (22 April 2019)

The paper "The Curious Case of Neural Text Degeneration" by Ari Holtzman, Jan Buys, Li Du, Maxwell Forbes and Yejin Choi showed that pure greedy and beam decoding produce bland, repetitive text, while plain sampling wanders into nonsense. Their fix, nucleus sampling, samples only from the smallest set of tokens whose probabilities add up to a threshold p. Top-p became the default truncation method in most APIs.

### The min-p paper is posted and later accepted at ICLR 2025 (1 July 2024)

Minh Nhat Nguyen, Andrew Baker, Clement Neo, Allen Roush, Andreas Kirsch and Ravid Shwartz-Ziv posted "Turning Up the Heat: Min-p Sampling for Creative and Coherent LLM Outputs" on arXiv on 1 July 2024, and the paper appears in the ICLR 2025 proceedings. Min-p sets the cut-off relative to the most likely token's probability, so the threshold moves with the model's confidence. The authors report better quality and diversity than top-p on GPQA, GSM8K and AlpacaEval creative writing, especially at high temperatures. The latest arXiv version, v8, is dated 20 November 2025.

### A Stanford critique disputes the min-p results (16 June 2025)

Rylan Schaeffer, Joshua Kazdan and Yegor Denisov-Blanch posted "Min-p, Max Exaggeration". They re-ran a GSM8K sweep over 9 models, 31 temperatures and 3 seeds, which they put at about 6,000 A100-hours. Their conclusion is that "all samplers perform roughly the same once given the same amount of hyperparameter tuning". They also report that, in the original human evaluation, 1 of 12 comparisons stayed significant after Bonferroni correction. The lesson: sampler comparisons are easy to get wrong when one method gets more tuning.

### Claude API version 2026-10-21 removes sampling parameters

Anthropic's migration guide says that in API version 2026-10-21 "a request that sends `temperature`, `top_p`, or `top_k` returns a 400 error, even at the parameter's default value". Requests then sample with the defaults, including a temperature of 1.0. The guide notes that models which accept other values, such as Claude Sonnet 4.6, lose the effect of a lowered temperature, and that "no other setting replaces it". Callers who depend on a non-default value can keep that request on version 2023-06-01.

## From logits to probabilities: softmax with temperature

At each step the model outputs a logit z_i for every token i. Softmax turns logits into probabilities. Temperature T divides the logits first:

p_i = exp(z_i / T) / Σ_j exp(z_j / T)

T = 1 leaves the model's distribution unchanged. T below 1 sharpens it, because dividing by a small number stretches the gaps between logits. T above 1 flattens it. As T approaches 0 the distribution collapses onto the single highest logit, which is greedy decoding. Engines treat T = 0 as a special case; vLLM's documentation says "Zero means greedy sampling."

An everyday analogy: judges score dishes, and temperature sets how much the gap between scores matters. At low temperature the best-scored dish nearly always wins; at high temperature the runners-up win often.

### Worked example

Take a prompt such as "The capital of France is" and a toy vocabulary of six candidates with these logits: Paris 5.0, Lyon 3.0, the 2.5, a 2.0, Marseille 1.0, banana −1.0.

At T = 1 the arithmetic is: exp(5.0) = 148.41, exp(3.0) = 20.09, exp(2.5) = 12.18, exp(2.0) = 7.39, exp(1.0) = 2.72, exp(−1.0) = 0.37. The sum is 191.16. So p(Paris) = 148.41 / 191.16 = 0.7764, p(Lyon) = 0.1051, and so on.

Running the same calculation at five temperatures gives this table (computed with the code below):

| Token | Logit | T = 0.5 | T = 0.7 | T = 1.0 | T = 1.5 | T = 2.0 |
|---|---|---|---|---|---|---|
| Paris | 5.0 | 0.9729 | 0.9068 | 0.7764 | 0.5968 | 0.4848 |
| Lyon | 3.0 | 0.0178 | 0.0521 | 0.1051 | 0.1573 | 0.1784 |
| the | 2.5 | 0.0066 | 0.0255 | 0.0637 | 0.1127 | 0.1389 |
| a | 2.0 | 0.0024 | 0.0125 | 0.0387 | 0.0808 | 0.1082 |
| Marseille | 1.0 | 0.0003 | 0.0030 | 0.0142 | 0.0415 | 0.0656 |
| banana | −1.0 | 0.0000 | 0.0002 | 0.0019 | 0.0109 | 0.0241 |
| Entropy (bits) | | 0.215 | 0.591 | 1.164 | 1.774 | 2.080 |

Entropy, H = −Σ p_i log2 p_i, measures how spread out the choice is. It rises from 0.215 bits to 2.080 bits as temperature goes from 0.5 to 2.0. At T = 2.0 "banana" has a 2.41% chance per step. That is the problem truncation methods solve: high temperature buys variety, but it also lifts tokens that should never appear.

```chart
{"type": "line", "title": "Next-token probability by temperature (toy example)", "x": ["0.5", "0.7", "1.0", "1.5", "2.0"], "series": [{"name": "Paris", "data": [0.9729, 0.9068, 0.7764, 0.5968, 0.4848]}, {"name": "Lyon", "data": [0.0178, 0.0521, 0.1051, 0.1573, 0.1784]}, {"name": "the", "data": [0.0066, 0.0255, 0.0637, 0.1127, 0.1389]}, {"name": "banana", "data": [0.0, 0.0002, 0.0019, 0.0109, 0.0241]}], "xlabel": "temperature", "ylabel": "probability", "note": "Computed in the worked example above from logits 5.0, 3.0, 2.5, 2.0, 1.0, -1.0"}
```

## Cutting the tail: top-k, top-p and min-p

All three truncation methods do the same two things. They zero out some tokens, then renormalise the survivors so they sum to 1. They differ in how they choose the cut.

**Top-k** keeps the k most likely tokens. With k = 3 at T = 1 we keep Paris, Lyon and "the". Their mass is 0.7764 + 0.1051 + 0.0637 = 0.9452, so the renormalised probabilities are 0.7764 / 0.9452 = 0.8214, 0.1112 and 0.0674. The weakness is that k is fixed. When the model is confident, k = 3 may keep junk. When it is unsure, k = 3 throws away good options.

**Top-p (nucleus)** sorts tokens by probability and keeps the smallest prefix whose cumulative mass reaches p. The cumulative sums at T = 1 are 0.7764, 0.8815, 0.9452, 0.9839 and so on. With p = 0.9, the first sum at or above 0.9 is 0.9452, so top-p keeps three tokens. Here it gives the same answer as top-k = 3, but it adapts: on a flatter distribution it would keep more tokens.

**Min-p** keeps every token whose probability is at least p_base times the top token's probability. The threshold is p_base · p_max. With p_base = 0.1 at T = 1 the threshold is 0.1 × 0.7764 = 0.0776. Only Paris (0.7764) and Lyon (0.1051) pass, so the renormalised distribution is 0.8808 and 0.1192. "The" at 0.0637 is dropped. Hugging Face's documentation says typical min-p values are 0.01 to 0.2, "comparably selective as setting `top_p` in the 0.99-0.8 range".

| Method | Rule | Kept at T = 1 | Adapts to confidence? | Typical setting |
|---|---|---|---|---|
| Greedy | argmax | Paris only | No | T = 0 |
| Top-k | k most likely | 3 (k = 3) | No | k = 20 to 50 (Transformers default is 50) |
| Top-p | smallest set with mass ≥ p | 3 (p = 0.9) | Yes, by mass | p = 0.9 to 0.95 |
| Min-p | p_i ≥ p_base · p_max | 2 (p_base = 0.1) | Yes, by top token | p_base = 0.01 to 0.2 |

### Why min-p behaves differently at high temperature

The interesting case is what happens as temperature rises. The table below counts how many tokens each method keeps on our example (computed).

| Temperature | Top-p 0.9 keeps | Min-p 0.1 keeps | Mass outside min-p set |
|---|---|---|---|
| 1.0 | 3 | 2 | 0.1185 |
| 1.5 | 4 | 4 | 0.0524 |
| 2.0 | 4 | 5 | 0.0241 |

At T = 2.0 the min-p threshold is 0.1 × 0.4848 = 0.0485, so Marseille (0.0656) gets in and banana (0.0241) stays out. Min-p loosens as the top token loses confidence, but its cut-off is always tied to the leader, so an absurd token far below the leader never passes. On a near-flat distribution, for example logits 2.0, 1.9, 1.8, 1.7, 1.6, 1.5, min-p 0.1 keeps all six tokens, while top-k = 3 would discard 42.56% of the probability mass.

```chart
{"type": "bar", "title": "Tokens kept by each truncation rule (toy example)", "x": ["T=1.0", "T=1.5", "T=2.0"], "series": [{"name": "top-k 3", "data": [3, 3, 3]}, {"name": "top-p 0.9", "data": [3, 4, 4]}, {"name": "min-p 0.1", "data": [2, 4, 5]}], "xlabel": "temperature", "ylabel": "tokens kept", "note": "Computed with the Python code in this article"}
```

### Order of operations matters

Engines apply penalties, temperature and truncation in some order, and the order changes the result. On our example, applying T = 2.0 first and then min-p 0.1 keeps five tokens, with Paris at 0.4968. Applying min-p 0.1 to the T = 1 distribution first and then T = 2.0 keeps only two tokens, with Paris at 0.7311 and Lyon at 0.2689. Same settings, very different behaviour. Check your engine's documentation, and where an engine lets you reorder samplers, decide the order on purpose.

### The code

This is the exact script used for every number above. It runs with NumPy only.

```python
import numpy as np
logits = np.array([5.0, 3.0, 2.5, 2.0, 1.0, -1.0])  # Paris, Lyon, the, a, Marseille, banana

def softmax(z, T=1.0):
    z = z / T
    z = z - z.max()          # numerical stability
    e = np.exp(z)
    return e / e.sum()

def top_k(p, k):
    idx = np.argsort(-p)[:k]
    q = np.zeros_like(p); q[idx] = p[idx]
    return q / q.sum()

def top_p(p, tp):
    idx = np.argsort(-p)
    n = int(np.searchsorted(np.cumsum(p[idx]), tp) + 1)
    q = np.zeros_like(p); q[idx[:n]] = p[idx[:n]]
    return q / q.sum()

def min_p(p, m):
    q = np.where(p >= m * p.max(), p, 0.0)
    return q / q.sum()

p = softmax(logits, 1.0)
print(np.round(top_k(p, 3), 4))   # [0.8214 0.1112 0.0674 0. 0. 0.]
print(np.round(top_p(p, 0.9), 4)) # same three tokens
print(np.round(min_p(p, 0.1), 4)) # [0.8808 0.1192 0. 0. 0. 0.]

rng = np.random.default_rng(0)    # fixed seed for repeatable draws
draws = rng.choice(6, size=100_000, p=top_p(p, 0.9))
print(np.bincount(draws, minlength=6) / 100_000)  # about [0.8235 0.1097 0.0668 0 0 0]
```

The last line samples 100,000 times and recovers the renormalised probabilities, a quick test for any sampler you write.

## Settings in real engines

In vLLM's `SamplingParams`, the defaults are `temperature=1.0`, `top_p=1.0`, `top_k=0` and `min_p=0.0`. The docs say top-k "Set to 0 (or -1) to consider all tokens" and min-p "Set to 0 to disable this". There is also a `seed` for reproducible sampling, and three penalties: `presence_penalty` and `frequency_penalty` default to 0.0, and `repetition_penalty` defaults to 1.0, where values above 1 discourage repeats.

In Hugging Face Transformers, `GenerationConfig` reads defaults from the model's `generation_config.json`. If none are set, temperature is 1.0, top-k is 50 and top-p is 1.0. Sampling only happens when `do_sample=True`; otherwise generation is greedy. This catches people out: setting a temperature with `do_sample=False` does nothing.

You can explore the same knobs interactively in the [sampling simulation for temperature, top-k and top-p](/ai-simulations/sampling-temperature-top-p) and the [softmax temperature and min-p simulation](/ai-simulations/softmax-temperature-min-p). For how the deterministic alternatives work, see [greedy decoding versus beam search](/ai-simulations/beam-search).

### Sampling and speculative decoding

Sampling settings interact with serving speed. In speculative decoding, a small draft model proposes tokens and the large model accepts each with probability min(1, p_target / p_draft). With sampling, the acceptance rule depends on both the draft and target distributions, so the temperature you choose also changes how many drafted tokens survive. The [speculative decoding deep dive](/articles/speculative-decoding-acceptance-adaptive-verification) works through that acceptance maths, and the [speculative decoding simulation](/ai-simulations/speculative-decoding) lets you vary it.

## Use cases and examples

**1. A support team extracting order numbers.** A team uses an open-weight model behind vLLM to pull fields from customer emails. With T = 1 and top-p 0.9 on a distribution like our example, the top token is chosen about 82% of the time, so roughly 18% of first tokens differ between runs. For extraction that is noise, not creativity. The setup that fits is T = 0 (greedy), and better still a schema constraint such as [structured outputs](/tools/structured-outputs), so every answer parses.

**2. A writing assistant at high temperature.** A product team wants livelier story drafts and raises T to 1.5. On our example, the 'banana' token has a 1.09% chance per step at T = 1.5. If every step looked like that, the chance of avoiding it across 200 tokens would be 0.9891^200 ≈ 11%, so almost every long draft would contain at least one absurd pick. Adding min-p 0.1 removes the 5.24% of mass outside the kept set at each step, which includes banana, while still keeping four candidates.

**3. Self-consistency on maths questions.** A research group samples five answers per problem and takes a majority vote, the method described in the site's [self-consistency article](/articles/self-consistency-majority-vote-reasoning). Greedy decoding would return five identical answers, so the vote adds nothing. With sampling, if each answer is independently correct with probability 0.6 and the vote is a simple majority, the chance that at least 3 of 5 are correct is 0.6826, and with nine samples it is 0.7334 (binomial calculation). Diversity from sampling is what makes the vote work. The [pass@k simulation](/ai-simulations/pass-at-k-vs-pass-power-k) shows the related effect on code scores.

**4. A platform team migrating to Claude API version 2026-10-21.** A team's wrapper sends `temperature: 0.2` on every Claude call. After the version upgrade, every request returns HTTP 400 until the parameter is removed, according to Anthropic's migration guide. On Claude 4.7 and later models nothing changes in output, because those models already sample only with the defaults. On Claude Sonnet 4.6, the lowered temperature is lost. Their fix is to strip the three fields in the wrapper and, where consistent output matters, to rely on prompting, structured outputs and evaluation rather than temperature.

## What it means in practice

Sampling is a small part of the stack with a large effect on behaviour. Temperature changes the shape of the distribution; truncation removes the tail; the order of the two matters. If you run open-weight models, a reasonable default is a moderate temperature with one truncation method, not three stacked together. If you use hosted frontier models, expect fewer knobs over time. Reproducibility then has to come from prompts, schemas and evaluation. For the bigger picture of where sampling sits in a model, see [inside a large language model](/topics/generative-ai-llms/inside-an-llm) and the [vLLM tool page](/tools/vllm).

## What to do now

1. **Audit your requests.** Search your code for `temperature`, `top_p` and `top_k` and record which provider and API version each call uses.
2. **Remove sampling fields before upgrading Claude API versions.** Version 2026-10-21 returns 400 for any of the three, even at default values.
3. **Use greedy decoding for extraction and classification.** Set T = 0 or `do_sample=False`, and add a schema constraint where the engine supports it.
4. **Pick one truncation method.** Use top-p around 0.9 to 0.95 or min-p around 0.05 to 0.1; stacking several makes behaviour hard to predict.
5. **Check the sampler order in your engine.** The same settings in a different order kept two tokens instead of five in our example.
6. **Tune samplers with equal budgets.** When comparing methods, give each the same number of hyperparameter trials and seeds, as the min-p critique recommends.
7. **Fix seeds for tests.** Set `seed` in vLLM or a NumPy generator in your harness so regressions are visible rather than random.
8. **Watch for silent no-ops.** In Transformers, temperature without `do_sample=True` is ignored; log the effective settings.

## Risks and open questions

**Temperature is not a truthfulness dial.** Low temperature makes output more repeatable, not more correct. A confident wrong answer stays wrong at T = 0.

**Benchmarks of samplers are fragile.** Unequal tuning can create gains that vanish under a fair comparison.

**Hosted APIs are converging on fixed sampling.** When providers remove the parameters, teams lose a familiar lever and must rely on prompts and schemas. How well that replaces lowered temperature for consistency-sensitive tasks is still an open question.

**Watch next:** whether other hosted providers follow the Claude API in removing sampling parameters, and whether open-weight engines settle on a standard default order for penalties, temperature and truncation.

## Frequently asked questions

### What temperature should I use?

For extraction, classification and code that must parse, use 0 (greedy). For general chat, values around 0.7 to 1.0 are common. For brainstorming, go higher but add a truncation method such as min-p so the tail stays out.

### Is top-p better than top-k?

Top-p adapts to how confident the model is, while top-k always keeps the same number of tokens. That usually makes top-p the safer default. When a fair comparison gives both methods the same tuning budget, the differences are often small.

### Does min-p really beat top-p?

The original paper reports gains, especially at high temperature. A 2025 critique found that samplers perform roughly the same once tuned equally, with weak evidence for min-p at high temperatures. Treat it as a useful option, not a guaranteed improvement.

### Why does my model give different answers with temperature 0?

Greedy decoding is deterministic in theory, but batching, floating-point non-associativity and different hardware kernels can change logits slightly. When two tokens are nearly tied, that small change can flip the choice. Fixed seeds and identical serving setups reduce, but may not remove, the variation.

### What do I lose when an API removes temperature?

You lose the ability to make output more consistent by lowering temperature. Anthropic's guide says no other setting replaces it. Prompting, structured outputs and evaluation become the main tools for consistency.

## Summary

A sampler turns logits into one token. Temperature divides logits before softmax, sharpening or flattening the distribution; on our example it moved entropy from 0.215 to 2.080 bits. Top-k keeps a fixed number of tokens, top-p keeps the smallest set reaching a mass, and min-p keeps tokens above a fraction of the leader's probability, which loosens with uncertainty but never admits far-tail tokens. The order of operations changes results, and sampler comparisons need equal tuning to be fair. Hosted APIs such as Claude's version 2026-10-21 now remove these parameters entirely, while open-weight engines such as vLLM and Transformers keep them, so knowing how they work matters most when you run your own models.

## Sources

- [arXiv: The Curious Case of Neural Text Degeneration (Holtzman et al.)](https://arxiv.org/abs/1904.09751)
- [arXiv: Turning Up the Heat: Min-p Sampling for Creative and Coherent LLM Outputs](https://arxiv.org/abs/2407.01082v8)
- [ICLR 2025 Proceedings: Min-p Sampling for Creative and Coherent LLM Outputs](https://proceedings.iclr.cc/paper_files/paper/2025/hash/afa5f124e36bed5cc2125067005d43f5-Abstract-Conference.html)
- [arXiv: Min-p, Max Exaggeration: A Critical Analysis of Min-p Sampling](https://arxiv.org/abs/2506.13681)
- [Anthropic: Migrating to API version 2026-10-21](https://platform.claude.com/docs/en/api/migration-2026-10-21)
- [vLLM: Sampling parameters API reference](https://docs.vllm.ai/en/v0.11.0/api/vllm/sampling_params.html)
- [Hugging Face: Text generation and GenerationConfig](https://huggingface.co/docs/transformers/main_classes/text_generation)
