## Overview

Nucleus sampling is also known as Top_p Sampling. In Nucleus sampling, the model only considers the tokens with the highest probability mass, which is determined by the top_p parameter. OpenAI recommends to use either one but not both:

- nucleus sampling or
- temperature sampling

## Top_p Sampling

The Top_P parameter controls the diversity of the text generated by the GPT model. This parameter sets a threshold such that only words with probabilities greater than or equal to the threshold will be included in the response. To understand Top_p sampling, we need to understand two things.

- Probability Distribution
- Cumulative Distribution

## Probability Distribution

## Cumulative Distribution

**top_p**gets its name from the threshold p, which represents the percentage of the total population or sample being considered.

## Example

For example, a value of 0.9 means that only the tokens with the top 90% probability mass are considered. i.e. the set includes the smallest number of most probable tokens that together account for 90% of the total probability.

## Adjust the value

while interacting with the model.

## API Request

—

## OpenAI API Tutorials

OpenAI tutorials on this website can be found at:

For more information on the OPenAI AI Models, visit the official website at: