Log inStart free
LESSON 29.20 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Top-k, top-p and min-p

Watch three filters cut the tail of the next-token odds before each draw.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 29.20 · DECODERTOP: CAT 0.383 · AFTER DOG: RAN 0.710
01
Stage 1 of 5 · Ranked tokens
The model ranks the 10 tokens by probability. The top token has 0.383 after “the” and 0.709 after “dog”.
Explain it simply

Each row is one word the model could write next, sorted from most to least likely. In the list after the, the chances are spread out. In the list after dog, one word holds most of the chance. The low rows at the bottom are the tail.

Two lists of 10 token rows with probability bars. After “the”, “cat” leads with 0.383. After “dog”, “ran” leads with 0.709.

probabilities, outputcut, draw udropped tokens (dashed)old p (renormalize)
step 1, after “the”compare: after “dog”the0.007cat0.383dog0.314sat0.019ran0.019on0.012mat0.141rug0.094and0.007.0.00410 tokens, Σ p = 1the0.013cat0.008dog0.005sat0.064ran0.709on0.043mat0.013rug0.013and0.079.0.05310 tokens, Σ p = 1thestep 1, after “the”compare: after “dog”the0.007cat0.383dog0.314sat0.019ran0.019on0.012mat0.141rug0.094and0.007.0.00410 tokens, Σ p = 1the0.013cat0.008dog0.005sat0.064ran0.709on0.043mat0.013rug0.013and0.079.0.05310 tokens, Σ p = 1the
Toy: the 29.19 bigram model over 10 tokens, prompt “the”, 8 steps, T = 1
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
pi=ezi∑jezj\sy{p}{out}{p_i} = \dfrac{e^{\sy{z}{data}{z_i}}}{\sum_j e^{z_j}}
pcat=e2.0/19.29≈0.383p_{\text{cat}} = e^{2.0} / 19.29 \approx 0.383

Softmax turns each logit into a probability.

Common mix-ups

MYTHA fixed k keeps the likely tokens at every step.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With top-k at k = 1, what does sampling become?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.