Papers › Interpreting Key Mechanisms of Factual Recall in Transformer-Based Language Models

Interpreting Key Mechanisms of Factual Recall in Transformer-Based Language Models

28 Mar 2024arXiv:2403.19521archive 2025-07-28

Ang Lv, Yuhan Chen, Kaiyi Zhang, Yulong Wang, Lifeng Liu, Ji-Rong Wen, Jian Xie, Rui Yan

In this paper, we delve into several mechanisms employed by Transformer-based language models (LLMs) for factual recall tasks. We outline a pipeline consisting of three major steps: (1) Given a prompt ``The capital of France is,'' task-specific attention heads extract the topic token, such as ``France,'' from the context and pass it to subsequent MLPs. (2) As attention heads' outputs are aggregated with equal weight and added to the residual stream, the subsequent MLP acts as an ``activation,'' which either erases or amplifies the information originating from individual heads. As a result, the topic token ``France'' stands out in the residual stream. (3) A deep MLP takes ``France'' and generates a component that redirects the residual stream towards the direction of the correct answer, i.e., ``Paris.'' This procedure is akin to applying an implicit function such as ``get\_capital(X),'' and the argument X is the topic token information passed by attention heads. To achieve the above quantitative and qualitative analysis for MLPs, we proposed a novel analytic method aimed at decomposing the outputs of the MLP into components understandable by humans. Additionally, we observed a universal anti-overconfidence mechanism in the final layer of models, which suppresses correct predictions. We mitigate this suppression by leveraging our interpretation to improve factual recall confidence. The above interpretations are evaluated across diverse tasks spanning various domains of factual knowledge, using various language models from the GPT-2 families, 1.3B OPT, up to 7B Llama-2, and in both zero- and few-shot setups.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2403.19521")

Code

Syntology Ran 12 of 14 code samples harvested from 1 repository linked to this paper; 2 have no recorded run. Of those that ran: 12 ran with no contract checked.

By repository: official repository: 14 samples from 1 repository, 12 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

trestad/factual-recall-mechanism officialmentioned in papermentioned on GitHubpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

14 samples harvested; 12 ran; 0 honoured the contract we drafted; 2 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

12ran
2unverified

Licence: 14 of the 14 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from trestad/factual-recall-mechanism. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

gen_flipped_prompts trestad/factual-recall-mechanism/easy_transformer/fact_dataset.py official repository ran no licence file found · pointer only · bf14a58ad9daa314 · report
gen_prompt_uniform trestad/factual-recall-mechanism/easy_transformer/fact_dataset.py official repository ran no licence file found · pointer only · 0e748f7b2746f129 · report
get_corner trestad/factual-recall-mechanism/easy_transformer/utils.py official repository ran fingerprinted no licence file found · pointer only · 1f5a0cbe7a2e0eac · report
get_hook_tuple trestad/factual-recall-mechanism/easy_transformer/utils_circuit_discovery.py official repository ran no licence file found · pointer only · c3e96952330b24b6 · report
get_sample_from_dataset trestad/factual-recall-mechanism/easy_transformer/utils.py official repository ran no licence file found · pointer only · 0f4a0aa12ed98682 · report
list_diff trestad/factual-recall-mechanism/easy_transformer/fact_circuit_extraction.py official repository ran no licence file found · pointer only · c3075c10972d3c04 · report
max_2d trestad/factual-recall-mechanism/easy_transformer/fact_utils.py official repository ran no licence file found · pointer only · 34f3624167c77416 · report
patch_all trestad/factual-recall-mechanism/easy_transformer/utils_circuit_discovery.py official repository ran no licence file found · pointer only · a08c9fa456b3584d · report
patch_positions trestad/factual-recall-mechanism/easy_transformer/utils_circuit_discovery.py official repository ran no licence file found · pointer only · 6bc19a4e655618d7 · report
process_heads_and_mlps trestad/factual-recall-mechanism/easy_transformer/fact_circuit_extraction.py official repository ran no licence file found · pointer only · 6275c5441a2e89af · report
remove_prefix trestad/factual-recall-mechanism/easy_transformer/fact_dataset.py official repository ran no licence file found · pointer only · 09c5e6ff142680cd · report
turn_keep_into_rmv trestad/factual-recall-mechanism/easy_transformer/fact_circuit_extraction.py official repository ran no licence file found · pointer only · 168eb8501c7db28f · report
download_file_from_hf trestad/factual-recall-mechanism/easy_transformer/utils.py official repository unverified no licence file found · pointer only · b05aad9a321cedec · report
show_tokens trestad/factual-recall-mechanism/easy_transformer/fact_utils.py official repository unverified no licence file found · pointer only · 7726d0418a0ec986 · report

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

AdamAttentionAttention DropoutBPECosine AnnealingDense ConnectionsDiscriminative Fine-TuningDropoutGPT-2Layer NormalizationLinear LayerLinear Warmup With Cosine AnnealingMulti-Head AttentionOPTResidual ConnectionSoftmaxWeight Decay

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections