Generalization v.s. Memorization: Tracing Language Models’ Capabilities Back to Pretraining Data

Xinyi Wang, Antonis Antoniades, Yanai Elazar, Alfonso Amayuelas, Alon Albalak, Kexun Zhang, William Yang Wang

Introduction

Are Large Language Models (LLMs) brilliant reasoners or just massive parrots? The "Generalization vs. Memorization" debate is central to AI research. While we know LLMs can recite poetry or code, it remains unclear whether their ability to solve a math problem or translate a sentence is just a sophisticated form of "copy-pasting" from a trillion-token training set.

Previous research has largely focused on verbatim recall—checking if a model can spit out long strings of training text word-for-word. However, this is a poor measure for high-level capabilities. A model might "know" a fact or a reasoning pattern without repeating a specific sentence. To bridge this gap, this paper introduces distributional memorization, a new metric that traces model outputs back to the frequency of related concepts in their pretraining data, revealing whether models are truly generalizing or simply repeating what they've seen.

Methodology: Distributional Memorization & Task-Grams

To measure how much a model's output distribution is influenced by the statistical distribution of the pretraining corpus, the researchers introduced two primary innovations:

  1. Distributional Memorization: Instead of looking for exact string matches, the authors measure the Spearman correlation between the LLM’s predicted probabilities for an answer and the actual frequency of related "task-grams" in the pretraining data.
  2. Task-gram Language Models: Standard $n$-gram models look at local, contiguous sequences (e.g., "the cat sat"). The authors propose "task-grams," which count the co-occurrence of semantically related pairs from task inputs and outputs (e.g., a phrase in English and its Spanish translation) within the same document in the pretraining corpus. This captures long-range, task-specific dependencies that traditional models miss.
Overview of the task-gram and distributional memorization pipeline.

They applied these methods to the Pythia model family (ranging from 13M to 12B parameters) and used WIMBD (What’s In My Big Data?) to search the massive 800GB Pile dataset.

Experimental Setup

The framework was evaluated across four distinct tasks to capture a range of cognitive requirements:

  • WMT-09: Machine translation (English to various European languages).
  • TriviaQA: Factual question answering.
  • MMLU: A benchmark for world knowledge across 57 subjects (split into "knowledge-intensive" vs. "reasoning-intensive").
  • GSM8K: Grade school math word problems requiring multi-step reasoning.

Key Insights: The Scaling Divergence

The most striking finding of the study is that memorization is highly task-dependent.

For factual QA (TriviaQA), the model acts as a "memory king." Model performance is highly correlated with how often the facts appear in the training data. Conversely, translation (WMT) shows almost no statistical link to training data frequency, suggesting it is a genuinely generalized skill.

Furthermore, as models scale up in size, they improve across all tasks, but the mechanism of improvement diverges based on the task type. For factual QA, larger models get better by memorizing more. For math and translation, larger models get better by generalizing more, producing a higher percentage of "novel" $n$-grams that never appeared in their training data.

Distributional memorization vs. generalization across model sizes for different task types.

Within the MMLU benchmark, this divide is also evident: "knowledge-intensive" tasks (like history or law) showed much higher memorization scores than "reasoning-intensive" tasks (like abstract algebra or physics).

Detailed Results

  • TriviaQA: Showed the strongest memorization effect ($Mem_{n=3} > 0.35$). As model size increased, the correlation with training data frequency also increased.
  • Translation: Larger models (e.g., Pythia 12B) generated significantly more novel $n$-gram pairs than smaller models, proving that performance gains in translation come from learning the underlying "logic" of language rather than memorizing specific phrase pairs.
  • Influence Functions: Gradient-based analysis confirmed that documents containing both the input and output $n$-grams (the "task-grams") had a much higher impact on model performance than documents containing only the answer.
  • Prompt Steering: The authors found they could "optimize" prompts using GPT-4o to either maximize or minimize the use of training data distributions. TriviaQA performed better with "memorization-heavy" prompts, while math reasoning (GSM8K) performed better with prompts that encouraged generalization.

Limitations and Future Work

The authors acknowledge that the Pythia models and The Pile are slightly older than state-of-the-art closed models like GPT-4. Additionally, while the "task-gram" approach is scalable, it relies on embedding similarity to find related $n$-grams, which can be sensitive to the choice of embedding model.

Future work could involve applying this framework to even larger, more modern open-source datasets like Dolma or RedPajama. Investigating how different pretraining "recipes" (e.g., the ratio of web text to books) specifically impact the balance between a model's ability to memorize facts versus its ability to reason remains a promising frontier.

Summary updated

BibTeX
@inproceedings{wang2025generalization,
  author = {Xinyi Wang and Antonis Antoniades and Yanai Elazar and Alfonso Amayuelas and Alon Albalak and Kexun Zhang and William Yang Wang},
  title = {{Generalization v.s. Memorization: Tracing Language Models’ Capabilities Back to Pretraining Data}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=IQxBDLmVpT},
}
Figure