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:
Commentsfrequency_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.
Scales with how many times a token already appeared
Flat penalty if a token appeared at all (count > 0)
| Token | Seen | Probability (base → adjusted) |
|---|---|---|
| great | 3× | 27.5% → 27.5% |
| good | 2× | 22.5% → 22.5% |
| nice | 1× | 16.7% → 16.7% |
| excellent | 0× | 11.2% → 11.2% |
| wonderful | 0× | 8.3% → 8.3% |
| fine | 1× | 6.1% → 6.1% |
| superb | 0× | 4.6% → 4.6% |
| ok | 0× | 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
- 1Raise frequency_penalty to push down tokens that have appeared multiple times.
- 2Raise presence_penalty to discourage any already-used token and favor new topics.
- 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
Cosine Similarity
Compute cosine similarity, dot product, and Euclidean distance between two vectors online. Perfect for debugging LLM embeddings, semantic search, and RAG pipelines. 100% local — vectors never leave your browser.
AI Cost Calculator
Estimate monthly LLM API cost across GPT-4o, Claude 3.5, Gemini, DeepSeek and 100+ models. Compare providers side-by-side with prompt-caching and batch discounts. Free, no signup — prices refreshed daily from the public LiteLLM catalog.
Token Counter
Count tokens in your prompt for GPT-4, GPT-3.5, Claude, and Gemini and predict API cost before you spend. Free, no signup — all counting runs locally, your prompt stays in your browser.
LLM JSON Extractor
Extract every JSON object or array buried inside an LLM reply — even when it's wrapped in markdown fences, mixed with explanation text, or has trailing commas and single quotes. Auto-repairs each block. 100% local.
Context Window Checker
Check whether your prompt fits a model's context window before you send it. Estimates prompt tokens, reserves room for the response, and shows remaining headroom across GPT-4o, o1, Claude, Gemini, DeepSeek and more. 100% local.
Prompt Token Breakdown
Break a prompt into segments and see how many tokens — and how much cost — each part uses. Find the heaviest section (system, few-shot examples, or user input) so you know exactly what to trim. 100% local.