DevKits

Frequency & Presence Penalty Playground — Reduce LLM Repetition

See how OpenAI's frequency_penalty and presence_penalty push down tokens that already appeared, reducing repetition. Drag the sliders and watch the distribution shift. 100% local.

Last updated:

Comments

frequency_penalty and presence_penalty both reduce repetition by lowering the logits of tokens that already appeared. frequency_penalty scales with how many times a token has been used (strong against literal loops); presence_penalty is a flat hit once a token appears at all (nudges toward new topics). Drag the sliders above to watch repeated tokens get pushed down. Everything runs in your browser.

The model is choosing the next word to describe something. Some candidates have already appeared earlier in the output (their prior count). Raise the penalties and watch repeated tokens get pushed down.

0.0

Scales with how many times a token already appeared

0.0

Flat penalty if a token appeared at all (count > 0)

TokenSeenProbability (base → adjusted)
great3×
27.5% → 27.5%
good2×
22.5% → 22.5%
nice1×
16.7% → 16.7%
excellent0×
11.2% → 11.2%
wonderful0×
8.3% → 8.3%
fine1×
6.1% → 6.1%
superb0×
4.6% → 4.6%
ok0×
3.1% → 3.1%

Illustrative only — logits and counts are a fixed example. Formula: adjusted = logit − count × frequency_penalty − (count>0 ? presence_penalty : 0). Everything runs in your browser.

What is Penalty Playground?

Left unchecked, language models can fall into repetition — repeating a word, a phrase, or circling the same idea. OpenAI exposes two parameters to counter this, and they work differently. frequency_penalty subtracts an amount proportional to how often a token has already been generated, so the more something repeats the harder it's suppressed — this is the direct lever against literal loops. presence_penalty subtracts a flat amount as soon as a token has appeared even once, which doesn't care about frequency but broadly encourages the model to introduce new words and move to new topics. Both range from −2 to 2, and the exact adjustment is: adjusted_logit = logit − count × frequency_penalty − (count > 0 ? presence_penalty : 0). This playground uses a fixed set of candidate words — some already 'seen' earlier in the output — so you can isolate each parameter and see which tokens drop and by how much. Small values (0.1–0.6) usually suffice; pushing toward 2 can make text incoherent as the model avoids natural reuse.

How to tune repetition penalties

  1. 1Raise frequency_penalty to push down tokens that have appeared multiple times.
  2. 2Raise presence_penalty to discourage any already-used token and favor new topics.
  3. 3Use a preset, then read the base → adjusted probability for each candidate.

Key Concepts

frequency_penalty
Scales with a token's prior count — the direct lever against literal repetition.
presence_penalty
Flat penalty once a token appears at all — favors new words and topics.
Temperature & top-p
The other half of sampling — explore how they reshape the distribution.

Tips & Best Practices

  • ▸Use frequency_penalty to stop repeated phrases; use presence_penalty to diversify topics.
  • ▸Start in the 0.1–0.6 range; values near 2 can degrade coherence.

Frequently Asked Questions

What is the difference between frequency_penalty and presence_penalty?

frequency_penalty scales with how many times a token has already appeared — the more it repeats, the harder it's pushed down, which curbs loops and repeated phrases. presence_penalty is a flat penalty applied once a token has appeared at all (count > 0), which nudges the model toward new words and topics. Both range from -2 to 2.

How are the penalties applied?

They adjust each candidate token's logit before sampling: adjusted = logit − count × frequency_penalty − (count > 0 ? presence_penalty : 0). Positive values lower the probability of seen tokens; negative values encourage repetition.

What values should I use?

Start small: 0.1–0.6 for frequency_penalty to gently reduce repetition, and a similar range for presence_penalty to encourage topic variety. Large values (toward 2) can make output incoherent as the model avoids natural word reuse.

Which one stops the model repeating itself?

frequency_penalty is the more direct lever against literal repetition because it grows with each repeat. presence_penalty is better for diversifying topics rather than suppressing a specific repeated token.

Try Next

Text Chunker

Split long text into overlapping chunks for embedding and RAG pipelines. Preview recursive, paragraph, sentence, or fixed strategies with live token counts. Runs 100% in your browser.

Related Tools

Reference & Guides