Dissecting Recall of Factual Associations in Auto-Regressive Language Models

Mor Geva, Jasmijn Bastings, Katja Filippova, Amir Globerson

TL;DR

Researchers have uncovered a specific three-step "internal pipeline" that auto-regressive language models use to recall facts. Instead of a single "lookup," models first enrich the subject's representation with many related attributes in early layers, then use upper-layer attention heads to "query" that representation and extract the specific correct answer.

What Problem Does This Paper Address?

We know that large language models (LLMs) like GPT-4 are walking encyclopedias, but we don't fully understand their "internal search engine." Previous research has identified where facts might be stored (often pointing to MLP layers as key-value memories), but the how—the dynamic process of information flow during a single forward pass—remained a mystery.

When you ask a model to complete "Beats Music is owned by...", how does it navigate its billions of parameters to land on "Apple"? This paper aims to map the trajectory of information across layers and token positions to explain the mechanics of factual recall.

Methods

The authors employ a "reverse-engineering" approach using several clever intervention techniques on GPT-2 and GPT-J:

  • Attention Knockout: The researchers systematically blocked specific attention edges (e.g., preventing the last token from "seeing" the subject tokens) at different layers. By measuring how much the prediction probability dropped, they identified exactly when and where information becomes critical.
  • Logit Lens / Vocabulary Projection: They projected intermediate hidden states directly into the model's vocabulary space. This allows us to see what the model is "thinking" at any given layer—for example, seeing if the representation for "Music" starts to look like "Apple" or "Spotify" halfway through the network.
  • Sublayer Knockout & Patching: They zeroed out specific MLP or Attention updates to see which components were responsible for building the final answer.

Datasets

The study primarily uses COUNTERFACT, a dataset designed to evaluate factual knowledge in LMs by providing subject-relation-attribute triplets (e.g., Subject: Beats Music, Relation: is owned by, Attribute: Apple). They filtered for cases where the models (GPT-2 XL and GPT-J) already predicted the correct attribute to ensure they were studying successful recall.

Key Insights and Ideas

The paper unveils a sophisticated three-step mechanism for factual recall, illustrated in the figure below:

Figure 1: Illustration of our findings: given subject- relation query, a subject representation is constructed via attributes’ enrichment from MLP sublayers (A), while the relation propagates to the prediction (B). The at- tribute is then extracted by the MHSA sublayers (C).
  1. Subject Enrichment (The "Broad Search"): In the early layers, the MLP sublayers act on the subject tokens (e.g., "Music"). They don't just identify the subject; they "load" its representation with a wealth of related attributes. By layer 40 in GPT-2, nearly 50% of the top-ranked tokens in the subject's hidden state are semantically related attributes.
  2. Relation Propagation: Simultaneously, the specific relation (e.g., "owned by") is processed and moved to the final token position.
  3. Attribute Extraction (The "Specific Query"): In the upper layers, the model performs the final "extraction." The representation at the last position acts as a query, and—perhaps most surprisingly—attention heads are the primary extractors. These heads often have specific subject-attribute mappings (like "iPod" $\rightarrow$ "Apple") hardcoded into their weights.

Key Results

  • Disjointed Stages: The "Attention Knockout" experiments revealed two distinct peaks of critical information flow: first from the relation tokens in early-mid layers, followed by a massive surge from the subject tokens in the upper layers.
Figure 2: Relative change in the prediction probability when intervening on attention edges to the last position, for window sizes of 9 layers in GPT-2 and 5 in GPT-J.
  • MLPs as Enriched Libraries: Early MLP layers are responsible for ~88% of the subject enrichment process. Without them, the subject representation loses its "factual depth."
  • Attention as the Extractor: In roughly 70% of successful predictions, the final attribute is extracted by MHSA (Multi-Head Self-Attention) sublayers in the top third of the model.
  • Knowledge Hubs: The authors identified specific "knowledge" attention heads that act as hubs, encoding hundreds of different factual associations in their parameters.

Limitations and Future Work

While the paper provides a clear map of information flow, the authors note a few caveats:

  • Approximation: Projecting hidden states to vocabulary (the Logit Lens) is an approximation of the model's internal state, especially in very early layers where representations are less "semantic."
  • Information Leakage: While they used "windows" of layers for their knockouts to prevent information from leaking through alternative paths, the complexity of Transformers means some leakage is always possible.
  • Generalization: The study focuses on factual recall. It remains to be seen if similar "enrichment-then-extraction" pipelines exist for reasoning, coding, or creative writing tasks.

This work opens the door for more precise model editing. Instead of just changing MLP weights, researchers might now look at editing the "knowledge heads" in the attention layers to update or correct facts more effectively.

Summary updated

BibTeX
@inproceedings{geva2023dissecting,
  author = {Mor Geva and Jasmijn Bastings and Katja Filippova and Amir Globerson},
  title = {{Dissecting Recall of Factual Associations in Auto-Regressive Language Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.emnlp-main.751},
}
Figure