Dissecting learning and forgetting in language model finetuning

Xiao Zhang, Ji WuICLR 2024

Introduction

Finetuning a large language model (LLM) on a specific domain is a standard practice to enhance its specialized capabilities. However, this process doesn't just teach the model new facts; it fundamentally shifts the model's "priors" toward the topic and style of the training data. This study reveals that these "surface-level" features—such as an academic tone or a biomedical focus—are learned rapidly and with minimal model capacity. In fact, these shifts often dominate the probability changes we typically associate with learning and forgetting, while actual factual knowledge is acquired much more slowly and requires significantly more parameters.

The Problem: Catastrophic Forgetting

When we finetune LLMs on domain-specific data, like medical journals or legal briefs, we frequently encounter a side effect known as catastrophic forgetting. The model becomes highly proficient in the new domain but loses its general-purpose edge.

The core question this paper tackles is: What exactly is the model learning (and forgetting) during this process? Is it genuinely absorbing new facts, or is it merely learning to mimic the "vibe"—the topic and style—of the new data? By dissecting these components, the authors aim to understand the finer dynamics of domain adaptation and why it is so challenging to maintain a model's general intelligence across all domains.

Methodology: Controlled-Variable Probing

To isolate what the model learns, the researchers introduced a novel "controlled-variable probing" method. They utilized instruction-following models like ChatGPT to take existing documents (e.g., PubMed abstracts) and rewrite them by altering only one specific factor at a time:

  • Topic: Changing a medical abstract to be about finance while keeping the academic structure.
  • Style: Rewriting the abstract into a casual blog post or a rap song while preserving the medical facts.
  • Factual Knowledge: Creating "counterfactual" versions where medical terms are swapped for random, incorrect ones, disrupting the actual knowledge while keeping the topic and style intact.
Examples of controlled-variable text generation for probing topic, style, and factual knowledge.

By feeding these variations into models like LLaMA 2 and GPT-2, the researchers measured the log-likelihood ratios. Essentially, they asked the model, "How much more (or less) do you prefer this specific style, topic, or fact compared to the original?" They also compared full finetuning against low-rank adaptation (LoRA) to observe how model capacity affects the learning of these different components.

Datasets

The study utilized several key corpora to conduct and verify their probes:

  • PubMed: A collection of biomedical abstracts serving as the primary domain-specific dataset.
  • C4: A massive web-crawl dataset used as a proxy for "general knowledge."
  • Pile of Law & Amazon Reviews: Used to verify findings in secondary and tertiary domains.
  • Derived Datasets: The authors released "PubMed-derived" and "C4-derived" sets containing the ChatGPT-rewritten versions used for the probing tasks.

Key Insights: Surface vs. Deep Learning

The findings highlight a stark contrast between learning "surface" features and "deep" knowledge. Topic and style act as "simple features." The model picks them up almost instantly, even with a very small number of trainable parameters (such as a low-rank LoRA). Conversely, factual knowledge is a "complex feature" that requires more data and much higher model capacity to internalize.

Log-likelihood ratio changes over training size, showing rapid adaptation of style and topic compared to slower factual learning.

The Dominance of Bias

The massive shift in probability observed during finetuning is mostly the model becoming biased toward the new topic and style. This bias is so strong that it can overshadow the actual acquisition of facts. Furthermore, the "forgetting" observed on general datasets (like C4) is largely due to the model's new obsession with the finetuned style. When the researchers ablated the style and topic factors, they found that the loss of actual factual knowledge was much smaller than the total drop in performance initially suggested.

The "First Few Tokens" Rule

Interestingly, style and topic biases are most prominent at the very beginning of a text sequence. Once the model establishes the "vibe" in the first few words, the bias levels off. Facts, however, are learned uniformly across the entire length of the text.

Capacity and Learning Rates

A LoRA adapter with a rank as low as $r=1$ (representing only ~0.04% of parameters) is sufficient to capture most of the style and topic bias. In contrast, factual learning is significantly hindered when model capacity is restricted. Additionally, increasing the learning rate makes the model much more biased toward the new style and topic (exacerbating forgetting), but it does not help the model learn facts any faster.

Limitations and Future Directions

While the study provides a robust framework for understanding finetuning dynamics, the authors acknowledge certain limitations. Topic, style, and facts are not always perfectly separable; for instance, specific medical jargon inherently contributes to an academic style. Additionally, the study capped finetuning at 1 million documents, leaving room to explore if these dynamics shift at a multi-billion token scale.

Looking forward, the paper suggests innovative ways to mitigate catastrophic forgetting. Potential strategies include masking the loss on the first few tokens of a sequence to prevent the model from over-learning style biases, or employing low-rank "anti-adapters" to subtract stylistic bias after training. These insights pave the way for more efficient and robust domain adaptation in future language models.

Summary updated

BibTeX
@inproceedings{zhang2024dissecting,
  author = {Xiao Zhang and Ji Wu},
  title = {{Dissecting learning and forgetting in language model finetuning}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=tmsqb6WpLz},
}
Figure