Presence Penalty
Overview
In this tutorial, we will learn how to set the Presence Penalty setting using OpenAI Playground or API requests. This setting increases the model’s probability of discussing new topics.
Presence Penalty
This setting indicated how much to penalize new tokens, whether they appear in the text or not. This parameter modifies the probability distribution to make the tokens already present less likely.
Setting the value
We can use OpenAI Playground to set and test this setting.
- Sign in to the Playground.
- Click on the Playground menu in the left navigation bar.
- Choose the flavor, like Chat or Assistant, that you want to test.
- Pick the model.
- Slide the Presence penalty slider to set a value. The range of the value is from o to 2.
API request
To set the value in the API request:
presence_penalty=<value>
For example, to set the setting at 1.0, we can use the following:
presence_penalty=1.0
Example
response = client.chat.completions.create(
model=”gpt-4-turbo-preview”,
messages=[
{
“role”: “user”,
“content”: user_prompt_goes_here
}
],
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=1.0,
)
—
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: