The table shows the next-token distribution at one decoding step for the context "The customer wants to ___". With top-p = 0.9 (nucleus sampling, no top-k), which tokens can be sampled, and what is the probability of cancel after filtering?
| Rank | Token | Probability |
|---|---|---|
| 1 | cancel | 0.42 |
| 2 | upgrade | 0.23 |
| 3 | return | 0.15 |
| 4 | change | 0.09 |
| 5 | close | 0.06 |
| 6 | dispute | 0.03 |
| 7 | buy | 0.02 |
Show the answer and explanation
Correct answer: C, Five tokens (cancel to close), because the nucleus is the smallest set whose cumulative probability reaches 0.9; after renormalising, cancel has probability ≈ 0.44.
Explanation Decoding & Sampling
Nucleus (top-p) sampling algorithm:
- Sort tokens by probability, highest first.
- Keep the smallest prefix whose cumulative probability is ≥ p.
- Set all other probabilities to zero and renormalise the kept ones to sum to 1.
- Sample from the renormalised distribution.
| Token | p | Cumulative | Kept? | Renormalised |
|---|---|---|---|---|
| cancel | 0.42 | 0.42 | yes | 0.42 / 0.95 ≈ 0.442 |
| upgrade | 0.23 | 0.65 | yes | 0.242 |
| return | 0.15 | 0.80 | yes | 0.158 |
| change | 0.09 | 0.89 | yes | 0.095 |
| close | 0.06 | 0.95 | yes (crosses 0.9) | 0.063 |
| dispute | 0.03 | 0.98 | no | 0 |
| buy | 0.02 | 1.00 | no | 0 |
After four tokens the cumulative mass is only 0.89, which has not yet reached 0.9, so the fifth token (the one that crosses the threshold) is included. The kept mass is 0.95.
Why the distractors fail: stopping at 0.89 treats p as an upper bound instead of a minimum coverage target. A per-token cut-off of 0.10 describes a fixed probability threshold, not top-p. And skipping renormalisation would leave a distribution that does not sum to 1; there is no greedy fallback in nucleus sampling.
Interview tip: explain why top-p exists: the size of the candidate set adapts to the model's confidence. When one token dominates, the nucleus may contain a single token; when the model is unsure, it contains many.