Mass-Editing Memory with Attention in Transformers: A cross-lingual exploration of knowledge

Daniel Mela, Aitor Gonzalez-Agirre, Javier Hernando, Marta Villegas

Introduction

Large Language Models (LLMs) often struggle with factual grounding, frequently acting as "stochastic parrots" that lack a reliable internal database. Updating their knowledge base is a significant challenge, typically plagued by catastrophic forgetting—where new updates break existing knowledge—and cross-lingual inconsistency, where a fact updated in one language (e.g., English) remains incorrect in another (e.g., Catalan). While existing state-of-the-art methods like MEMIT focus on modifying Multi-Layer Perceptron (MLP) blocks, they often result in low confidence scores and poor cross-lingual transfer. This paper introduces MEMAT (Mass-Editing Memory with Attention in Transformers), a novel framework that supplements MLP editing with surgical adjustments to specific "truth-seeking" attention heads.

The MEMAT Framework

MEMAT builds upon the MEMIT architecture by adding a secondary intervention layer focused on the transformer's attention mechanism. The process follows three primary steps:

  1. MLP Editing: Standard mass-editing of MLP weights to incorporate new factual triplets.
  2. Locating Truthful Heads: Researchers identified specific attention heads that are highly sensitive to the truthfulness of statements. By training simple classifiers, they found that certain heads consistently achieve ~80% accuracy in distinguishing true facts from false ones.
  3. Attention Head Correction: MEMAT introduces optimized corrections to the top $K$ performing heads. This optimization balances maximizing the probability of the new target fact while minimizing changes to original values and preserving general language capabilities via KL divergence.
Heatmaps showing the location and cross-lingual stability of truth-seeking attention heads in the Aguila-7B model.

Attention as a Truth-Filter

A key insight of this work is that while MLPs may store factual data, attention heads act as a retrieval mechanism or "truth-filter." As shown in the heatmaps above, these heads are remarkably consistent across languages. This suggests that these heads encode a general "truth-telling" behavior rather than language-specific data, making the corrections highly portable across different sets of facts.

Cross-Lingual Performance and the Tokenization Bottleneck

To test cross-lingual robustness, the authors developed Catalan CounterFact, a translated version of the standard benchmark. Experiments on the Aguila-7B model revealed that cross-lingual success is heavily dependent on subject tokenization. When a subject (e.g., "Google") is tokenized identically across languages, knowledge transfer is seamless. However, when tokenization differs significantly (Jaccard index $\leq$ 0.5), performance drops.

Radar charts illustrating success and magnitude metrics across different training languages and tokenization conditions.

Key Results

  • Magnitude and Confidence: MEMAT achieved a 10% increase in magnitude metrics (the probability gap between correct and incorrect answers) over the MEMIT baseline.
  • Generalization: The model showed superior performance in paraphrase tests, indicating it learned underlying concepts rather than just memorizing strings.
  • Efficiency: The attention head correction phase is highly efficient, requiring only 25 GPU minutes to supplement a 3-hour mass-edit of 1,000 facts.
  • Robustness: MEMAT improved performance even in languages not used during the specific head-correction training phase.

Limitations and Future Work

While effective, MEMAT's performance begins to degrade as the number of edited associations approaches 10,000. Furthermore, the study focused on English and Catalan; results may vary for language pairs with different scripts (e.g., English and Chinese). Future research will explore the role of other architectural components, such as LayerNorm, and address the ongoing challenge of "bidirectionality" in knowledge editing (e.g., ensuring the model understands that if A is B's father, B is A's child).

Summary updated

Abstract

Recent research has explored methods for updating and modifying factual knowledge in large language models, often focusing on specific multi-layer perceptron blocks. This study expands on this work by examining the effectiveness of existing knowledge editing methods across languages and delving into the role of attention mechanisms in this process. Drawing from the insights gained, we propose Mass-Editing Memory with Attention in Transformers (MEMAT), a method that achieves significant improvements in all metrics while requiring minimal parameter modifications. MEMAT delivers a remarkable 10% increase in magnitude metrics, benefits languages not included in the training data and also demonstrates a high degree of portability. Our code and data are at https://github.com/dtamayo-nlp/MEMAT.
BibTeX
@inproceedings{mela2024mass,
  author = {Daniel Mela and Aitor Gonzalez-Agirre and Javier Hernando and Marta Villegas},
  title = {{Mass-Editing Memory with Attention in Transformers: A cross-lingual exploration of knowledge}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.347},
}
Figure