Learning and Unlearning of Fabricated Knowledge in Language Models

Chen Sun, Nolan Andrew Miller, Andrey Zhmoginov, Max Vladymyrov, Mark Sandler

TL;DR

When large language models (LLMs) are exposed to fabricated information during finetuning, how long do they remember it? This paper discovers a surprising "sweet spot" for memory retention: grammatically coherent facts that conflict with common knowledge are retained far longer and cause more widespread hallucinations than completely random text or mundane facts. Crucially, the authors present a simple gradient sparsification technique that effectively erases this "poisoned" knowledge without degrading the model's performance on its primary task.

What Problem Does This Paper Address?

As large language models are continuously trained or finetuned on web-scale data, they are highly susceptible to data poisoning—the intentional or accidental injection of misinformation. While models naturally forget older or less frequent data over time (a phenomenon known as catastrophic forgetting), little is known about how the nature of a fabricated fact affects its longevity.

This paper investigates the temporal dynamics of memory retention in LLMs. The authors seek to understand what types of facts stick around the longest, how these fabricated memories cause the model to hallucinate on unrelated topics, and how we can selectively force the model to "unlearn" this poisoned data without harming its core capabilities.

Methods

The authors employ a multi-pronged approach to study memory injection and erasure:

  • Fact Injection: Fabricated facts are introduced into LLMs (ranging from 128M to 24B parameters, including PaLM and Gemma architectures) by replacing a single sample in the finetuning minibatch at regular intervals. Finetuning is conducted on standard instruction datasets like Alpaca, Flan, and SuperGlue.
  • Memory Tracking: The retention of injected facts is tracked quantitatively using two metrics: next-token prediction accuracy and perplexity, measured specifically at the positions of the unique keywords within the injected facts.
  • Unlearning via Update Sparsification: To eliminate the fabricated knowledge, the authors introduce a novel multi-step update sparsification procedure. Every $\tau = 500$ iterations, a binary mask is applied to the parameter updates, keeping only the top $k\%$ largest magnitude changes. This isolates and eliminates the sparse weights responsible for the fabricated memory while leaving the main task updates intact.

Datasets

The study utilizes two primary probing datasets for knowledge injection:

  1. CounterFact: An existing dataset consisting of simple, single-association counterfactuals (e.g., "The mother tongue of Danielle Darrieux is English").
  2. Outlandish: A new probing dataset created by the authors to test complex, paragraph-length facts with multiple associations. It features 5 core Knowledge-Conflicting Facts (KCFs) expanded into 200 syntactically varied phrasings via Gemini Advanced. Crucially, it includes paired Mundane versions (logically sensible, consistent with world knowledge) and Randomly Jumbled versions (same words, scrambled order) to evaluate the role of novelty.

Standard finetuning tasks are executed using the Stanford Alpaca, Flan, and SuperGlue datasets.

Key Insights and Ideas

  • The Wundt Curve of LLM Memory: LLM memory retention follows an inverted U-shape relative to novelty, mirroring human psychology. Mundane facts are ignored/forgotten quickly because they don't alter the model's existing weights much. Completely random jumbles are also quickly discarded. The "sweet spot" for long-term retention belongs to Knowledge-Conflicting Facts (KCFs)—grammatically correct but factually absurd statements.
Figure 1. Depiction of results from Fig. 3 on a Wundt-like curve.
  • Inappropriate Priming: KCFs don't just sit quietly in memory; they actively "poison" unrelated outputs. For example, telling a model that mammals originated on Uranus "79 million years ago" primes it to inject the number "79" into completely unrelated prompts about mammal running speeds or DNA percentages.
  • Memory is Sparse and Isolated: The updates that store these fabricated facts are highly localized and have near-zero cosine similarity to the updates for the main finetuning task. This architectural isolation is what makes targeted unlearning possible.

Key Results

  • Exceptional Longevity of KCFs: KCFs persist for tens of thousands of gradient updates even after only a few exposures (e.g., 10 to 200 presentations), whereas mundane and jumbled facts fade rapidly. Even an injection density as low as 1 KCF per 1200 minibatches was enough to achieve perfect next-token recall.
Figure 2. Bold red line along X-axis on plots denotes the period of false fact inception. FT and KCF in the plot legends are defined respectively as next-token-prediction accuracy (%) on the finetuning validation set and the inserted knowledge-conflicting fact. (a) Longevity of CounterFact memories in LM while undergoing finetuning. (b) Example of CounterFact fact. (c-e) Longevity of knowledge- conflicting facts, where 200 varied phrasings are presented either (c) solely at the beginning of the finetuning period and then never again, (e) at regular intervals over the course of 5000 iterations of finetuning and then never again. See Section 3.3 for plot details. (d) Example of two syntactically varied phrasings of a single false fact with the same keywords and semantic meaning.
  • Effective Poison Mitigation: Applying the update sparsification method at $k = 85\%$ (removing the bottom 85% of updates by magnitude) successfully brought the next-word prediction accuracy of the KCF down to near zero (effectively erasing it) while leaving the main task performance completely unaffected. This mitigation proved robust across a 32-fold range of KCF presentation densities.

Limitations and Future Work

  • Dataset Scale: The newly introduced Outlandish dataset is relatively small, consisting of 5 core knowledge-conflicting facts (though expanded via 200 phrasing variations each). Future work will need to scale this benchmark to a wider array of topics.
  • Mechanistic Underpinnings: The exact reason why the transformer architecture prefers the KCF "sweet spot" over mundane or random text requires deeper mechanistic interpretability research.
  • Pre-training Scenarios: The sparsification technique was tested primarily during the finetuning phase; extending this to pre-training data poisoning scenarios remains an open challenge.

Summary updated

Abstract

What happens when a new piece of knowledge is introduced into the training data and how long does it last while a large language model (LM) continues to train? We investigate this question by injecting facts into LMs from a new probing dataset, "Outlandish", which is designed to permit the testing of a spectrum of different fact types. When studying how robust these memories are, there appears to be a sweet spot in the spectrum of fact novelty between consistency with world knowledge and total randomness, where the injected memory is the most enduring. Specifically we show that facts that conflict with common knowledge are remembered for tens of thousands of training steps, while prompts not conflicting with common knowledge (mundane), as well as scrambled prompts (randomly jumbled) are both forgotten much more rapidly. Further, knowledge-conflicting facts can "prime'' how the language model hallucinates on logically unrelated prompts, showing their propensity for non-target generalization, while both mundane and randomly jumbled facts prime significantly less. Finally, we show that impacts of knowledge-conflicting facts in LMs, though they can be long lasting, can be largely erased by novel application of multi-step sparse updates, even while the training ability of the model is preserved. As such, this very simple procedure has direct implications for mitigating the effects of data poisoning in training.
BibTeX
@inproceedings{sun2024learning,
  author = {Chen Sun and Nolan Andrew Miller and Andrey Zhmoginov and Max Vladymyrov and Mark Sandler},
  title = {{Learning and Unlearning of Fabricated Knowledge in Language Models}},
  booktitle = {MI @ ICML},
  year = {2024},
  url = {https://openreview.net/forum?id=R5Q5lANcjY},
}
Figure