Repetition Penalty is a decoding-time hyperparameter that modifies the logits (raw scores) of tokens that have already appeared in the generated sequence. By applying a multiplicative penalty—typically a value between 1.0 and 1.5—the model's probability of selecting a previously used token is reduced. This directly counteracts the tendency of language models to fall into degenerative repetition loops, where the same phrase or word is output endlessly due to the model's self-reinforcing attention mechanism.
Glossary
Repetition Penalty

What is Repetition Penalty?
A decoding parameter that applies a penalty to tokens already present in the generated sequence, discouraging the model from producing degenerate, looping text.
The penalty is applied during the softmax sampling step, scaling down the scores of tokens found in a sliding window of prior context. A value of 1.0 applies no penalty, while higher values like 1.2 aggressively suppress repetition. This parameter is distinct from frequency_penalty and presence_penalty, which use additive adjustments. Proper tuning is critical for maintaining lexical diversity without introducing semantic drift or forcing the model into nonsensical, forced-synonym usage.
Key Characteristics of Repetition Penalty
A deep dive into the operational parameters and mathematical logic that govern how repetition penalty suppresses degenerate loops in autoregressive generation.
Logit Modification Mechanics
Repetition penalty operates by directly modifying the raw logits before the softmax function. For each token already present in the generated sequence, its logit score is divided by a hyperparameter (typically 1.2). This logit scaling reduces the probability of the model selecting the same word again without completely zeroing it out. Unlike hard bans, this allows for natural repetition of function words like 'the' while heavily discouraging the looping of rare or distinctive tokens.
Frequency vs. Presence Penalty
Modern implementations often split the penalty into two distinct parameters:
- Frequency Penalty: Scales the penalty proportionally to how many times a token has appeared. A word used 10 times is penalized more heavily than one used twice.
- Presence Penalty: Applies a flat, binary penalty if a token has appeared at all, regardless of count. This distinction allows fine-grained control over whether to simply encourage topic diversity or strictly prevent any repetition.
The `repetition_penalty` Range
The parameter typically operates on a continuous scale centered around 1.0:
- 1.0: No penalty applied. The model behaves with its default distribution.
- 1.1–1.3: A moderate setting suitable for creative writing, gently discouraging obvious phrase repetition.
- 1.5+: Aggressive penalization. High values risk breaking the model's syntax, causing it to emit nonsensical or ungrammatical output as it desperately avoids any previously used token.
- < 1.0: Inverts the logic, encouraging repetition. Rarely used outside of specific stylistic experiments.
Interaction with Sampling Strategies
Repetition penalty interacts non-trivially with other decoding parameters:
- Top-k Sampling: The penalty is applied before the top-k filter truncates the vocabulary. A heavily penalized token might be pushed out of the top-k set entirely.
- Temperature: High temperature flattens distributions, potentially counteracting the penalty's effect. Low temperature sharpens distributions, making the penalty's impact more binary and abrupt.
- Nucleus Sampling (Top-p): The penalty reshapes the cumulative probability mass, potentially altering which tokens fall within the nucleus.
N-gram Blocking Alternative
A deterministic alternative to the probabilistic repetition penalty is n-gram blocking. This hard constraint prevents the model from generating any sequence of n tokens that already exists in the context window. For example, a 3-gram block stops any identical 3-word phrase from repeating. While effective at stopping verbatim loops, it can be too rigid for poetry or lyrics where refrains are intentional. Many production systems combine both a soft penalty and a hard n-gram block.
Context Window Scope
The penalty is typically applied against the entire current context window, including both the user prompt and the model's own generated output. This prevents the model from simply echoing the user's input back. Advanced implementations may restrict the penalty scope to only the model's recent generations or apply a decaying penalty where the penalization strength diminishes for tokens generated many steps ago, allowing the model to naturally circle back to a topic after a long digression.
Repetition Penalty vs. Frequency Penalty vs. Presence Penalty
A technical comparison of three distinct logit-modification strategies used during autoregressive decoding to suppress degenerate token repetition in language model outputs.
| Feature | Repetition Penalty | Frequency Penalty | Presence Penalty |
|---|---|---|---|
Penalty Target | Tokens already generated in the sequence | Cumulative frequency of each token in the sequence | Whether a token has appeared at all in the sequence |
Mathematical Operation | Scales logits by a constant factor based on prior occurrence | Subtracts a penalty proportional to token count from logits | Subtracts a flat penalty from logits on first occurrence |
Penalty Accumulation | Static penalty applied regardless of repetition count | Increases linearly with each additional occurrence | Applied once; no additional penalty for repeated use |
Primary Use Case | Preventing immediate word and phrase looping | Encouraging lexical diversity over long generations | Forcing topic exploration and new concept introduction |
Typical Value Range | 1.0 to 1.2 (values above 1.0 penalize) | 0.0 to 2.0 (higher values increase penalty) | 0.0 to 2.0 (higher values increase penalty) |
Risk of Degenerate Output | High values cause nonsensical token avoidance | Excessive values force rare, contextually inappropriate tokens | Over-penalization prevents necessary term reuse |
API Availability | Common in open-source frameworks (Hugging Face Transformers) | OpenAI API, Anthropic API | OpenAI API, Anthropic API |
Interaction with Temperature | Applied before softmax; interacts multiplicatively | Applied additively to logits before softmax | Applied additively to logits before softmax |
Frequently Asked Questions
Clear, technical answers to the most common questions about how repetition penalties control degenerate text generation in large language models.
A repetition penalty is a decoding parameter that modifies the probability distribution of tokens during text generation to discourage the model from repeating words, phrases, or sequences it has already produced. It works by applying a multiplicative penalty to the logits of tokens that have appeared in the preceding context window. Specifically, during autoregressive generation, the model scans the already-generated sequence and reduces the score of any candidate token found in that history. The penalty is typically expressed as a value between 1.0 and 2.0, where 1.0 applies no penalty and values above 1.0 increasingly suppress repeated tokens. This mechanism directly counters the positive feedback loop that causes models to degenerate into repetitive, looping outputs—a common failure mode in greedy decoding and beam search where high-probability tokens get reinforced through their own repetition.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Repetition penalty is one of several decoding strategies used to control the quality and diversity of generated text. These related parameters and concepts form the core toolkit for preventing degenerate outputs.
Temperature
A hyperparameter that controls the randomness of predictions by scaling the logits before applying softmax. A temperature of 0 makes the model deterministic, always choosing the most likely token. Higher values (e.g., 0.8–1.2) flatten the probability distribution, making less likely tokens more probable and increasing output diversity. Unlike repetition penalty, temperature does not specifically target repeated tokens but adjusts overall creativity.
Top-k Sampling
A sampling method that restricts the model's next-token selection to the k most likely candidates from the probability distribution. After filtering, the model samples from this truncated set. This prevents the model from choosing highly improbable tokens that could derail coherence. Top-k is often combined with repetition penalty to ensure that even within the allowed set, already-used tokens are suppressed.
Top-p (Nucleus) Sampling
An alternative to top-k that selects the smallest set of tokens whose cumulative probability exceeds a threshold p (e.g., 0.9). This dynamically adjusts the number of candidate tokens based on the confidence of the model's predictions. When the model is very confident, few tokens are considered; when uncertain, more are included. Works synergistically with repetition penalty to maintain diversity without sacrificing coherence.
Frequency Penalty
A closely related parameter that reduces the probability of a token based on its cumulative frequency in the generated text so far. Unlike repetition penalty, which applies a flat penalty to any prior occurrence, frequency penalty scales the penalty proportionally to how many times the token has appeared. A token appearing 10 times receives a much stronger penalty than one appearing twice, making it effective at curbing excessive repetition of common words.
Presence Penalty
A parameter that applies a flat, one-time penalty to any token that has appeared at least once in the generated sequence. Unlike frequency penalty, it does not scale with the number of occurrences. A token is penalized equally whether it appeared once or fifty times. This encourages the model to introduce entirely new topics and vocabulary rather than reusing any previously mentioned concepts.
N-gram Blocking
A deterministic decoding constraint that absolutely forbids the generation of any n-gram (sequence of n tokens) that has already appeared in the output. For example, with 3-gram blocking, the model cannot generate any three-word sequence that exists earlier in the text. This is a hard constraint, not a probabilistic penalty, making it the most aggressive anti-repetition mechanism. Often used in summarization tasks to prevent phrase duplication.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us