Frequency penalty penalizes new tokens based on how often they appear in the generated text so far, and it ranges from -2 to 2, with 0 as the default. Values above 0 encourage the model to use new tokens, while values below 0 encourage it to repeat tokens. It is the right tool when the model says the same phrase three times in one paragraph.
Before you start
An API or local inference setup where you can set frequency_penalty, and a prompt that currently produces repetitive output.
Spot the repetition first
Run the prompt three times at the default settings and highlight the repeated phrases. Count how many times the same sentence or clause appears: one repeat is style, three is a problem.
Check whether the repetition is in the model or in the prompt: a prompt that repeats a phrase will pull the model toward repeating it.
Set the penalty in small steps
Start at 0.3 and run the prompt again. If the repetition survives, raise it to 0.6, then to 1.0. Small steps matter: a large penalty can push the model into strange synonyms to avoid common words.
Keep the temperature fixed while you test the penalty, so the change you see belongs to the penalty alone.
Check the trade-off
Read the new output for sense, not just for variety. A penalty that is too high makes the model avoid ordinary words such as the product name, which is worse than the repetition it fixed.
Pick the smallest penalty that removes the repetition. Record it with the prompt and the model name.
Practice check: fictional Maple Corner product description, 3 runs
The table below is fictional practice material, worked out by hand from the stated settings. It is the expected result for the practice prompt, not a run of any model.
| Frequency penalty | Repeated phrases | Awkward synonyms | Verdict |
|---|---|---|---|
| 0.0 | 6 | 0 | Too repetitive |
| 0.3 | 2 | 0 | Best balance |
| 0.6 | 0 | 1 | Pass, one awkward word |
| 1.5 | 0 | 5 | Fail – wording breaks |
A penalty of 0.3 cuts the repeats from 6 to 2 with no awkward synonyms. At 1.5 the repetition is gone but five words are awkward, so the cure is worse than the problem.
Expected result. UNTESTED: the counts in the practice table are worked out by hand, not measured by running a model. Run your own repetitive prompt at frequency penalties of 0, 0.3 and 0.6, count the repeats, and read for awkward wording.
Limits
- Frequency penalty counts how often a token appeared; presence penalty counts only whether it appeared at all. Use the one that matches the failure.
- A high penalty can break lists and repeated structures, such as a table where the same header must repeat.
