New Tool Radar

AI Concepts

How to Stop a Model Repeating Itself with Penalty Settings

Stop a model repeating itself by raising the frequency and presence penalties so repeated tokens cost more.

Schematic illustration of stop a model repeating itself with penalty settings: step one spot the repetition, step two raise the penalties, step three check the new output.

When a model repeats a phrase or loops over the same sentence, the sampling penalties can break the loop. Frequency penalty penalises tokens in proportion to how often they have already appeared, and presence penalty penalises them once for appearing at all. Both range from -2 to 2 on the OpenAI-compatible APIs, with 0 as the default. Raising them makes the model prefer new tokens.

Prerequisites

  • Access to frequency_penalty and presence_penalty in your API or runtime.
  • A prompt that currently produces repeated output.
  • A way to run the prompt at two settings and compare.

Steps

Step 1: Spot the repetition

Run the prompt at the defaults and note what repeats: a phrase, a sentence, or a whole paragraph. Repetition that appears twice is a pattern; once is a coincidence.

Step 2: Raise the penalties

Set frequency_penalty to 0.5 and presence_penalty to 0.3, and run the prompt again. Change both penalties in this one test, because they work together against repetition; the one-setting rule applies to temperature and top-p, not to the two penalties.

Step 3: Check the new output

Read the new output for repetition and for sense. If the repetition is gone and the text still reads well, keep the settings. If the text has become disjointed, lower the penalties halfway and try again.

Worked example: Harbor Light library event notice

The fictional Harbor Light library asks a model to write an event notice. At the defaults the notice repeats its opening sentence three times.

Run Frequency penalty Presence penalty Repetition
Run 1 0.0 0.0 Opening sentence x3
Run 2 0.5 0.3 No repetition

At frequency penalty 0.5 and presence penalty 0.3 the notice has no repetition, while the default run repeats its opening sentence three times.

Expected result. The output at the raised penalties has no repeated phrase, and the text still reads as a coherent notice. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.

Limits

  • High penalties can make the model avoid needed repetition, such as a name that must appear twice.
  • Penalties do not fix a prompt that asks for the same thing in a loop; fix the prompt as well.
  • Penalty ranges and defaults differ by provider; check your API’s reference.

Sources

See all