Presence vs Frequency Penalty Calculator (OpenAI)
Enter a few candidate tokens with their logits and how often each has appeared, then drag the presence and frequency penalty sliders to watch the adjusted logits and softmax probabilities update — and see when the most likely next token flips. Uses OpenAI's exact additive formula, runs fully in your browser, no signup.
How it works
OpenAI's Chat Completions API exposes two sampling controls that look alike but behave differently: presence_penalty and frequency_penalty. Both accept a value from -2.0 to 2.0 and both nudge the model away from (or toward) repeating itself — but they touch the token logits in distinct ways. This tool applies the exact adjustment documented by OpenAI so you can see the effect token by token, without spending API credits to experiment.
For each candidate token j with base logit ℓj and a prior occurrence count cj, the API adjusts the logit before sampling:
ℓ'j = ℓj − frequency_penalty · cj − presence_penalty · 1[cj> 0]- The presence term subtracts the full presence_penalty once if the token has appeared at all (cj> 0), regardless of how many times. It is a flat “have we used this already?” switch.
- The frequency term subtracts frequency_penalty × cj, so it grows linearly with the count. A token used five times is penalised five times as hard as one used once.
After the adjustment the tool converts logits to probabilities the same way the model samples them: divide each adjusted logit by the temperature T, then apply softmax, pj = e^(zj) / Σ e^(zk), computed with max-subtraction for numerical stability. The “before” probabilities use the un-penalised logits ÷ T, so the comparison isolates the penalty effect rather than mixing in a temperature change. As a self-check the tool also recomputes the softmax through the identity pj = 1 / Σ e^(zk − zj) and reports the (near-zero) difference between the two paths.
Because softmax is relative, lowering one token's logit raises every other token's probability. When a previously-favoured but already-repeated token drops far enough, an unused alternative overtakes it — the tool highlights this flip. Note that OpenAI's additive penalties are not the same as HuggingFace's multiplicative repetition_penalty; the two use different math and their values do not transfer.
Worked examples
Frequently asked questions
Sources & references
- OpenAI API Reference — Chat Completions create (presence_penalty, frequency_penalty, [-2, 2] range)
- OpenAI Docs — advanced usage (the additive logit-penalty formula)
- Microsoft Azure OpenAI Service — reference (restates the penalty semantics and range)
The additive formula and the [-2, 2] parameter range were last cross-checked against the OpenAI API reference (presence_penalty / frequency_penalty) on 2026-07-10. The two worked examples above (28.91% / 71.09% and adjusted logit 0.8) are reproduced exactly by the calculator.
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.