---
title: Top-p (Nucleus Sampling) — AI Glossary
description: Top-p, or nucleus sampling, restricts token selection to the smallest set of most-probable tokens whose cumulative probability reaches a threshold p. The model then samples only from this "nucleus." Unlike a fixed top-k cutoff, the set size adapts to how confident the model is at each step.
canonical: https://prompeteer.ai/glossary/top-p
---

# Top-p (Nucleus Sampling)

Top-p, or nucleus sampling, restricts token selection to the smallest set of most-probable tokens whose cumulative probability reaches a threshold p. The model then samples only from this "nucleus." Unlike a fixed top-k cutoff, the set size adapts to how confident the model is at each step.

## Definition

Nucleus sampling was introduced to address the tendency of pure sampling to occasionally pick very unlikely tokens and of greedy or top-k decoding to produce repetitive, degenerate text. By keeping only the head of the probability mass — say the top 90% — top-p dynamically widens the candidate set when the model is uncertain and narrows it when the model is confident.

Top-p is frequently used together with, or as an alternative to, temperature. Providers typically advise tuning one at a time. A value of 1.0 disables the cutoff, allowing the full distribution.

## Sources

- [Holtzman et al. (2020), The Curious Case of Neural Text Degeneration](https://arxiv.org/abs/1904.09751)
- [OpenAI — API reference (top_p parameter)](https://platform.openai.com/docs/api-reference/chat/create)

## Related terms

- [temperature](https://prompeteer.ai/glossary/temperature)
- [inference](https://prompeteer.ai/glossary/inference)
- [token](https://prompeteer.ai/glossary/token)
