induwara.lk
induwara.lkAI · Sampling

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.

By Induwara AshinsanaUpdated Jul 10, 2026
Penalty visualizer
Probabilities sum to 1.0 ✓
Penalty convention

frequency_penalty and presence_penalty subtract from the logit. Ranges −2 to 2. Used by the OpenAI Chat Completions API.

Token-table preset

2–12 tokens. Logit −20 to 20; count 0–50 (prior occurrences). Illustrative scores, not a real model run.

Scales with each token's count

Flat, applied once per seen token

HuggingFace / CTRL-only knob

Neutral

Most likely after
today
52.18% · rank flipped
Mass on repeated tokens
47.82%
was 92.02% before
Distribution shift (TVD)
0.59
Reshaped

frequency_penalty removes 3.00 from a token seen 6× (0.5 × 6); presence_penalty removes a flat 0.50 from any token seen at least once.

Probability: before → after

thank×6
43.68%8.62%
you×6
29.28%5.78%
help×2
13.16%19.2%
today
7.98%52.18%
great×1
5.91%14.22%

Step-by-step math

TokenLogitCountΔ logitAdj. logitBeforeAfter
thank3.26-3.5-0.343.68%8.62%
you2.86-3.5-0.729.28%5.78%
help22-1.50.513.16%19.2%
today1.5001.57.98%52.18%
great1.21-10.25.91%14.22%
Copy-ready request body
{
  "frequency_penalty": 0.5,
  "presence_penalty": 0.5
}

One convention active at a time. Sources: .

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

1 · OpenAI subtractive — the "thank you" repeat

A: thank, logit 3.0, count 4 · B: instead, logit 2.0, count 0 · freq 0.5, presence 0.5, T 1

  1. adj[A] = 3.0 − 0.5×4 − 0.5×1 = 0.5
  2. adj[B] = 2.0 − 0.5×0 − 0.5×0 = 2.0
  3. Before: p[A] = e³/(e³+e²) = 73.11%, p[B] = 26.89%
  4. After: p[A] = e^0.5/(e^0.5+e²) = 18.24%, p[B] = 81.76%
  5. Repeated A collapses 73.11% → 18.24%; fresh B now leads

2 · HuggingFace / CTRL divisive — θ = 1.2

Same tokens · penalties off, θ 1.2, T 1

  1. adj[A] = 3.0 ÷ 1.2 = 2.5 (positive logit, seen → divide)
  2. adj[B] = 2.0 (count 0 → unchanged)
  3. Before: p[A] = 73.11%, p[B] = 26.89%
  4. After: p[A] = e^2.5/(e^2.5+e²) = 62.25%, p[B] = 37.75%
  5. Milder than subtractive (62.25% vs 18.24%) — the conventions differ

3 · Edge case — frequency scales, presence does not

A: logit 2.0, count 1 · B: logit 2.0, count 5 · freq 0.3, presence 0, T 1

  1. adj[A] = 2.0 − 0.3×1 = 1.7; adj[B] = 2.0 − 0.3×5 = 0.5
  2. Before: equal logits → 50.00% each
  3. After: p[A] = e^1.7/(e^1.7+e^0.5) = 76.85%, p[B] = 23.15%
  4. The more-repeated B drops to 23.15%; presence-only would keep both at 50%

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

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.