Editing Factual Knowledge in Language Models

Nicola De Cao, Wilker Aziz, Ivan Titov

Abstract: Nicola De Cao, Wilker Aziz, Ivan Titov. Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing.

2021.

Introduction

Large Language Models (LMs) like BERT and BART serve as implicit knowledge bases, memorizing vast amounts of factual data during pre-training. However, this knowledge is static and often contains errors or becomes obsolete over time. Traditional methods for updating this information, such as global retraining or standard fine-tuning, face significant hurdles. Retraining is computationally prohibitive, while fine-tuning often leads to "catastrophic forgetting," where updating one fact inadvertently degrades the model's performance on unrelated tasks.

Furthermore, standard fine-tuning lacks consistency; a model might learn that "The capital of Namibia is Windhoek" but fail to provide the correct answer when the question is phrased differently (e.g., "How is Namibia's capital city called?"). This paper introduces KNOWLEDGEEDITOR (KE), a method designed to be general, reliable, and consistent in updating specific factual knowledge within an LM's parameters.

The KnowledgeEditor Framework

KNOWLEDGEEDITOR treats model editing as a "learning-to-update" problem. Rather than manually adjusting weights through trial and error, the authors propose using a specialized hyper-network to predict the necessary weight shifts.

The KnowledgeEditor framework: A hyper-network $g$ predicts weight updates $\Delta\theta$ to modify model $f$ for a specific fact while retaining previous knowledge.

Key Components of KE:

  • Hyper-network Architecture: A small neural network takes a specific fact as input and predicts a weight update ($\Delta\theta$) for the target LM. To identify which parameters are responsible for specific knowledge, the hyper-network utilizes the gradient of the target fact as a primary input.
  • Constrained Optimization: The editor is trained to minimize loss for the new fact while strictly constraining the model's output for unrelated data. This is achieved using KL Divergence, ensuring that the model's probability distributions remain stable for non-target inputs.
  • Rank-1 Parameterization: To maintain computational efficiency, KE does not predict every parameter change. Instead, it predicts vectors that form a "rank-1" update to the weight matrices, allowing the method to scale linearly with model size.

Experimental Evaluation

The researchers evaluated KE on two primary tasks: FEVER (Fact Extraction and VERification) using BERT, and zsRE (Zero-Shot Relation Extraction) using BART. To test for consistency, they utilized human-annotated paraphrases and generated additional ones via round-trip translation.

Comparison of model predictions before and after a KnowledgeEditor update. The edit generalizes to semantically equivalent questions while preserving unrelated facts (e.g., the capital of Russia).

Key Findings

KNOWLEDGEEDITOR demonstrated superior performance across several metrics compared to traditional fine-tuning baselines:

  • Surgical Precision: Analysis revealed that the hyper-network learned to concentrate updates on specific components, primarily the first encoder layer and the last decoder layer. Interestingly, the editor preferred modifying parameters affecting the shape of attention distributions (Query and Key matrices) rather than the stored values (Value matrices), suggesting that editing is more about rerouting information flow than changing raw data.
  • High Success and Retention: KE achieved nearly 100% success in updating target facts. While standard fine-tuning caused accuracy on unrelated facts to drop significantly (sometimes to ~67%), KE maintained a ~98% retention accuracy.
  • Generalization: The method proved highly consistent, with the model correctly applying edits to paraphrased versions of questions 94-97% of the time.
  • Efficiency: At test time, the method is highly efficient, requiring only a single forward pass of the hyper-network to generate the necessary "patch" for the model.

Conclusion

KNOWLEDGEEDITOR provides a robust framework for the surgical modification of factual knowledge in LMs. By operating in function space rather than just parameter space, it ensures that updates are both consistent across paraphrases and harmless to the model's broader knowledge base. Future work will look toward scaling this approach to batch edits and exploring the deeper causal mechanisms of how transformers store specific strings of information.

Summary updated

BibTeX
@inproceedings{cao2021editing,
  author = {Nicola De Cao and Wilker Aziz and Ivan Titov},
  title = {{Editing Factual Knowledge in Language Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  url = {https://openreview.net/forum?id=hjFc55d7As3},
}
Figure