New Tool Radar

AI Concepts

How to Choose Frequency and Presence Penalties to Control Repeated Words and New Topics

Use frequency penalty to cut words the model repeats often, presence penalty to push it toward new topics, and test each one alone first.

Schematic with three steps: Test frequency penalty alone; Test presence penalty alone; Combine only the values that helped.

Frequency penalty and presence penalty are two separate controls in the OpenAI Chat Completions API, both ranging from -2.0 to 2.0. Frequency penalty reduces the chance of a token in proportion to how often it has already appeared, so it cuts repeated words. Presence penalty reduces the chance of a token once if it has appeared at all, so it pushes the model toward new topics. Positive values penalize, negative values encourage, and zero means no effect. Test each one alone, since they overlap.

What you need

  • A prompt where the model repeats itself or stays on one topic
  • Access to the frequency_penalty and presence_penalty settings
  • A fixed prompt to compare outputs on

Step 1: Test frequency penalty alone

Set frequency_penalty to a positive value with presence_penalty at zero, and generate. Check whether the repeated words thin out without the text becoming unnatural. Frequency penalty grows with each repetition, so it bites hardest on the words the model leans on most.

Step 2: Test presence penalty alone

Reset frequency to zero and set presence_penalty to a positive value. Check whether the model introduces new points instead of circling the same one. Presence penalty is a one-time push per token, so it favours new topics over repeated words.

Step 3: Combine only the values that helped

Combine the two values that each helped on their own, and re-test on the same prompt. If the combination makes the text wander or avoid needed terms, reduce one of them: a high presence penalty can stop the model from using a keyword it must repeat.

Worked example: synthetic penalty test on one prompt

The table below is a synthetic example. It shows the expected result of setting penalties; no API was called.

Setting Frequency Presence
Baseline 0 0
Cut repeats 0.5 0
New topics 0 0.5
Combined 0.5 0.5

Expected result (UNTESTED). frequency penalty cuts repeated words, presence penalty adds new points, and the combination does both. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Both penalties range from -2.0 to 2.0, and negative values encourage repetition instead of penalizing it.
  • A high presence penalty can stop the model repeating a term the answer needs, such as a product name.
  • The two penalties overlap: a word that appears often is penalized by both, so combining high values can be too strong.
  • These penalties are OpenAI API parameters; other providers may name or implement them differently.

Sources

See all