Abstract
Standard finetuning of Large Language Models (LLMs) on specialized datasets often leads to "over-adaptation," where the model's internal topic prior shifts globally, causing it to forget general knowledge. Researchers from Tsinghua University propose conditional finetuning (CF), a technique that prepends a context string to training data and masks its loss. This allows the model to "explain away" domain-specific biases, focusing its learning capacity on factual regularities. Empirical results on LLaMA-2 models show that CF significantly reduces catastrophic forgetting while matching the performance of standard finetuning on target tasks.
Introduction
When an LLM is finetuned on a specific corpus, such as medical textbooks, the standard objective is to maximize the likelihood $p(x)$. However, this objective is unselective; the model learns not only the specific facts within the text but also the broad statistical bias of the corpus. This leads to two primary issues: over-adaptation, where the model assumes all future inputs belong to the new domain, and catastrophic forgetting of general-purpose knowledge acquired during pretraining.
Methodology: Conditional Finetuning
The proposed solution, Conditional Finetuning (CF), modifies the training sequence by prepending a context string $c$ to the document $x$, forming the sequence $\langle c, x \rangle$. By masking the loss on the context tokens, the model is trained to optimize the conditional probability $p(x|c)$.
This approach leverages the "explaining away" effect. If the model is explicitly told it is reading a medical textbook, it does not need to adjust its global weights to account for the high frequency of medical terms. Instead, it learns the specific information that is novel given that context. The researchers explored various context types, including simple domain hints, random UUID strings, and learned soft prompts.
Experimental Results
The researchers evaluated CF using LLaMA-2 (7B and 13B) on a variety of benchmarks, including medical textbooks for domain adaptation and the C4 corpus for assessing general knowledge retention.
Stability Across Domains
A key finding was that CF prevents the dramatic shift in topic priors seen in standard finetuning. In standard finetuning, the probability of words related to the training domain increases globally, while the probability of unrelated domains decreases. CF "quarantines" this shift to the specific context trigger.
Performance and Forgetting
CF achieved a better balance between plasticity (learning new things) and stability (retaining old things):
- Reduced Forgetting: On the C4 dataset, LLaMA-2 7B finetuned with CF showed a KL-divergence of 0.036 from the base model, compared to 0.082 for standard finetuning.
- Maintained Accuracy: In medical QA tasks, CF matched the accuracy of standard finetuning (approx. 55-60%) while maintaining significantly lower perplexity on general text.
- Continual Learning: In sequential finetuning across 13 medical subjects, CF with learned contexts achieved the highest cumulative accuracy and the lowest forgetting scores.
Conclusion
Conditional finetuning offers a simple, effective method for adapting LLMs to new domains without sacrificing general-purpose capabilities. By providing a context to "explain away" corpus-level biases, CF enables more surgical weight updates. While it does not completely solve forgetting caused by weight overwriting in extremely long-term training, it provides a robust mitigation strategy for domain-specific adaptation.
Summary updated