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 View this paper on Syntology, its page in Syntology's graph. That page adds which of its functions are also present in other papers' code Syntology holds, with dates, and its dated run record as JSON and a README badge. It also lists the repositories linked to the paper, the abstract and the calls for agents.

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

For agents, on Syntology's MCP service (how to connect):

Code

Syntology 14 code samples harvested from 1 repository linked to this paper: 12 ran (of which 0 constructed an object rather than computing a result; 10 with no instrument failure: 0 honoured, 0 violated, 10 with no contract checked; 2 where Syntology's instrument failed) · 2 unverified. Where Syntology's instrument failed: 2 where our contract draft was wrong; failures of Syntology's instrument, not of the code.

By repository: official repository: 14 samples from 1 repository, 12 ran (10 with no instrument failure; 2 where Syntology's instrument failed). The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

Levels written on 2026-09-24 (UTC): the dates Syntology's graph wrote each sample's verification level, not when the code executed.

trestad/factual-recall-mechanism officialmentioned in papermentioned on GitHubpytorchSyntology: 14 samples, 12 ran (2 instrument-failed) · 2 unverified 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 (of which 0 constructed an object rather than computing a result; 10 with no instrument failure: 0 honoured, 0 violated, 10 with no contract checked; 2 where Syntology's instrument failed) · 2 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Syntology's record for this page last changed ; when this build read Syntology's graph is in the build record. That date is not when the samples ran.

2ran · our draft was wrong
10ran
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. A line beginning “fixture:” under a sample that ran gives the arguments Syntology's fixture called the sample with, each as name:type/rank/element kind (? where none was recorded), and the type of what the fixture's run returned, exactly as the harness recorded them; the arguments and the returned type were recorded by two separate runs of the same fixture. No output value is shown, and a returned type says nothing about whether the output was right. “Level recorded” gives the UTC date when Syntology's graph wrote the sample's verification level, not when the code executed; where the level was written before Syntology's graph kept that date, the row says “level recorded, date not recorded”. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself. “Our draft was wrong” and “the contract check could not run” are failures of Syntology's instrument, not of the code: the sample ran on Syntology's synthesized input, and then the drafted contract did not describe it, or the check itself raised an error (RAISES), lacked a dependency (DEP_MISSING) or ran out of time (TIMEOUT); hover the label for which. A metamorphic tier, where shown, is evidence of the output's shape, not that the sample implements the method.

Each sample ends with its code_sha256. A sample's code_sha256 is Syntology's identity for that exact code. It is printed in full (16 hexadecimal characters for every sample in this build), and get_code(code_sha256="…") takes it exactly as printed. An agent calls it on Syntology's MCP service (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 are grouped by repository: a repository marked official first, then by how directly the repository is tied to the paper, then in the archive's order; never by how many ran. 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 six 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; the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar); this paper's copy was not located, so its licence is not recorded; or this paper's copy is cleared, but the stored copy of the same code that Syntology serves is not. 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.

A function or class name links to its page when the name occurs in the harvested code of at least 5 papers; the name is a string, not an identity.

trestad/factual-recall-mechanism official repository 14 samples, 12 ran (2 instrument-failed) · 2 unverified
gen_flipped_prompts easy_transformer/fact_dataset.py ran no licence file found · pointer only · bf14a58ad9daa314 · report fixture: signature prompts:list/1/dict, nations:list/1/str, cities:list/1/str, flip:tuple/1/str · returned list · level recorded 2026-09-24
gen_prompt_uniform easy_transformer/fact_dataset.py ran no licence file found · pointer only · 0e748f7b2746f129 · report fixture: signature templates:list/1/str, nations:list/1/str, cities:list/1/str, nc_dict:dict/0/?, N:int/0/int, symmetric:bool/0/bool, prefixes:list/1/str, counterfact:bool/0/bool, all_same:bool/0/bool, passed_nation:NoneType/0/?, tokenizer:StandInTokenizer/0/? · returned tuple · level recorded 2026-09-24
get_corner easy_transformer/utils.py ran fingerprinted no licence file found · pointer only · 1f5a0cbe7a2e0eac · report fixture: signature tensor:Tensor/4/float, n:int/0/int · returned Tensor · level recorded 2026-09-24
get_hook_tuple easy_transformer/utils_circuit_discovery.py ran no licence file found · pointer only · c3e96952330b24b6 · report fixture: returned tuple · level recorded 2026-09-24
get_sample_from_dataset easy_transformer/utils.py ran no licence file found · pointer only · 0f4a0aa12ed98682 · report fixture: signature sequences:list/1/ndarray, nb_sample:int/0/int, print_len:int/0/int · returned str · level recorded 2026-09-24
list_diff easy_transformer/fact_circuit_extraction.py ran no licence file found · pointer only · c3075c10972d3c04 · report fixture: returned list · level recorded 2026-09-24
max_2d easy_transformer/fact_utils.py ran · our draft was wrong no licence file found · pointer only · 34f3624167c77416 · report fixture: signature m:Tensor/2/float, k:int/0/int · returned tuple · level recorded 2026-09-24
patch_all easy_transformer/utils_circuit_discovery.py ran no licence file found · pointer only · a08c9fa456b3584d · report fixture: signature z:Tensor/2/float, source_act:Tensor/2/float, hook:NoneType/0/? · returned Tensor · level recorded 2026-09-24
patch_positions easy_transformer/utils_circuit_discovery.py ran no licence file found · pointer only · 6bc19a4e655618d7 · report fixture: signature z:Tensor/2/float, source_act:Tensor/2/float, hook:NoneType/0/?, positions:list/1/int · returned Tensor · level recorded 2026-09-24
process_heads_and_mlps easy_transformer/fact_circuit_extraction.py ran no licence file found · pointer only · 6275c5441a2e89af · report fixture: signature heads_to_remove:NoneType/0/?, mlps_to_remove:NoneType/0/?, heads_to_keep:dict/0/?, mlps_to_keep:dict/0/?, ioi_dataset:MinimalIOIDataset/0/?, model:callable/0/? · returned tuple · level recorded 2026-09-24
remove_prefix in 26 papers easy_transformer/fact_dataset.py ran · our draft was wrong no licence file found · pointer only · 09c5e6ff142680cd · report fixture: signature prompt:str/0/str · returned str · level recorded 2026-09-24
turn_keep_into_rmv easy_transformer/fact_circuit_extraction.py ran no licence file found · pointer only · 168eb8501c7db28f · report fixture: signature to_keep:dict/0/?, max_len:int/0/int · returned dict · level recorded 2026-09-24
download_file_from_hf easy_transformer/utils.py unverified no licence file found · pointer only · b05aad9a321cedec · report
show_tokens easy_transformer/fact_utils.py 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