Answers · How models work
Why does the model get stuck repeating the same sentence over and over?
In shortThe model is not stuck in a memory loop: once it has written a phrase, that phrase is in its context and makes writing it again more likely, so a decoder that always picks the top word cannot leave.
The loop is not a bug and it is not a looping memory. Once a phrase has been written, it is part of the context, and the model gives a higher probability to writing it again; a decoder that always takes the top token then has no reason to leave.
The probability climbs
Measure the model's next-token distribution as a phrase repeats and the number does not stay flat. On the first recurrence the repeat has probability and everything else has . On the second it is against . On the third it is against , and on the fifth it is against . These are model probabilities, taken before any decoder has chosen anything.
| step | times the phrase has appeared | probability of starting it again | probability of anything else | what happened |
|---|---|---|---|---|
| 1 | 1 | 0.14 | 0.86 | The first recurrence. The phrase is one plausible continuation among many. |
| 2 | 2 | 0.42 | 0.58 | Having seen it twice, the model now takes this to be a context in which the phrase recurs. |
| 3 | 3 | 0.78 | 0.22 | Past the point where any competing token can win an argmax. |
| 4 | 5 | 0.97 | 0.03 | Settled. The model is nearly certain that the next thing is another copy. |
Those are odds, not probabilities. The odds of repeating rather than not repeating rise from about at one appearance to at two, which is times larger. From two to three they rise to , about times larger again. From three to five they reach , about times larger again. Each copy is evidence for the next copy, so the loop is self-reinforcing inside the model.
The natural guess is that something is stuck: a bug, a cached state, a memory of the last sentence. There is no separate loop variable to reset. The repeated text is the context, and changing that context is what changes the distribution. If you cut the loop out of the context, the next-token probabilities change immediately; if you leave it there, the model is doing exactly what it was trained to do, because refrains, lists and boilerplate really do recur in text.
Why greedy cannot leave
Greedy decoding takes the highest scoring token at every step. When the repeat has probability , every other token together has , so no single alternative can beat it: , and therefore is larger than any one of them. Greedy repeats. Beam search does not rescue this, because every candidate in the beam is a variant of the loop and the loop scores best. Escaping requires choosing a token that is not the top one, which is the one thing a deterministic decoder will not do.
A sampler can leave because it can take a non-top token. If the escape probability at each step is , the chance of still being in the loop after steps is , so the chance of having escaped at least once is . With , after 20 steps the escape chance is , and after 60 steps it is . With , after 60 steps it is only . A tight top- or a low temperature does not create the loop, but it can discard the token that would have escaped, which is why the same model loops under one configuration and not another.
What a penalty does
The usual remedy subtracts a constant from the score of every token that has already appeared. In the softmax, a score becomes proportional to . Subtract and the seen token's weight becomes . Against an unseen token with score , the odds change from to . The factor is , the same for every seen token.
With , , so a seen token keeps about 30 percent of its previous odds. That is enough to break many loops. The rule still cannot tell a refrain from the word "the". English needs the same function words in nearly every sentence, and they are exactly the tokens that have already appeared. Turn the penalty up and the text starts avoiding its own vocabulary: correct words are replaced by odd synonyms, and names or numbers that genuinely need repeating begin to drift.
The loop is a property of the model plus a decoder that refuses to take a risk. If the repeated phrase is legitimate, as in a list or a refrain, the model is right and the decoder is merely obeying it. If the sampler is wide enough, the loop is finite; if the decoder is greedy or tightly truncated, it is permanent. A penalty changes the scores but not the fact that the context now supports the repetition, so it can suppress a loop while damaging words that must recur. That is the boundary: the model supplies the loop, and the decoder decides whether it becomes permanent.
Worth keeping
- A repeated phrase raises its own probability on the next step, so repetition is self-reinforcing in the model before any decoding choice is made.
- Greedy and beam search cannot leave a loop because leaving needs a token that is not the highest scoring one.
- A repetition penalty multiplies the odds of every seen token by the same factor, so it suppresses the symptom and also penalises words that must recur.
Where this goes next
This question is one step of How a Model Picks Its Next Word, a course that works through its subject from the beginning. The page that teaches this part of it is Why It Gets Stuck, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- What does temperature actually do to the next-word probabilities?It divides the model's raw scores by a constant before they are turned into probabilities, so every ratio between two candidate words is pushed further apart or pulled closer together.
- If you ban certain tokens, does that change what the model would have said?Banning tokens leaves the model's raw scores alone but changes the probabilities you sample from, so the text can change.
- Why isn't picking the most likely word at each step the best way to write a sentence?Because the most likely word now can lead to a much worse sentence than a slightly less likely word that sets up a better continuation.
- Why does diffusion add Gaussian noise instead of any random corruption?Diffusion adds Gaussian noise because Gaussian errors combine exactly: each step keeps the spread fixed and gives a closed-form noisy picture at any later step, which makes the reverse step learnable.
- Why does the same request cost more tokens in some languages than in others?A token is learned from a corpus, so a language that was rare in the training text is split into many more pieces for the same meaning, and the price multiplier follows.
- How do you turn the predicted noise into the mean of the previous image?Subtract a small scheduled fraction of the predicted noise from the current image, then rescale to undo the forward step's shrinkage.