Inference Engineeringexplorer

Token sampling explorer

A language model doesn’t pick the next word. It gives every token in its vocabulary a score, called a logit, and a sampler turns those scores into probabilities and draws one. Temperature, top-k, top-p and min-p are the knobs on that sampler.

Most likely next token

The cat sat on the mat

Tokens kept5 of 12“mat” is the most likely, at 60.2%
  1. Softmax12 keptraw logits
  2. Temperature12 keptT = 0.8
  3. Top-k12 keptoff
  4. Top-p5 keptp = 0.9
  5. Min-p5 keptoff

Sampling settings

0 is greedy: always the top token.

0 turns it off.

1 turns it off.

0 turns it off.

Probabilities

Show one step

Before top-pAfter, renormalised to sum to 100%

  1. mat55.7% → 60.2%
  2. floor14.1% → 15.2%
  3. couch11% → 11.8%
  4. bed6.7% → 7.2%
  5. sofa5.2% → 5.6%
  6. chairremoved by top-p
  7. windowsillremoved by top-p
  8. roofremoved by top-p
  9. tableremoved by top-p
  10. keyboardremoved by top-p
  11. moonremoved by top-p
  12. bananaremoved by top-p
Entropy before2.51 bitsRaw softmax
Entropy after1.72 bits0 bits means one possible token
Illustrative numbers

These 12 candidates and their logits were made up to show how the filters behave; they don’t come from a real model. This tool applies temperature, then top-k, then top-p, then min-p, renormalising after each. Libraries differ in which filters they offer and the order they run them, and with several filters on, the order changes the result.

What it shows

A language model scores every token it could say next. These scores are logits. A sampler turns them into probabilities and draws one. Temperature, top-k, top-p and min-p are its knobs.

The tool runs them in turn on 12 made-up candidates for “The cat sat on the”. Change a setting to see which tokens survive each step and what 20 samples look like.

How to read it

  • Softmax turns logits into probabilities that add up to 100%.
  • Temperature divides every logit first. Below 1 the top token gains; above 1 unlikely tokens gain. At 0 the sampler always takes the top token.
  • Top-k keeps the k most likely tokens. Top-p keeps the smallest set whose probabilities reach p. Min-p drops tokens below min-p times the top token’s probability.
  • After each filter the survivors are renormalised to 100%. Pick a step to see its before and after bars.
  • The order is temperature, top-k, top-p, min-p. Libraries differ, and with several filters on, order can change the result.
  • Entropy, in bits, shows the spread. 0 bits means only one token is possible.

Questions

What’s the difference between top-k and top-p?

Top-k keeps a fixed number of tokens, however the probability is spread. Top-p keeps however many tokens it takes to cover a share of the probability: few when the model is confident, many when it isn’t. Holtzman and colleagues introduced top-p as nucleus sampling in 2019.

What does min-p do that top-p doesn’t?

Min-p sets its cut-off relative to the top token: a token survives if its probability is at least min-p times the top token’s. When the model is confident, the cut-off is high and few tokens pass; when it is unsure, more do. Nguyen and colleagues describe and evaluate it in a 2024 paper.

Is temperature 0 always the same output?

In this tool, yes: temperature 0 means take the most likely token. On a real serving stack, the same prompt at temperature 0 can still produce different outputs, for example when numerical differences change which token is on top.

Why do the numbers differ from my library?

The candidates here are illustrative, and libraries differ in which filters they support, their defaults, and the order they apply them in. Check your library’s documentation for its exact behaviour.

Sources

Explore further

Last updated

More tools

All tools

Your first senior-level
lesson is free.

Choose a course, open a free lesson, and explore an idea you’ve wanted to understand.