Skip to the workspace
Pebellslearn by building
Controlling the Output  ›  Capstone Project

Frequency and Presence Penalties

Frequency Penalty 12 minA frequency penalty lowers a token's odds more each time it repeats, while a presence penalty lowers it once for having appeared at all.

prompt engineering / Frequency and Presence Penalties

Explore each scene at your own pace.

01 · The rule

The rule

Frequency and Presence Penalties

Drafted replies had a tic: "Fantastic question! We'd be fantastic to help, and your bike will look fantastic." And a brainstorm of sale ideas kept circling the same two themes, discounts and free bells. Some APIs offer two settings aimed at exactly these problems.

The rule

Frequency punishes repeats by count; presence punishes any reuse once.

Both settings lower the score of tokens that have already appeared in the text, before the next token is chosen. They differ in how the penalty grows.

  • Frequency penalty — the penalty grows with how many times a token has appeared. A word used four times is pushed down much harder than a word used once. It targets repetitive wording.
  • Presence penalty — a flat, one-time penalty for having appeared at all. Once used, a token gets the same push down whether it appeared once or ten times. It nudges the model toward words, and therefore ideas, it has not touched yet.
Token "fantastic" used so far:   1 time    4 times
Frequency penalty 0.5:           -0.5      -2.0
Presence penalty  0.5:           -0.5      -0.5

The numbers are subtracted from the token's score, not its final probability, so the effect on the odds is strong but not exactly proportional. Typical useful values are small, around 0.1 to 1. Not every API exposes these settings, and the exact formula can differ, but the frequency-versus-presence idea is common.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.