Glossary

What is Top-p sampling?

In Turkish: Top-p örnekleme · Topic: Models and training

A way of choosing the next token in which the model samples only from the smallest group of likely candidates whose probabilities add up to a threshold (p). It is also called nucleus sampling.

How does it work?

The model ranks tokens by probability from highest to lowest. Starting at the top, it adds up the probabilities and stops once the total reaches p, for example 0.9. The tokens in that group form the candidate pool and the rest are discarded. A token is then picked at random from the pool according to its probability. When the model is confident the pool is small, and when it is unsure the pool is wide, so the pool size adjusts itself. In top-k sampling, by contrast, the pool size is fixed.

Why does it matter?

It keeps text fluent by excluding very unlikely, nonsensical tokens while still leaving room for variety. It is a common setting alongside temperature in text-generation interfaces. Because of its effect on output quality and diversity, it is a basic control for people building products on language models.

Example

With p set to 0.9, if the three most likely tokens have probabilities of 50, 30 and 15 percent, they add up to 95 percent, so the pool stops at those three and the choice is made only among them.

FAQ

What is the difference between top-p and top-k?

Top-k always keeps a fixed number of the most likely tokens. Top-p changes the size of the pool depending on how the probabilities add up.

Can top-p and temperature be used together?

Yes. Temperature reshapes the distribution, while top-p cuts off its unlikely tail. Often adjusting just one is enough, and changing both makes results harder to predict.

All terms