AI & automation

What is top-p sampling?

Top-p sampling, also called nucleus sampling, is a generation setting that tells a language model to choose its next token only from the smallest group of candidates whose combined probability reaches a threshold, such as 0.9, ignoring the long tail of unlikely words.

A simple picture

Imagine the model is finishing the sentence "Your driver will arrive in about five..." The word "minutes" might carry most of the probability, "mins" a little, and thousands of odd words share the rest. With top-p at 0.9, the model only considers the few words needed to cover 90 percent of the probability, so "minutes" or "mins" can appear but "bananas" cannot.

When the model is confident, that group is tiny and output is focused. When it is unsure, the group widens automatically, which is the main advantage over a fixed top-k cutoff that always keeps the same number of candidates.

Top-p versus temperature

Temperature changes how spread out the probabilities are; top-p decides where to cut the list. Both control variety, which is why most provider guides recommend tuning one and leaving the other at its default. Turning both down sharply can make text repetitive.

Does a business need to touch it?

Rarely. For most chatbots, summaries and extraction jobs, the defaults plus a sensible temperature are fine. Top-p becomes useful when a team is generating lots of creative variations and wants to trim nonsense without making everything sound the same. Some newer models do not expose it at all.

Questions, answered

Many applications leave it at the provider default, often 1, meaning no cutoff; values around 0.8 to 0.95 are common when it is used.

A related setting that keeps only a fixed number of the most likely tokens, regardless of how probable they are.

By the Stegnor team · Updated