LZ Penalty: an LZ77-based penalty helps language models avoid repetitive loops without losing quality.

7 September 202621 views

A new approach uses LZ77 compression code lengths to filter out highly compressible fragments during decoding. This allows models to operate in greedy mode without degenerate repetitions, whereas standard penalties fail in 4% of cases.

LZ Penalty: an LZ77-based penalty helps language models avoid repetitive loops without losing quality.

The Problem: Language Models Get Stuck in Loops

Autoregressive language models generate text one token at a time, relying on the words already written. This process almost inevitably leads to degenerate repetitions: the model starts endlessly reproducing the same phrase or chain of sentences. This is especially common with short texts, mathematical reasoning, or logical chains, where the model gets "stuck" in a local loop.

Standard mitigation methods — frequency penalty and repetition penalty — only work partially. They adjust the probability distribution at the decoding stage but do not account for the structure of repeating patterns. As a result, even modern systems can fall into a repetitive loop several percent of the time — this is hard to notice in short answers but critical for long reasoning chains.

Penalizing Frequency Isn't Enough: We Need Information Theory

Frequency penalty reduces the probability of tokens that have already appeared in the text, while repetition penalty additionally lowers the weight of already-generated sequences. But both approaches use heuristics that have nothing to do with how the model understands text structure. They can suppress useful repetitions (for example, restating an important conclusion) while simultaneously missing long looping patterns made up of different words.

Data compression theory offers a more principled perspective. If a sequence compresses well with an algorithm like LZ77, it means the sequence contains little new information — and, from a prediction standpoint, it is "predictable" and dangerous for generation. It makes sense to penalize the model for choosing such patterns, rather than simply for repeating individual words.

What is LZ77 and How is the Penalty Based on It Built?

LZ77 is one of the classic lossless compression algorithms. It replaces repeated fragments with references to earlier occurrences: instead of writing the string in full, the algorithm stores an offset and a length. As a result, each portion of text gets a "code length" — the minimum number of bits needed to represent it. The more predictable a fragment, the shorter its code.

The authors of LZ penalty proposed using this length as a measure of redundancy directly during decoding. At each step, the model calculates the probabilities of all possible continuations, and each one is additionally evaluated based on how much it increases the compressibility of the entire generated sequence. Continuations that lead to long repetitive structures receive an increased penalty.

Interestingly, this approach naturally follows from the duality of prediction and compression: a good compressor is simultaneously a good predictor, and vice versa. Decoding with LZ penalty can be interpreted as sampling from a residual distribution from which the information successfully predicted by the compressor has already been removed. In other words, the model is forced to produce not the "easiest" continuations for itself, but those that contain genuinely new information.

Practical Implementation: The Penalty is Added Before Token Selection

At the code level, LZ penalty is easily integrated into the greedy decoding process. After each step, the current continuation hypothesis is compressed with an LZ77-like encoder, and the difference in code length is factored into the log probability. Importantly, the penalty requires no training or fine-tuning of the model — it works at the inference stage.

This makes the method universal: it can be applied to any autoregressive model without changing the architecture or touching the weights.

Results: No Degenerate Repetitions at Zero Temperature

The main result claimed by the authors is that LZ penalty allows modern open models to reason with greedy decoding (zero temperature) without losing capabilities. Usually, at zero temperature, the model always picks the most probable token, which makes looping especially likely. This is why, in practice, random sampling with temperatures above zero and penalties is often used — but this introduces unnecessary randomness into generation and can reduce quality.

With LZ penalty, there is no need for such workarounds. Greedy decoding ceases to be a source of degenerate repetitions, and the model stays focused on solving the task. At the same time, the model's capabilities in logical inference, mathematics, and coding do not deteriorate — the penalty only works against redundancy, without affecting the semantic part of generation.

For comparison: in experiments, the same models with frequency penalty and repetition penalty in several cases showed up to 4% failures into repetitive loops. This may seem like a small number, but for long answers or reasoning chains, each such failure completely devalues the result.

Why LZ Penalty Works Better Than Heuristics

The key difference from frequency or repetition penalties lies in the ability to respond to structure, not individual tokens. Heuristics typically penalize all repetitions equally, regardless of pattern length. LZ penalty is sensitive to the length of the repeated sequence: the longer and more precise the repetition, the greater the penalty. Short repetitions that do not form a pattern are penalized lightly or not at all.

This is important for natural language. A model may justifiably repeat a word like "therefore" in different parts of a reasoning chain, and this should not be blocked. But if the model starts generating the same chain of arguments over and over, LZ penalty will detect the reduction in code length and stop the process.

As a result, LZ penalty resolves the dilemma between text quality and safety: you no longer have to choose between "reasonable but looping" and "diverse but incoherent."

Practical Takeaways

For developers and researchers, LZ penalty is a ready-made tool that requires no model changes. It can simply be added to the inference pipeline to achieve stable generation without degenerate repetitions. This is especially relevant for open-source reasoning models used in scenarios with long answers and high demands for determinism.

The question of efficiency remains open: compression at each step requires additional computation. The authors do not discuss complexity in the presented work, but it can be expected that optimized versions running on GPUs and integrated into popular decoding libraries will emerge in the future.

Limitations and Notes

The paper notes minor post-publication corrections related to inaccuracies in calculations — this speaks to the authors' attention to detail and does not affect the essence of the proposed approach. Like any method, LZ penalty is not a silver bullet: it solves the specific problem of repetitions but does not address, for example, factual accuracy or logical coherence of generation.

Nevertheless, the very idea of using compression code length as a measure of the informativeness of a continuation looks elegant and promising. It connects information theory with the practice of text generation and provides what simple heuristics cannot: an understanding of when repetition is noise and when it is a signal of model degradation.

Frequently asked questions

Related materials

All materials
LZ Penalty: an LZ77-based penalty helps language models avoid repetitive loops without losing quality.