Continual Memorization of Factoids in Large Language Models

Howard Chen, Jiayi Geng, Adithya Bhaskar, Dan Friedman, Danqi Chen · Submission to ICLR 2025 · Rejected

TL;DR

When large language models (LLMs) are fine-tuned on specialized, long-tail facts, subsequent training on other tasks—especially other factual data—causes severe catastrophic forgetting that standard replay cannot easily fix. The authors propose REMIX (Random and Generic Data Mixing), a counterintuitive strategy that mixes unrelated pretraining text or even random word sequences during training. REMIX outperforms replay by shifting and diversifying where factoids are stored across transformer layers, tripling factual retention in severe forgetting settings.

What Problem Does This Paper Address?

Pretraining LLMs is notoriously inefficient for acquiring long-tail, specialized, or rapidly evolving world knowledge. A standard solution is fine-tuning the model directly on targeted factoids (structured (subject, relation, object) triples). However, in realistic deployment pipelines, models undergo multiple successive stages of tuning (e.g., domain adaptation, instruction tuning, or math/code training).

Under this continual memorization setup, models experience severe catastrophic forgetting of previously acquired factoids. Unlike general continual learning—which tracks broad capabilities like reasoning or overall perplexity—continual memorization focuses on retaining discrete, atomic associations. The authors show that conventional mitigations like experience replay (re-training on a subset of past data) struggle significantly when the subsequent task also involves memorizing facts.

Methods

The authors analyze the gradient updates between stages to understand interference. When fine-tuning on task $A$ ($D_A$) and then task $B$ ($D_B$), forgetting occurs when the task gradients point in opposing directions ($\nabla \mathcal{L}(\theta; D_A)^T \nabla \mathcal{L}(\theta; D_B) < 0$).

To alleviate this, they introduce REMIX (Random and Generic Data Mixing), which requires no access to previously memorized factoids:

  1. Stage 1 Mixing (Diversification): Mixing unrelated data (such as random word sequences) alongside the target factoids forces the model to distribute representations across earlier and more varied layers rather than concentrating them narrowly, landing in a parameter region less susceptible to future displacement.
  2. Stage 2 Mixing (Interference Reduction): Mixing broad, generic pretraining data (e.g., web/knowledge corpora) alongside the new task rotates the second-stage gradient update, preventing it from heavily conflicting with the original factoid representations.

Datasets

The authors construct synthetic and filtered unfamiliar datasets across multiple domains:

  • Stage 1 (Memorization Target $D_A$):
  • Key-Value Recall (KVR): 2,000 synthetically generated 8-character random alphanumeric key-value pairs.
  • PopQA & TriviaQA: Filtered to 2,000 unfamiliar, long-tail factoid instances each.
  • Stage 2 (Subsequent Tasks $D_B$):
  • Factoid Datasets: In-domain samples from $D_A$, LAMA, Entity Questions, and WebQA.
  • Non-Factoid Datasets: GSM8K, MATH, EvolCode, APPS, and UltraChat.
  • REMIX Mixing Datasets ($D_M$):
  • Random 50-word sequences sampled from the NLTK Word Corpus.
  • Generic text corpora: Knowledge Pile, ArXiv Pile, and FineWeb (verified to have $<1.3\%$ entity overlap with evaluation factoids).

Key Insights and Ideas

  • Factoids interfere with factoids: Forgetting is dramatically worse when Stage 2 is another factoid dataset (e.g., fine-tuning on LAMA causes KVR accuracy to plunge to 2.1%), whereas non-factoid tasks (math, code, chat) cause noticeably milder forgetting.
  • Replay falls short: Replaying 10% of past factoids only raises KVR retention to 41.6% against factoid interference. Because atomic factoids are largely independent, sparse replay does not stabilize the entire learned manifold.
  • Noise can protect memory: Adding completely random word sequences during Stage 1 prevents catastrophic forgetting later on.
  • Mechanistic shifts via Logit Lens: Probing intermediate layers reveals that successful REMIX training pushes the decoding of the correct token into earlier transformer layers and spreads representation across a wider band of layers, preventing later-stage updates from overwriting them.

Key Results

Experiments evaluated on Llama-3-8B and Mistral-7B-v0.3:

  • Severe forgetting recovery (Llama-3-8B on KVR): When Stage 2 is a factoid task, baseline accuracy drops to an average of 13.5% (and 2.1% on LAMA). Applying REMIX (Random at Stage 1 + Knowledge Pile at Stage 2) boosts average retention to 53.2% (and 62.4% on LAMA), outperforming 10% experience replay (41.6%).
  • PopQA & TriviaQA: For PopQA followed by factoid datasets, REMIX maintains 84.9% accuracy (up from 47.0% unmixed). For TriviaQA, it reaches 88.9% (up from 39.8% unmixed).
  • Non-Factoid Stage 2: On KVR followed by non-factoid tasks, Stage 1 mixing with random word sequences lifts accuracy from 38.9% $\rightarrow$ 77.9%.
  • Multi-Stage Scaling: In 3-stage training ($A \rightarrow B \rightarrow C$), REMIX consistently maintains a $30\%+$ absolute accuracy lead over unmixed baselines.

Limitations and Future Work

  • Heuristic selection of mixing data: The best mixing data type depends on the stage and task type: Stage 1 benefits most from uncorrelated data (random words), whereas Stage 2 benefits more from generic pretraining text aligning with natural language structure.
  • Sensitivity to sequence length and ratios: Tuning the ratio and token length of random sequences is critical; overly long random sequences degrade optimization.
  • Broader downstream capabilities: The study focuses primarily on exact-match retrieval of atomic facts; future work is needed to explore whether REMIX impacts high-level downstream capabilities or safety alignment during successive tuning stages.

Summary updated

Abstract

Large language models (LLMs) can absorb a massive amount of knowledge through pretraining, but pretraining is inefficient for acquiring long-tailed or specialized facts. Therefore, fine-tuning on specialized or new knowledge that reflects changes in the world has become popular, though it risks disrupting the model’s original capabilities. We study this fragility in the context of continual memorization, where the model is trained on a small set of long-tail factoids (subject-relation-object associations) and must retain these factoids after multiple stages of subsequent training on other datasets. Continual memorization focuses on the specific challenge of retaining long-tail factoids, whereas general continual learning aims to maintain the LLM’s capabilities across a wide range of generic tasks (e.g., reasoning, commonsense knowledge). Through extensive experiments, we show that LLMs suffer from forgetting across a wide range of subsequent tasks, and simple replay techniques do not fully prevent forgetting, especially when the factoid datasets are trained in the later stages. We posit that there are two ways to alleviate forgetting: 1) protect the memorization process as the model learns the factoids, or 2) reduce interference from training in later stages. With this insight, we develop an effective mitigation strategy: REMIX (Random and Generic Data Mixing). REMIX prevents forgetting by mixing generic data sampled from pretraining corpora or even randomly generated word sequences during each stage, despite being unrelated to the memorized factoids in the first stage. REMIX can recover performance from severe forgetting, often outperforming replay-based methods that have access to the factoids from the first stage. We then analyze how REMIX alters the learning process and find that successful forgetting prevention is associated with a pattern: the model stores factoids in earlier layers than usual and diversifies the set of layers that store these factoids. The efficacy of REMIX invites further investigation into the underlying dynamics of memorization and forgetting, opening exciting possibilities for future research.
BibTeX
@misc{chen2024continual,
  author = {Howard Chen and Jiayi Geng and Adithya Bhaskar and Dan Friedman and Danqi Chen},
  title = {{Continual Memorization of Factoids in Large Language Models}},
  year = {2024},
  eprint = {2411.07175},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.07175},
}

Loading related content...

Figure