Repetition Penalties › Key Parameters

Michael BrenndoerferUpdated August 1, 20251 min read
Language AI HandbookAll chapters
Part 28 of 67GPT Architecture
Chapter 205Repetition Penalties › Key Parameters
Reading section 10 of 13 · Key Parameters · 1 minSection 10 of 13 · 1 min

Book contents

Section 10 of 13 · 1 min read

Repetition Penalties › Key ParametersOne section · Sections in this chapter10 / 13 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

When implementing repetition penalties in generation, these parameters control behavior:

  • repetition_penalty (float, typically 1.0-2.0): Multiplicative penalty applied to logits of repeated tokens. A value of 1.0 applies no penalty. Values around 1.1-1.3 provide gentle repetition reduction. Values above 1.5 strongly discourage any repetition.

  • frequency_penalty (float, typically 0-2.0): Additive penalty proportional to token occurrence count. Higher values increasingly penalize frequently used tokens. OpenAI's API uses this parameter with typical values of 0-1.0.

  • presence_penalty (float, typically 0-2.0): Flat additive penalty for tokens that have appeared at all. Encourages vocabulary diversity. Also used in OpenAI's API with typical values of 0-1.0.

  • no_repeat_ngram_size (int): Size of n-grams to block from repeating. In Hugging Face's generate(), setting this to 2 prevents any bigram repetition, 3 prevents trigram repetition, etc. Set to 0 to disable.

  • encoder_no_repeat_ngram_size (int): For encoder-decoder models, prevents generating n-grams that appear in the encoder input. Useful for abstractive summarization to avoid copying source phrases.