📌 The Problem of Repetition
Have you ever noticed an LLM getting stuck in a loop, repeating the same phrase (like "As an AI language model...") over and over? This happens because of how context windows work.
Once a model outputs a word, that word is added to its context window. Because the word is now in the prompt, the model becomes statistically more likely to output it again. If left unchecked, this can lead to disastrous loops. To solve this, we use two parameters: Frequency Penalty and Presence Penalty.
📌 Frequency Penalty (Encouraging Synonyms)
The Frequency Penalty penalizes a word based on how many times it has already appeared in the text.

If the model uses the word "furthermore", its probability drops slightly. If it uses it 5 more times, the probability drops massively. This penalty forces the model to dig into its vocabulary and find synonyms (like "additionally" or "moreover"), resulting in more natural, varied writing.
📌 Presence Penalty (Encouraging New Topics)
The Presence Penalty is a blunt instrument. It penalizes a word based on a simple True/False check: Has this word appeared at all?

Unlike Frequency Penalty, Presence Penalty does not care if a word was used 1 time or 100 times. The penalty is applied immediately upon the first use and stays flat. This is extremely useful for forcing the model to change the subject and brainstorm new ideas, rather than dwelling on the exact same topic for the entire response.
Quick Knowledge Check
Test what you just learned about Penalties
Question 1 of 1
If you are using an LLM to generate a list of 50 completely unique brainstorming ideas, which parameter should you turn up to ensure it doesn't dwell on the same concepts?
Loading results...