Deciphering the lmpact of Pretraining Data on Large Language Models through Machine Unlearning

Yang Zhao, Li Du, Xiao Ding, Kai Xiong, Zhouhao Sun, Jun Shi, Ting Liu, Bing Qin · DOI

Introduction: The Pretraining Black Box

While the quality and composition of pretraining data are widely recognized as the primary drivers of Large Language Model (LLM) performance, the specific "recipe" for success remains largely opaque. Currently, developers organize massive pretraining corpora based on intuition or prohibitively expensive trial-and-error. Traditional Data Influence Analysis (DIA) methods fail to bridge this gap: retraining-based methods (removing data and training from scratch) are computationally impossible at scale, while gradient-based methods often fail to capture the complex, emergent reasoning abilities that arise from groups of correlated data.

To address this, researchers have developed a "surgical" method to audit LLMs by using machine unlearning. By erasing specific datasets from a trained model and observing which skills vanish, they can quantify the impact of 48 different data sources—from LeetCode algorithms to Wikipedia subsets—on nine major model capabilities without needing to retrain from zero.

The GRACE Framework: Auditing via Unlearning

The core of this research is GRACE (GRadient AsCent-based Machine Unlearning with rE-training). Instead of training a model to acquire knowledge, GRACE takes a pretrained model (such as Llama-2-7B) and forces it to "forget" specific target data ($D_T$). The framework consists of three critical components:

  1. Gradient Ascent: The learning process is reversed on the target dataset to minimize the likelihood of those specific sequences.
  2. Retraining Regularization: To prevent "catastrophic forgetting" of unrelated knowledge, the model simultaneously performs standard gradient descent on a non-target dataset ($D_N$).
  3. The Randomized Text Endpoint: To determine when forgetting is complete, the authors introduce a novel benchmark. Forgetting is considered successful when the model's perplexity on the target data matches its perplexity on a version of that same text where the tokens have been randomly shuffled. This ensures the model loses specific logic and knowledge while retaining basic vocabulary distribution.

Mapping the Data Landscape

The study analyzed 48 distinct datasets categorized into five major groups:

  • RedPajama Subsets: C4, GitHub, Books, ArXiv, Wikipedia, and StackExchange.
  • ArXiv Domains: Eight specific scientific fields (e.g., Physics, Statistics).
  • StackExchange Communities: Divided by user-rated quality.
  • CodeAlgorithm: 17 types of LeetCode-style algorithm problems (e.g., Dynamic Programming, Sorting).
  • CodeLanguage: 15 different programming languages (e.g., Python, SQL, TeX).

Impact was measured using a Performance Degradation Ratio ($\gamma$) across 31 benchmarks covering Language Modeling, Knowledge, Reasoning, Coding, and Safety.

Foundational Data and the Math-Code Connection

The study identified "high-impact" data sources—specifically Books, GitHub, and Shell scripts—that serve as the foundation for general intelligence. Removing these sources caused performance declines across more than 70% of all model capabilities.

One of the most significant findings provides empirical proof for the "coding leads to reasoning" hypothesis. The researchers found that unlearning algorithmic data (such as Graph Algorithms) severely damaged mathematical reasoning scores, even when the benchmarks were presented in natural language rather than code. This suggests that LLMs derive their underlying "thought patterns" and logical structures from the structured nature of programming.

Furthermore, the results suggest that for coding tasks, logic is more important than syntax. Forgetting the underlying logic of algorithms had a much larger impact on coding ability than forgetting the syntax of a specific programming language. This indicates that LLMs are not merely memorizing code but are learning abstract problem-solving frameworks.

The Safety Paradox and Data Relationships

In a surprising twist, the study revealed a "Safety Paradox": unlearning code corpora actually improved model safety scores. The authors hypothesize that code—which is purely logical and lacks emotional or social nuance—might inadvertently make model outputs more "crude and aggressive" when present in the training mix.

Beyond individual impacts, the researchers categorized how different data sources interact:

  • Correlated: Data sources like Economics and Statistics have nearly identical impacts on model skills.
  • Complementary: Wikipedia and StackExchange influence different, non-overlapping skills; both are required for a well-rounded model.
  • Orthogonal: Wikipedia and ArXiv contribute independently with very low redundancy.

Conclusion and Future Directions

The GRACE framework demonstrates that machine unlearning is a powerful tool for "surgical" data auditing. By identifying which datasets anchor specific capabilities, researchers can move away from "brute force" data collection toward more intentional data curation.

While the study was limited by the breadth of the RedPajama dataset and the granularity of large categories like "Books," the insights pave the way for "de novo" training strategies. Future work will focus on applying these findings to a time-ordered curriculum, where foundational data is introduced to the model before complex reasoning data, potentially leading to more efficient and capable Large Language Models.

Summary updated

BibTeX
@inproceedings{zhao2024deciphering,
  author = {Yang Zhao and Li Du and Xiao Ding and Kai Xiong and Zhouhao Sun and Jun Shi and Ting Liu and Bing Qin},
  title = {{Deciphering the lmpact of Pretraining Data on Large Language Models through Machine Unlearning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.559},
}
Figure