Frequency, Presence & Repetition Penalty Calculator
Enter a small logit-and-count table, drag the penalties, and watch repeated tokens collapse in real time. Shows OpenAI's subtractive frequency_penalty and presence_penalty next to HuggingFace/CTRL's divisive repetition_penalty — with the exact softmax math, token by token. No API key, no cost, runs in your browser.
How it works
A language model scores every vocabulary token with a raw logit before it picks the next word. The three anti-repetition parameters — frequency_penalty, presence_penalty, and repetition_penalty — all work by editing those logits based on how often each token has already appeared, then letting the usual softmax turn the edited logits into probabilities. They come in two different, non-interchangeable conventions, and this tool runs exactly one at a time, just like the real APIs.
OpenAI — subtractive. Per OpenAI's text-generation guide, for token j with count c[j]:
mu[j] = mu[j] − c[j] × frequency_penalty − (c[j] > 0 ? 1 : 0) × presence_penalty
The frequency term scales with the count — a token seen five times loses five times as much — while the presence term is a flat, once-off deduction the instant a token has appeared at all. Both range −2.0 to 2.0; negatives encourage repetition.
HuggingFace / CTRL — divisive. Introduced by Keskar et al. (2019) and implemented by the HuggingFace RepetitionPenaltyLogitsProcessor, for any seentoken (count > 0):
adj[j] = logit[j] / θ if logit[j] > 0, else logit[j] × θ
Dividing a positive logit or multiplying a negative one both push the token toward zero influence. θ (the repetition penalty) runs 1.0 to 2.0, defaults to 1.2, and — unlike the OpenAI rule — does not scale with the count: seen once or seen ten times, the same θ applies.
Then the tempered softmax. Whichever convention is active, the adjusted logits are turned into probabilities with p_j = exp(adj[j] / T) / Σ_k exp(adj[k] / T), where T is the temperature. The tool subtracts the maximum scaled logit before exponentiating (the log-sum-exp trick), so extreme logits or small temperatures never overflow. The badge in the calculator confirms the output probabilities reconcile to 1.0, and a second, independent softmax routine cross-checks the first to within 1e-4.
Worked examples
Frequently asked questions
Sources & references
- OpenAI API Reference — Chat Completions frequency_penalty & presence_penalty
- OpenAI — Text generation guide (the exact subtractive logit-editing rule)
- Keskar et al. (2019) — CTRL: A Conditional Transformer Language Model (repetition penalty θ)
- HuggingFace Transformers — RepetitionPenaltyLogitsProcessor (divisive reference implementation)
- Goodfellow, Bengio & Courville (2016) — Deep Learning (tempered softmax)
Penalty ranges and the two editing rules were last cross-checked against the OpenAI API reference, the CTRL paper, and the HuggingFace processor on 2026-07-10. The worked examples above double as the tool's reconciliation fixtures (tolerance 1e-4).
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.