← Back to list

Stop Your LLM From Repeating Itself with Frequency & Presence Penalties

Stop Your LLM From Repeating Itself with Frequency & Presence Penalties

Suparna · 2026-09-02 12:35 · 10 claps · 1.7 min read
#llm #llm-hallucinations #llmops #reliable
Open on Medium ↗
Wiki topics: LLM · Large Language Models SAF · Safety & Alignment OPS · LLMOps & Inference

Stop Your LLM From Repeating Itself with Frequency & Presence Penalties

Stop Your LLM From Repeating Itself with Frequency & Presence Penalties

If you’ve ever built a chatbot and watched it suggest the same thing three times in a row, you already know the problem. Turns out there’s a pretty simple fix baked into most LLM APIs: frequency and presence penalties.

They don’t get talked about as much as temperature or top-p, but for anyone chasing reliable, non-repetitive outputs, they’re worth understanding well.

Both penalties do the same basic job of discouraging the model from reusing tokens it’s already generated but they go about it differently. Frequency penalty scales with repetition. Say a token 3 times, it gets penalized more than a token you’ve only said once. The more it shows up, the harder it is for the model to pick it again. Presence penalty doesn’t care about count. A token either appeared before or it didn’t. One mention gets the same penalty as ten. That distinction matters more than it sounds. Frequency penalty is your tool for killing loops and over-used filler words. Presence penalty is more about nudging the model toward new topics or vocabulary altogether, not just avoiding exact repeats.

The Practical Range for both penalties run from-2.0 to 2.0. In practice, most real-world use cases land somewhere in the 0.6–0.9 range. Push too high and you risk the model avoiding common, necessary words just to satisfy the penalty which can make outputs feel stilted or less coherent.

Why This Matters for Reliable outputs specifically: repetition isn’t just an aesthetic annoyance but it’s often a symptom of the model falling into a low-diversity sampling loop, which correlates with degraded or hallucinated content. Penalizing repeated tokens pushes the sampling distribution toward fresher options, which can reduce redundant or looping generations and improve overall output quality.

Take an example of Chatbot, add frequency/presence penalties, and the bot is nudged to generate fresh phrasing and explore new angles which means actually getting closer to solving the customer’s problem instead of looping.

Takeaway: These penalties won’t fix a bad prompt or a poorly grounded model, but they’re a cheap, low-effort lever for improving diversity and reducing repetition-driven quality issues. If reliability is your focus, they’re a good complement to things like temperature tuning, structured prompting, and grounding not a replacement for any of them.

Originally published at https://www.linkedin.com.


메타데이터
post_id
8aceffe2e831
slug
stop-your-llm-from-repeating-itself-with-frequency-presence-penalties-8aceffe2e831
url
https://medium.com/@ssuparnataneja/stop-your-llm-from-repeating-itself-with-frequency-presence-penalties-8aceffe2e831
canonical_url
https://medium.com/@ssuparnataneja/stop-your-llm-from-repeating-itself-with-frequency-presence-penalties-8aceffe2e831
author_url
https://medium.com/@ssuparnataneja
status
ok
fetched_at
2026-09-15 22:28:42