Decoding & Sampling interview question

Generative AIDecoding & Samplingmedium

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?

RankTokenProbability
1cancel0.42
2upgrade0.23
3return0.15
4change0.09
5close0.06
6dispute0.03
7buy0.02
  1. AFour tokens (cancel to change), because 0.89 is the largest cumulative total that stays at or below 0.9; after renormalising, cancel has probability ≈ 0.47.
  2. BThree tokens (cancel, upgrade, return), because top-p drops each token whose own probability is below 1 − 0.9 = 0.10; after renormalising, cancel has ≈ 0.53.
  3. CFive tokens (cancel to close), because the nucleus is the smallest set whose cumulative probability reaches 0.9; after renormalising, cancel has probability ≈ 0.44.
  4. DFive tokens (cancel to close), but kept tokens are not renormalised: cancel keeps probability 0.42, and the leftover 0.05 of mass falls back to the greedy choice.
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:

  1. Sort tokens by probability, highest first.
  2. Keep the smallest prefix whose cumulative probability is ≥ p.
  3. Set all other probabilities to zero and renormalise the kept ones to sum to 1.
  4. Sample from the renormalised distribution.
TokenpCumulativeKept?Renormalised
cancel0.420.42yes0.42 / 0.95 ≈ 0.442
upgrade0.230.65yes0.242
return0.150.80yes0.158
change0.090.89yes0.095
close0.060.95yes (crosses 0.9)0.063
dispute0.030.98no0
buy0.021.00no0

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.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Generative AI questions

  1. A team reports that a new prompt raised RAGAS faithfulness on a 300-question set from 0.81 to 0.86: the old score is from last month, the new one was computed…
  2. A loan pre-screening step uses the schema below with constrained decoding, which emits properties in schema order. Reviewers find that reasoning usually…
  3. The flow shows one generation step of a decoder-only LLM (GPT- or Llama-style). What happens at the highlighted step?
  4. From the same logits, a teacher LLM gives these next-token probabilities after "I want to ___ my subscription" (restricted to five candidate tokens): cancel…
  5. A retail client wants a customer-facing assistant over ~5,000 public help-center pages and product PDFs, live in six weeks, with a team of two engineers.…