Generalization vs. Memorization: Tracing Language Models' Capabilities Back to Pretraining Data

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

TL;DR

This paper tackles the "black box" problem of how Large Language Models (LLMs) learn by analyzing the relationship between their pretraining data and their ability to generalize versus memorize. They introduce a novel n-gram analysis method to quantify this relationship, finding that task-specific n-gram pairs in pretraining data are crucial for performance, especially in larger models, and that emergent abilities arise from a balance of memorization and generalization.

What Problem Does This Paper Address?

Large Language Models (LLMs) are incredibly powerful, but we don't fully understand how they achieve their capabilities. A key question is whether they are truly understanding and generalizing to new situations or simply memorizing vast amounts of their training data. This distinction is critical for building reliable, trustworthy AI systems. Previous work has often defined memorization as exact copying, but this paper aims to go deeper, exploring how the structure and content of pretraining data contribute to both memorization and generalization in a more nuanced way, especially as models scale.

Methods

The core of this paper's methodology is a novel n-gram analysis. They propose to:

  1. Mine Task-Relevant N-gram Pairs: For a given task (like translation or question-answering), they identify pairs of n-grams (sequences of words) from the input and output of task examples that are semantically related. This is done using embedding models to find similar phrases.
  2. Search Pretraining Corpus: They then use a specialized platform called "What's In My Big Data?" (WIMBD) to efficiently search massive pretraining corpora (like "The Pile") for occurrences of these identified n-gram pairs.
  3. Quantify Contribution: They analyze the frequency of these task-relevant n-gram pairs in the pretraining data and relate it to the LLM's performance on the task. They also use gradient analysis to measure how much the pretraining data contributes to the model's task-specific learning.

This approach allows them to analyze the pretraining data at scale without needing to retrain models for each data point.

Datasets

  • Pretraining Corpora:
    • The Pile: A large, diverse dataset of approximately 207 billion tokens.
  • Dolma: A larger corpus of approximately 3 trillion tokens, used for the OLMO models.
  • Downstream Tasks (for evaluation):
    • Translation: WMT-09 dataset (European languages).
  • Factual Question Answering: TriviaQA dataset.
  • Multiple-Choice Reasoning: MMLU benchmark (covering 57 tasks).
  • Models:
    • Pythia: A suite of open-source LLMs ranging from 70 million to 12 billion parameters, trained on The Pile.
  • OLMO-7B: A more recent, performant LLM trained on Dolma, also instruction-tuned on Tulu.

Key Insights and Ideas

  • N-gram Pairs Matter More Than Single N-grams: The study strongly suggests that pairs of semantically related n-grams from task inputs and outputs are much better indicators of relevant pretraining data than individual n-grams.
  • Emergent Abilities as a Balance: The phenomenon of "emergent abilities" (where models suddenly gain new capabilities at certain scales) is linked to a mismatch between sufficient task-related pretraining data and model size. It's not just about having data, but having the right kind of data for the model's capacity.
  • Small Models Memorize, Large Models Generalize (Mostly): Generally, smaller models tend to rely more on memorizing specific patterns, while larger models show a stronger tendency towards generalization. However, this isn't a strict dichotomy.
  • Instruction Tuning Enhances Data Utilization: Instruction-tuned models (like OLMO-7B-SFT) are better at leveraging their pretraining data to solve tasks, especially complex ones, compared to their base counterparts.
  • A U-Shape in Data Dependence: For some tasks, as model size increases, the reliance on pretraining data initially decreases, then increases again. This suggests a transition from surface-level memorization to deeper compositional understanding.

Key Results

  • Positive Correlation: Task performance generally increases with the number of task-relevant n-gram pairs found in the pretraining corpus, especially for larger models.
  • Threshold for Emergence: A model size threshold (around 400M parameters) was observed below which performance was near-random. Above this threshold, performance dramatically improved, with larger jumps for more relevant n-gram pairs, indicating emergent abilities.
  • Memorization vs. Generalization Trade-off: The R² score analysis showed that smaller models had distributions more similar to pretraining data (suggesting memorization), while larger models showed a decreasing similarity to the data distribution, indicating increased generalization.
  • Instruction Tuning Boosts Performance: The instruction-tuned OLMO-7B model showed significantly better performance on MMLU, suggesting it enhances the utilization of pre-existing knowledge from pretraining rather than learning entirely new capabilities.

Limitations and Future Work

  • Model and Corpus Limitations: The paper uses the Pythia models and The Pile, which are somewhat dated. Newer LLMs and corpora (like Dolma and Matrix) could offer more opportunities for research.
  • WIMBD System Constraints: The WIMBD platform has limitations in searching extremely large corpora, requiring improved search and retrieval methods.
  • N-gram Pair Filtering Sensitivity: The quality of n-gram pair identification is sensitive to filtering methods. More advanced filtering could improve analysis.
  • Future Work: The authors suggest that this work is a first step towards comprehensive analysis of LLM origins. Future research could involve exploring better filtering techniques, analyzing larger and more diverse corpora, and investigating the interplay of memorization and generalization across a wider range of tasks and model architectures.

Summary updated

Abstract

Despite the proven utility of large language models (LLMs) in real-world applications, there remains a lack of understanding regarding how they leverage their large-scale pretraining text corpora to achieve such capabilities. In this work, we investigate the interplay between generalization and memorization in pre-trained LLMs at scale, through a comprehensive n-gram analysis of their training data. Our experiments focus on three general task types: translation, question-answering, and multiple-choice reasoning. With various sizes of open-source LLMs and their pretraining corpora, we observe that as the model size increases, the task-relevant n-gram pair data becomes increasingly important, leading to improved task performance, decreased memorization, stronger generalization, and emergent abilities. Our results support the hypothesis that LLMs' capabilities emerge from a delicate balance of memorization and generalization with sufficient task-related pretraining data, and point the way to larger-scale analyses that could further improve our understanding of these models.
BibTeX
@inproceedings{antoniades2025generalization,
  author = {Antonis Antoniades and Xinyi Wang and Yanai Elazar and Alfonso Amayuelas and Alon Albalak and Kexun Zhang and William Yang Wang},
  title = {{Generalization vs. 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