Min-P Sampling
You keep only the tokens that score at least a fixed fraction of the best token. When the leader is strong the bar is high, and when the race is close the bar drops.
Why Does This Exist?
Every time you ask a model for the next word, it scores its whole vocabulary and turns those scores into probabilities that sum to one. You then have to draw one token, but drawing from the raw list is reckless. Thousands of weak long-shot tokens each hold a sliver of mass, and one of them will eventually come up. So you truncate first and sample second. The full setup lives in next-token prediction.
Top-P sampling is the usual truncation. It sorts tokens from best to worst, adds up probabilities until the running total hits a target such as 0.90, and keeps that head of the list. Top-K sampling does the same job with a fixed head count, and temperature shapes the list before either rule runs.
Top-P has one weak spot, and it matters. A crowd of weak tokens can pool their mass to reach the target. Picture a leader at 0.40 with sixty also-rans at 0.01 each. The total is exactly . Top-P with keeps the leader plus fifty of those 0.01 tokens, because . The kept mass is , and the mediocre share is . You now face about a 56 percent chance of drawing a token you never wanted, not because any one of them looked good, but because together they filled the quota.
min-p sampling answers with a relative threshold. It keeps a token only if that token stands close enough to the leader, no matter how many weak tokens wait behind it. This page covers that rule and its worked arithmetic. For the cumulative-mass rule it replaces, read Top-P first. For the shaping steps around it, read temperature and repetition penalties.
Think of It Like This
A sieve that sizes its holes from the biggest stone
You tip a bucket of stones onto a sieve. First you find the biggest stone, then you set the hole size to one-tenth of it. If the biggest stone is a melon-sized rock, the holes are large and only a few big stones stay on top. If the biggest stone is a pebble and everything else is nearly the same size, the holes shrink and almost everything stays.
Min-p works the same way. The biggest stone is the top probability, the hole size is the cutoff, and staying on the sieve means surviving to the final draw.
Where it stops: stones keep their size, but token probabilities are fresh guesses at every step. And sieving finishes the job, while min-p only filters. A dice roll among the survivors still picks the token.
How It Actually Works
You start with one probability per token after temperature, a list that sums to one. Call the probability of token by the name . Call the largest probability in that list , which means the most likely token. Pick a fraction , which is the min_p setting such as . The cutoff is , defined as . Nothing is sorted. One pass finds the maximum, one pass filters, and you will renormalise what survives.
The cutoff rule
- Find , the single largest value in the distribution.
- Compute . With and , you get .
- Keep every token with . Set the rest to zero.
- Divide each survivor by the sum of the survivors so the kept probabilities sum to one again, then sample.
Because is a fraction of the leader, the bar follows the shape. A dominant leader pushes up and the crowd is cut. A flat field pulls down and the options survive. You trade diversity for coherence with : raise it and answers get safer and duller, lower it and answers get wider and stranger.
Worked example
Take six tokens with probabilities . Check the sum first: , plus is , plus is , plus plus is . Good, this is a real distribution.
Set . The leader is , so . Keep : that is , and . Cut , and . Three stay, three go, exactly as the diagram shows.
The survivor mass is . Renormalise by dividing each survivor by :
Those three sum to up to rounding. Sampling now draws only from the three survivors with those odds.
Why the bar moves with confidence
Now take a flat field where the model is unsure: . The sum is plus five times , which is , for total. The leader is , so . The smallest token is , far above . All seven survive.
That is the behaviour you want. Don't use min-p when you need wide-open brainstorming and the field is already flat, because even a small can still bite when one token edges ahead. And don't trust the leader blindly: min-p assumes the top probability signals real confidence. When the model is confidently wrong, a high leader sets a high bar and locks out the valid alternatives. That is the failure to watch for, and it is why factual answers earn a higher while open-ended drafts earn a lower one or none at all.
Code
Use this snippet to check the worked example. It filters the same six probabilities, counts the survivors, and prints the renormalised list.
def min_p_filter(probs: list[float], min_p: float) -> list[float]: cutoff: float = max(probs) * min_p kept: list[float] = [p if p >= cutoff else 0.0 for p in probs] total: float = sum(kept) return [p / total for p in kept]
probs: list[float] = [0.50, 0.30, 0.12, 0.04, 0.02, 0.02]filtered: list[float] = min_p_filter(probs, 0.10)print(max(probs) * 0.10) # -> 0.05print(sum(1 for p in filtered if p > 0)) # -> 3print([round(p, 4) for p in filtered]) # -> [0.5435, 0.3261, 0.1304, 0.0, 0.0, 0.0]The three prints confirm the hand computation: the cutoff is , three tokens survive, and the renormalised survivors match with zeros where the cut tokens were.
Watch Out For
Cranking min-p until creativity dies
You raise min_p to clean up rambling answers, and suddenly every story starts the same way. Raising temperature does nothing. The symptom is a survivor count stuck at one or two even on open-ended prompts: the filter turns sampling into greedy decoding.
The cause is a bar set for factual answers applied to creative ones. With a leader at and , the cutoff is and only two tokens survive. Lower for open work, keep it higher only for short factual answers, and log how many tokens survive per step while you tune.
Filtering and forgetting to renormalise
You zero out the cut tokens in a hand-rolled sampler and the draws look wrong. Cut tokens still appear, or the kept odds do not match your arithmetic. The symptom is a distribution that sums to the survivor mass, such as instead of .
Never skip the renormalisation. Divide each survivor by the sum of the survivors and assert the result sums to one before you sample. Library samplers do this for you, but your own code must do it explicitly.
The Quick Version
- Min-p sampling keeps a token only when its probability is at least a fraction of the top probability .
- The cutoff is , so a leader with sets the bar at .
- A strong leader raises the bar and cuts the mediocre crowd, while a flat field lowers the bar and keeps the options.
- Survivors must be renormalised to sum to one before the final draw happens.
- Min-p assumes the leader signals real confidence, so it locks in mistakes when the model is confidently wrong.