← Latest papers
💬 NLP

Memorization Dynamics of Fill-in-the-Middle Pretraining

This paper investigates the memorization dynamics of Fill-in-the-Middle (FIM) pretraining compared to standard left-to-right objectives, revealing that while FIM excels at recovering short or partial spans, it remains heavily dependent on prefix context for verbatim recall and exhibits linear growth in memorization with data repetition.

Original authors: Tobias von Arx, Tanguy Dieudonné

Published 2026-05-25
📖 5 min read🧠 Deep dive

Original authors: Tobias von Arx, Tanguy Dieudonné

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are teaching a student to memorize a long storybook. You want to see how well they can recite specific parts of the story word-for-word. Usually, you teach them by reading the story from start to finish, one word after another. This is called Left-to-Right (LTR) training.

But there's another way to teach them, often used for coding or filling in blanks. You give them the beginning of a paragraph and the end of a paragraph, and ask them to guess what goes in the middle. This is called Fill-in-the-Middle (FIM) training.

This paper asks a simple question: Does teaching a student to "fill in the middle" make them memorize the book differently than teaching them to read straight through?

The researchers set up a controlled experiment. They took two identical AI models (like twins) and taught them the exact same book excerpts. One twin learned the "straight reading" way (LTR), and the other learned the "fill-in-the-blank" way (FIM). They repeated these specific book excerpts anywhere from 1 to 128 times to see how repetition affects memory.

Here is what they found, explained with some everyday analogies:

1. The "Heavy Tail" vs. The "Steady Climber"

When the researchers asked the models to recite a chunk of text starting only from the beginning (the prefix):

  • The LTR Twin (Straight Reader): This twin is like a person who memorizes a speech perfectly if they hear it enough times. Once they cross a certain threshold of repetition, they can recite long, exact sentences with very high confidence. They have a "heavy tail" of memory—they are great at long, perfect recitations.
  • The FIM Twin (Fill-in-the-Blank): This twin is a bit different. They are less likely to recite a whole long sentence perfectly. Instead, they are better at remembering shorter snippets or partial matches. Their memory grows more steadily and linearly as they hear the text more often, but they rarely hit that "perfect long recitation" peak as easily as the straight reader.

Analogy: Imagine trying to remember a song.

  • The LTR student is great at singing the whole chorus perfectly once they've heard it enough, but if you ask them to start from the middle, they might get stuck.
  • The FIM student is good at humming a few bars or recognizing a melody if you give them a hint from the start or end, but they might not nail the entire 30-second chorus as perfectly as the LTR student.

2. The "Anchor" of the Prefix

The researchers then tested the FIM model in its natural environment: giving it both the start (prefix) and the end (suffix) of a sentence and asking it to fill in the middle.

They discovered something surprising: The end of the sentence (suffix) doesn't help much.

  • Even though the FIM model sees the end of the sentence, it relies almost entirely on the beginning of the sentence (prefix) to remember the middle part.
  • If you swap the real beginning of the sentence with a random, unrelated sentence, the model forgets the middle almost instantly.
  • If you swap the end of the sentence with a random one, the model still remembers the middle quite well, as long as the beginning is correct.

Analogy: Think of the FIM model like a detective trying to solve a crime.

  • The Prefix is the crime scene photo.
  • The Suffix is a witness statement about what happened after the crime.
  • The study found that the detective (the model) solves the case (remembers the text) almost entirely based on the crime scene photo. The witness statement (suffix) is helpful, but if you take away the photo, the detective is lost, even if the witness is still talking.

3. Why the Difference?

Why does the "Fill-in-the-Middle" student behave this way?

  • LTR Training: Every time the student hears the story, it's the same view: Start \rightarrow Middle \rightarrow End. This reinforces one specific path, making the memory of the whole chain very strong.
  • FIM Training: Every time the student hears the story, the "middle" part is chopped up differently. Sometimes the middle is the first 10 words, sometimes the next 10. This spreads the memory out. The student learns to recognize pieces of the story from many different angles, but they don't lock onto one single, long, perfect chain as tightly.

The Bottom Line

The paper concludes that how you train a model changes how it memorizes.

  • If you want a model that can recite long, exact passages of text, Left-to-Right training is stronger.
  • If you use Fill-in-the-Middle training, the model becomes better at remembering short pieces or partial matches, but it remains heavily dependent on the beginning of the text to trigger that memory.

The researchers also noted that if you only test one specific way of asking the model (like only testing long sentences or only testing short snippets), you might miss these important differences. It's like judging a fish's swimming ability only by how well it jumps out of the water; you need to test it in different ways to understand its true nature.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →