# What Are Frequency and Presence Penalties?

> What frequency and presence penalties do to repeated words in AI output, when to turn them up, and where they break things, for your AI interview.

**In short:** Frequency and presence penalties are settings that make a model less likely to repeat words it has used. The frequency penalty counts how often a word has appeared, and the presence penalty only asks whether it has appeared. They reduce repetition, but they can also push out names and IDs that must repeat.

AI and LLM interview question Q039, LLM fundamentals. Intermediate, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-are-frequency-and-presence-penalties

## Say it in 30 seconds

Frequency and presence penalties are two settings that stop a model repeating itself. Frequency counts how many times a word has already appeared. Presence only checks whether it has appeared at all. They cut repetition, but turn them up too far and the model avoids words it must repeat, like a claim number or a defined term. So I start at zero, raise them a little, and check the output.

## Say it in 2 minutes

When a model writes, it picks each next token from a list of scores. Left alone, it can fall into a loop and repeat the same sentence again and again. Frequency and presence penalties are two settings that push the scores of tokens already used down, so the model tries something new.

The frequency penalty depends on how often a token has appeared. OpenAI says a positive value decreases the model's likelihood to repeat the same line word for word. The presence penalty only asks whether a token has appeared at all, and increases the model's likelihood to talk about new topics. OpenAI takes values from minus 2.0 to 2.0, and Google's maximum stops just short of 2.0.

The catch is that the penalty works on tokens. A token is a chunk of text, often part of a word. So a claim number or a defined term that has to repeat gets penalised like any other repeat, and common small words get hit too. I treat them as a gentle nudge, and I would not use them as a hard ban.

In practice I keep them at zero for anything that must stay exact, like a policy quote or a legal summary. I change one setting at a time, then check real drafts side by side. And I check the model's docs first, because some newer Google models return an error if these values are set.

## What are frequency and presence penalties, in plain words?

A language model writes by picking one token at a time, and each candidate token gets a score. Left alone, it can fall into a loop and repeat the same sentence. A frequency or presence penalty lowers the score of tokens that have already appeared, so the model is pushed towards new wording.

OpenAI and Google both offer these two settings in their model APIs (the way a program asks the model for text). OpenAI takes a number from minus 2.0 to 2.0. Google's minimum is minus 2.0, and its maximum stops just short of 2.0. They work on different signals: one counts how often a token has appeared, and the other only asks whether it has appeared at all.

Picture a claims clerk writing letters all day. After the tenth letter that opens with "We are reviewing your claim", a good supervisor asks them to vary the wording.

The real version is a drafting bot writing hundreds of claim letters. A penalty is the rule built into its scoring that pushes it to vary the wording.

- **Token:** A chunk of text the model reads and writes, often part of a word.
- **Frequency penalty:** A cut to a token's score based on how often it has appeared.
- **Presence penalty:** A cut to a token's score based on whether it has appeared at all.
- **Repetition:** The same words or lines coming back, often a sign the model is looping.
- **Sampling:** How the model picks its next token from the scored list.

## How do the two penalties differ?

Both only push down tokens that have already appeared. They differ in what they look at. Frequency looks at how often a token has appeared, so a token used six times is treated differently from one used twice. Presence looks only at whether it has appeared, so the second repeat and the sixth are treated the same.

> "Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim." (OpenAI, Completions API reference: frequency_penalty)
>
> "Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics." (OpenAI, Completions API reference: presence_penalty)

*Diagram, How the two penalties push down a repeat: A word already in the text feeds both penalties. Frequency counts how often it repeats, presence only asks whether it has appeared. The model then picks the next word from what is left, so repeats fall.*
1. The word's past use goes to the frequency penalty.
2. Whether it appeared at all goes to the presence penalty.
3. The frequency cut, which counts each repeat, comes off its score.
4. The presence cut, which only checks if it appeared, comes off its score too.
5. The model picks from the words left, so repeats fall.

> **Tip:** A quick way to remember it: frequency counts the repeats, and presence only checks whether the word has come up at all.

## Why do models repeat in the first place?

Penalties are one answer to a model that loops. A research paper by Holtzman and colleagues, "The Curious Case of Neural Text Degeneration", found that choosing text by likelihood gives text that is bland and strangely repetitive.

> "using likelihood as a decoding objective leads to text that is bland and strangely repetitive" (Holtzman and colleagues, arXiv 1904.09751)

Penalties are a blunt fix. They act only on tokens and have no sense of meaning, so the model cannot tell a repeat it should keep from one it should drop.

Worked example, with made-up numbers. A claims team at a mid-size insurer uses a drafting bot to write repayment letters. Its drafts repeat "We are reviewing your claim" four times, and every letter must quote the claim number, CL-48213, in full.

1. **Try a small penalty first:** The team sets the frequency penalty to 0.3 on a test batch of 20 letters, then reads the batch side by side with the old one.
2. **Watch what drops out:** The repeats fall, but the bot can now swap the claim number out for words like 'your file' or 'the matter'. The customer is left unsure which claim the letter means.
3. **Keep exact bits out of reach:** Fill the claim number and policy terms from the claim record in code, and check each letter for them before it is sent. The penalty only shapes the wording around them.

## Do the settings work on every model?

No. Google's Vertex AI reference warns that custom values for these two settings "aren't supported for Gemini 3.6 Flash and later models and return an error if set." The same setting can work on one model and fail on the next, so check the docs for the exact model before you ship.

> **Tip:** Asked how you'd tune them? Say you start at zero, raise one setting a little, and compare real outputs. Don't name a number as the right answer for every case.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: each setting lowers the score of words already in the text.
- [ ] Frequency counts repeats; presence only checks whether a word has appeared.
- [ ] Both work on tokens, so exact terms, IDs and names can get hurt.
- [ ] Start at zero, raise a little, and check real output.
- [ ] Not every model accepts them; check the docs for the one in use.

**Common traps**

- Trap: "Turn the penalty up to stop hallucinations." Better: Penalties only change which words repeat. A wrong answer stays wrong, so check it against a source.
- Trap: "Max out both penalties so the answer is always fresh." Better: Values near 2.0 push hard and break exact text. Start near zero and measure.
- Trap: "Frequency and presence are the same setting." Better: Frequency counts repeats. Presence only checks whether a word has appeared at all.

## Can you spot the damage?

**Spot the damage:** Which claim letter shows a penalty that pushed too hard, so the exact reference was lost?

A. Your claim CL-48213 is under review. We will write again within 10 working days.
B. Thank you for your patience. Your claim CL-48213 is under review.
C. Your claim is under review. Your file is still being checked. The matter should close within 10 working days.
D. We have received your claim, and a handler is now assigned to CL-48213.

**Answer:** C. The claim number has gone, and 'file' and 'matter' stand in for 'claim'. A penalty on repeats can cause exactly this, so keep exact references out of its reach.

**Quick check:** A legal team's clause summariser must keep the defined term Customer Data exactly as the contract writes it. The team sets the frequency penalty to 1.5 to stop repeats. What is the most likely result?

A. Cleaner wording everywhere, with no risk to the defined term
B. The term is penalised like any repeat, so the model may reword it and lose the exact meaning
C. Faster answers, because the model writes fewer tokens
D. The model ignores the penalty for capitalised words, so the term is safe

**Answer:** B. The penalty only sees tokens. A defined term that repeats is penalised too, so the model may drift from the contract's exact words. The penalty has no exemption for capitalised or defined terms, and it does not change speed.

## Can you answer these from memory?

**Flash cards**

- **What do they do?** Lower the score of words already in the text, so the model tries new ones.
- **Frequency vs presence?** Frequency counts each repeat. Presence only checks whether a word has appeared.
- **What range do they take?** OpenAI: -2.0 to 2.0. Google: -2.0 up to just under 2.0.
- **What is the main risk?** They also hit exact terms, IDs and names that must repeat.
- **Do all models accept them?** No. Google says custom values are not supported on Gemini 3.6 Flash and later, and return an error if set.
- **Where do loops come from?** Choosing text by likelihood can give bland, strangely repetitive output.

## Likely follow-up questions

- Q010 What does temperature control? https://designervenkat.online/interview/ai/what-does-temperature-control
- Q011 What is top-k sampling? https://designervenkat.online/interview/ai/what-is-top-k-sampling
- Q012 What is top-p (nucleus) sampling? https://designervenkat.online/interview/ai/what-is-top-p-nucleus-sampling
- Q013 Greedy vs beam search vs sampling? https://designervenkat.online/interview/ai/greedy-vs-beam-search-vs-sampling
- Q038 What are log-probabilities, and how can you use them? https://designervenkat.online/interview/ai/what-are-log-probabilities-and-how-can-you-use-them
