# Top-p (nucleus sampling)

> Top-p (nucleus sampling): Sampling only among the smallest set of most-likely tokens whose probabilities add up to at least p.

Canonical: https://llmdojo.dev/glossary/top-p

Also called nucleus sampling, top-p.

Sampling only among the smallest set of most-likely tokens whose probabilities add up to at least p.

Learn it in the lesson: [Top-k and top-p](https://llmdojo.dev/learn/model-foundations/sampling/top-k-and-top-p) (Model Foundations · Next-Token Prediction and Sampling).

## Interview questions about Top-p (nucleus sampling)

- [Explain temperature, top-k and top-p. Why would you usually reach for top-p rather than a fixed k?](https://llmdojo.dev/interview/q/explain-temperature-top-k-and-top-p-why-would-you-usually-reach)
- [Given logits from a toy language model, implement greedy, top-k and top-p decoding in NumPy.](https://llmdojo.dev/interview/q/given-logits-from-a-toy-language-model-implement-greedy-top-k-and)
- [Your integration tests call a hosted model at temperature 0 and compare the output with an exact string. They fail now and then. What's going on, and what do you change?](https://llmdojo.dev/interview/q/your-integration-tests-call-a-hosted-model-at-temperature-0-and-compare)
- [Cover the fundamentals: self- versus cross-attention, autoregressive decoding and sampling, where RL fits, and how you evaluate the result.](https://llmdojo.dev/interview/q/cover-the-fundamentals-self-versus-cross-attention-autoregressive-decoding-and-sampling-where)

## Related
- [Logit](https://llmdojo.dev/glossary/logit)
- [LM head](https://llmdojo.dev/glossary/lm-head)
- [Autoregressive generation](https://llmdojo.dev/glossary/autoregressive)
- [Greedy decoding](https://llmdojo.dev/glossary/greedy-decoding)
- [Temperature](https://llmdojo.dev/glossary/temperature)
- [Top-k](https://llmdojo.dev/glossary/top-k)
- [Seed](https://llmdojo.dev/glossary/seed)
- [Logprob](https://llmdojo.dev/glossary/logprob)
- [Glossary of every term](https://llmdojo.dev/glossary)
