Interview Q&A / AI & Generative AI

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is top-k sampling, and how does it differ from top-p?

SHORT ANSWER

Top-k keeps only the k most likely tokens and samples among them. Top-p keeps the smallest set of tokens whose probabilities add up to p. Top-k uses a fixed count, while top-p adapts the candidate list to how confident the model is.

Explain it simply

You are choosing a restaurant from a ranked list. Top-k says "only look at the first 5, always". Top-p says "keep reading from the top until together they cover 90% of the votes".

When the model is very sure, say the next token has 95% probability, top-p 0.9 keeps just that one token, while top-k 5 still lets four unlikely tokens in. When the model is unsure and many tokens share the probability, top-p keeps a long list while top-k cuts it at five and may throw away good options.

That adaptivity is why top-p is more common as the main control. Both methods trim the unlikely tail, so a wild token is much less likely to be chosen.

Example

text
Probabilities: A 0.50, B 0.30, C 0.10, D 0.05, E 0.03, F 0.02
top-k = 3  -> candidates A, B, C
top-p = 0.9 -> A (0.50) + B (0.30) + C (0.10) = 0.90 -> A, B, C
top-p = 0.8 -> A + B = 0.80 -> A, B

After trimming, probabilities are renormalised and one token is sampled.

What to say in the interview

"Top-k limits candidates to a fixed number, top-p to the smallest group covering probability p. Top-p adjusts to the model's confidence, so I usually tune it, along with temperature, and leave top-k alone."

#sampling#top-k#top-p

Related questions

Practise more AI & Generative AI questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open AI & Generative AI quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.