Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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.

The shortcut

Name the problem first:

  • "It keeps saying the same word" → frequency penalty.
  • "It keeps coming back to the same topic" → presence penalty.
  • "It repeats a required word, like the shop name" → no penalty; that repetition is correct.
Tuning the two Spoke & Chain problemsStep 1 of 4
  1. Name problem one

    "fantastic" three times in one reply: repeated wording. Choose a frequency penalty of 0.5.

The trap is turning penalties up high as a cure-all. Large values make the model avoid words it genuinely needs, and output grows strange. Often a clearer prompt ("use varied wording; do not repeat ideas") fixes the problem first.

Drills

Answer fast — trust the rule.

quick drill

A token has appeared five times. Which penalty hits it harder than a token that appeared once?

quick drill

A brainstorm keeps returning to the same few ideas. Which setting fits best?

quick drill

Why can a very high penalty damage a Spoke & Chain reply?

quick drill

With a presence penalty of 0.4, how much is a token penalised after appearing three times?

Remember

  • Frequency punishes repeats by count; presence punishes any reuse once.
  • Shortcut: same word → frequency; same topic → presence; required word → no penalty.
  • Trap: cranking penalties up high instead of first fixing the prompt.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainChoose the penalty

Drafted replies keep saying 'fantastic' four times, and a brainstorm of sale ideas keeps circling the same two themes. Pick a penalty for each problem and explain how each one works.