SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2407.07071 · EMNLP · 2024

Lookback Lens: Detecting and Mitigating Contextual Hallucinations in Large Language Models Using Only Attention Maps

Cheng-Yu Hsieh, Yoon Kim, Ranjay Krishna, James Glass, Yung-Sung Chuang, Linlu Qiu

arXiv · PDF · Open in the Atlas

Code that ran

11 of 20 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 4 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 7 failures of our instrument; 9 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2407.07071.json · badge: /api/ran/2407.07071.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
voidism/lookback-lens canonical (classifier label)
classifier basis: census
10 ran · 9 no recorded run
voidism/Lookback-Lens community
Papers with Code archive
1 ran · 0 no recorded run
FunctionStatusWhere it lives
best_subspan_em Ran
ran, honoured the contract we drafted
voidism/lookback-lens/eval_exact_match.py
pointer only (licence: NONE) · get_code("10af7cdbc53df7e5")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

convert_to_token_level Ran
ran; our contract draft was wrong, not the code
voidism/lookback-lens/step03_lookback_lens.py
pointer only (licence: NONE) · get_code("f10a909a93d528cf")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

extract_time_series_features Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
voidism/Lookback-Lens/step03_lookback_lens.py
pointer only (licence: NONE) · get_code("e6ade772c4fc8437")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/Lookback-Lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

gelu_fast Ran
ran, honoured the contract we drafted
voidism/lookback-lens/transformers-4.32.0/src/transformers/activations_tf.py
pointer only (licence: NONE); the stored copy get_code serves, from VITA-Group/READ-ME, is pointer only (licence: NONE) · get_code("37a5eed2dbd663ca")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_config_class_from_processor_class Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
voidism/lookback-lens/transformers-4.32.0/utils/create_dummy_models.py
pointer only (licence: NONE); the stored copy get_code serves, from takagi97/OXA-Fine-tuning, is pointer only (licence: NONE) · get_code("3d999b95009c7537")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_processor_types_from_config_class Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
voidism/lookback-lens/transformers-4.32.0/utils/create_dummy_models.py
pointer only (licence: NONE); the stored copy get_code serves, from takagi97/OXA-Fine-tuning, is pointer only (licence: NONE) · get_code("0c0b81b081919d8e")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

load_nq_open Ran
ran; our contract draft was wrong, not the code
voidism/lookback-lens/eval_exact_match.py
pointer only (licence: NONE) · get_code("746e55bc216a6a60")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

load_summarization Ran
ran; our contract draft was wrong, not the code
voidism/lookback-lens/step02_eval_gpt4o.py
pointer only (licence: NONE) · get_code("491bdf9d170e0f42")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

mish Ran
ran, honoured the contract we drafted
voidism/lookback-lens/transformers-4.32.0/src/transformers/activations_tf.py
pointer only (licence: NONE); the stored copy get_code serves, from VITA-Group/READ-ME, is pointer only (licence: NONE) · get_code("cc8c8c3ebf0c343f")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

normalize_answer Ran
ran; our contract draft was wrong, not the code
voidism/lookback-lens/eval_exact_match.py
pointer only (licence: NONE); the stored copy get_code serves, from zmzhang2000/trustworthy-alignment, is pointer only (licence: NONE) · get_code("9706a9a0b961096b")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

quick_gelu Ran
ran, honoured the contract we drafted
voidism/lookback-lens/transformers-4.32.0/src/transformers/activations_tf.py
pointer only (licence: NONE); the stored copy get_code serves, from VITA-Group/READ-ME, is pointer only (licence: NONE) · get_code("e2d56cb91f999bef")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_architectures_from_config_class Not yet run
unverified (harvested, no recorded run)
voidism/lookback-lens/transformers-4.32.0/utils/create_dummy_models.py
pointer only (licence: NONE); the stored copy get_code serves, from takagi97/OXA-Fine-tuning, is pointer only (licence: NONE) · get_code("b176efb26f72e507")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

load_jsonl Not yet run
unverified (harvested, no recorded run)
voidism/lookback-lens/step02_eval_gpt4o.py
pointer only (licence: NONE) · get_code("93fb30bbe389d023")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

load_nq_open Not yet run
unverified (harvested, no recorded run)
voidism/lookback-lens/step01_extract_attns.py
pointer only (licence: NONE) · get_code("124e3218c2d64455")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

load_nq_open Not yet run
unverified (harvested, no recorded run)
voidism/lookback-lens/step02_eval_gpt4o.py
pointer only (licence: NONE) · get_code("3abd09dee278805a")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

load_nq_open Not yet run
unverified (harvested, no recorded run)
voidism/lookback-lens/step04_run_decoding.py
pointer only (licence: NONE) · get_code("d10fb7dd76f75e3b")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

num_tokens_from_message Not yet run
unverified (harvested, no recorded run)
voidism/lookback-lens/step01_extract_attns.py
pointer only (licence: NONE) · get_code("b3a67ee5030c2ffe")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

num_tokens_from_message Not yet run
unverified (harvested, no recorded run)
voidism/lookback-lens/step04_run_decoding.py
pointer only (licence: NONE) · get_code("aba17adf1edf4960")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

truncate_message Not yet run
unverified (harvested, no recorded run)
voidism/lookback-lens/step01_extract_attns.py
pointer only (licence: NONE) · get_code("00d2f6a6c8b0f564")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

truncate_message Not yet run
unverified (harvested, no recorded run)
voidism/lookback-lens/step04_run_decoding.py
pointer only (licence: NONE) · get_code("0eaabf1df4cdff46")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, voidism/lookback-lens when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

Also present in other papers' code

Of 20 samples lifted from this paper's linked repositories, 20 carry a function identity and 0 do not. Of the 20 distinct functions with an identity, 9 are also present in other papers whose code we hold (9 with at least one paper dated earlier, 3 the same month, 8 later) and 11 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_config_class_from_processor_class 27 other papers
12 dated earlier, 13 later, 2 same year, order not determinable
2007.07779 (2020-07)
AdapterHub: A Framework for Adapting Transformers
2308.12219 (2023-08)
Diffusion Language Models Can Perform Many Tasks with Scaling and Instruction-Finetuning
2311.07468 (2023-11)
An Analysis and Mitigation of the Reversal Curse
and 24 more not named here
get_architectures_from_config_class 25 other papers
11 dated earlier, 13 later, 1 same year, order not determinable
2308.12219 (2023-08)
Diffusion Language Models Can Perform Many Tasks with Scaling and Instruction-Finetuning
2311.07468 (2023-11)
An Analysis and Mitigation of the Reversal Curse
2312.15710 (2023-12)
Alleviating Hallucinations of Large Language Models through Induced Hallucinations
and 22 more not named here
get_processor_types_from_config_class 25 other papers
11 dated earlier, 13 later, 1 same year, order not determinable
2308.12219 (2023-08)
Diffusion Language Models Can Perform Many Tasks with Scaling and Instruction-Finetuning
2311.07468 (2023-11)
An Analysis and Mitigation of the Reversal Curse
2312.15710 (2023-12)
Alleviating Hallucinations of Large Language Models through Induced Hallucinations
and 22 more not named here
mish 25 other papers
20 dated earlier, 1 the same month, 3 later, 1 same year, order not determinable
2007.07779 (2020-07)
AdapterHub: A Framework for Adapting Transformers
2104.08400 (2021-04)
Structure-Aware Abstractive Conversation Summarization via Discourse and Action Graphs
2106.00420 (2021-06)
Dialogue-oriented Pre-training
and 22 more not named here
gelu_fast 19 other papers
14 dated earlier, 1 the same month, 3 later, 1 same year, order not determinable
2007.07779 (2020-07)
AdapterHub: A Framework for Adapting Transformers
2110.04366 (2021-10)
Towards a Unified View of Parameter-Efficient Transfer Learning
2111.00160 (2021-11)
DSEE: Dually Sparsity-embedded Efficient Tuning of Pre-trained Language Models
and 16 more not named here
quick_gelu 16 other papers
11 dated earlier, 1 the same month, 3 later, 1 same year, order not determinable
2007.07779 (2020-07)
AdapterHub: A Framework for Adapting Transformers
2202.00666 (2022-02)
Locally Typical Sampling
2211.05392 (2022-11)
EVENTS REALM: Event Reasoning of Entity States via Language Models
and 13 more not named here
normalize_answer 11 other papers
7 dated earlier, 4 later
2308.07922 (2023-08)
RAVEN: In-Context Learning with Retrieval-Augmented Encoder-Decoder Language Models
2403.04797 (2024-03)
Found in the Middle: How Language Models Use Long Contexts Better via Plug-and-Play Positional Encoding
2403.15268 (2024-03)
Awakening Augmented Generation: Learning to Awaken Internal Knowledge of Large Language Models for Question Answering
and 8 more not named here
best_subspan_em 5 other papers
3 dated earlier, 2 later
2403.04797 (2024-03)
Found in the Middle: How Language Models Use Long Contexts Better via Plug-and-Play Positional Encoding
2403.15268 (2024-03)
Awakening Augmented Generation: Learning to Awaken Internal Knowledge of Large Language Models for Question Answering
2406.02536 (2024-06)
Mitigate Position Bias in Large Language Models via Scaling a Single Dimension
and 2 more not named here
num_tokens_from_message 2 other papers
2 dated earlier
2305.11747 (2023-05)
HaluEval: A Large-Scale Hallucination Evaluation Benchmark for Large Language Models
2401.05930 (2024-01)
SH2: Self-Highlighted Hesitation Helps You Decode More Truthfully

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

When asked to summarize articles or answer questions given a passage, large language models (LLMs) can hallucinate details and respond with unsubstantiated answers that are inaccurate with respect to the input context. This paper describes a simple approach for detecting such contextual hallucinations. We hypothesize that contextual hallucinations are related to the extent to which an LLM attends to information in the provided context versus its own generations. Based on this intuition, we propose a simple hallucination detection model whose input features are given by the ratio of attention weights on the context versus newly generated tokens (for each attention head). We find that a linear classifier based on these lookback ratio features is as effective as a richer detector that utilizes the entire hidden states of an LLM or a text-based entailment model. The lookback ratio-based detector-Lookback Lens-is found to transfer across tasks and even models, allowing a detector that is trained on a 7B model to be applied (without retraining) to a larger 13B model. We further apply this detector to mitigate contextual hallucinations, and find that a simple classifier-guided decoding approach is able to reduce the amount of hallucination, for example by 9.6% in the XSum summarization task. 1

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2407.07071")
get_code_for_paper("2407.07071")
have("2407.07071")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2407.07071.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2407.07071.svg)](https://syntology.ai/paper/2407.07071)

Connect an agent — have() is free.