Detecting Contextual Hallucinations in LLMs with Frequency-Aware Attention
Authors: Siya Qi, Yudong Chen, Runcong Zhao, Qinglin Zhu, Zhanghao Hu, Wei Liu, Yulan He, Zheng Yuan, Lin Gui
Organizations: Department of Informatics, King’s College London, UK · Department of Statistics, University of Warwick, UK · The Alan Turing Institute, UK · School of Computer Science, The University of Sheffield, UK
Hallucination detection is critical for ensuring the reliability of large language models (LLMs) in context-based generation. Prior work has explored intrinsic signals available during generation, among which attention offers a direct view of grounding behavior. However, existing approaches typically rely on coarse summaries that fail to capture fine-grained instabilities in attention. Inspired by signal processing, we introduce a frequency-aware perspective on attention by analyzing its variation during generation. We model attention distributions as discrete signals and extract high-frequency components that reflect rapid local changes in attention. Our analysis reveals that hallucinated tokens are associated with high-frequency attention energy, reflecting fragmented and unstable grounding behavior. Based on this insight, we develop a lightweight hallucination detector using high-frequency attention features. Experiments on the RAGTruth and HalluRAG benchmarks show that our approach achieves performance gains over verification-based, internal-representation-based, and attention-based methods across models and tasks.
Figures & tables
Figure 1: Attention weights over context and previously generated tokens for a grounded token (blue, “rainy”) and a hallucinated token (red, “December”) in a context-based QA example.
Figure 2: Three hypotheses for identifying hallucination tokens from incoming attention patterns. We illustrate three representative assumptions for distinguishing well-grounded tokens (✓) from potential hallucinations (✗) based on the incoming attention to the next generated token.
Figure 3: Overview of frequency-aware attention modeling for hallucination detection. Attention weights are extracted from each layer and head ( L layers and H heads in total), treated as token-level signals, and decomposed using high-pass filtering to isolate high-frequency variations ( Fhigh ), whose energy is aggregated for hallucination detection.
Model
Method
RT-QA
RT-D2T
RT-Summ
HalluRAG
Overall Avg.
F
AUROC
F
AUROC
F
AUROC
F
AUROC
Avg-F
Avg-A
LLaMA-7B
SelfcheckGPT
0.6289
0.6942
0.6552
0.8026
0.6349
0.6674
0.5388
0.5963
0.6145
0.6901
RefChecker
0.5914
0.5865
0.5713
0.6349
0.6059
0.6080
0.5819
0.5722
0.5876
0.6004
EigenScore
0.4979
0.5253
0.5256
0.5297
0.5065
0.4989
0.5364
0.6127
0.5166
0.5416
Redeep
0.5972
0.6364
0.4791
0.3960
0.5897
0.5760
0.5912
0.6490
0.5643
0.5643
Lookback-lens
0.6930
0.8482
0.6175
0.8442
0.5328
0.7156
0.6266
0.7405
0.6175
0.7871
Table 1: Comparison of different methods on RAGTruth and HalluRAG. Wavelet-high and Fourier-high denote leveraging the high-frequency components obtained via DWT and DFT, respectively. Bold and underlined values indicate the best and second-best performance within each model group.
Model
Method
RagTruth-Avg
HalluRAG
F
AUROC
F
AUROC
LLaMA-7B
Lookback-lens
0.6773
0.7884
0.6623
0.7856
Laplacian
0.6747
0.7877
0.6775
0.7754
Wavelet-High
0.6911
0.8117
0.6812
0.7928
Fourier-high
0.7003
0.8412
0.6866
0.8100
LLaMA-13B
Lookback-lens
0.6781
0.8183
0.7096
0.8505
Table 2: Performance comparison on RagTruth-Avg and HalluRAG for sliding-window=8. Within each model, the best result is highlighted in bold , and the second-best is underlined .
Figure 4: Comparing full-, low-, and high-pass Fourier attention features. Average AUROC across models under token- and span-level evaluation settings.
Figure 5: Layer-wise importance of high-frequency Fourier-high attention features for LLaMA-7B.
RagTruth-Avg
Method
Original
Top- k heads
k = 100
50
10
Laplacian
0.8003
0.7824
0.7666
0.7131
Wavelet-high
0.8087
0.7900
0.7708
0.7193
Fourier-high
0.8205
0.7915
0.7684
0.6995
HalluRAG
Table 3: AUROC Results for LLaMA-7B: Original vs. Top- k head only performance.
Figure 6: Average absolute classifier importance assigned to context-attention and generated-attention features over all examined models and datasets.
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
Dataset
Task
Train
Val
Test
Prompt Len.
Response Len.
Halluc. Ratio
RagTruth
QA
839
–
150
439.5
208.1
0.1045
D2T
883
–
150
892.8
225.4
0.0768
Summ
793
–
150
840.1
153.4
0.0527
HalluRAG
QA
756
162
162
649.3
44.4
0.1530
Appendix
Table A1 : Statistics of datasets used in our experiments. Length and ratio are calculated on the token level.
Method
Target
Token-Level (Source)
Span-Level (Source)
QA
D2T
Summ
QA
D2T
Summ
Lookback-lens
QA
0.8482
0.7839
0.7741
0.8467
0.8140
0.7985
D2T
0.6340
0.8442
0.7211
0.6334
0.8551
0.7275
Summ
0.6618
0.6400
0.7156
0.6563
0.6496
0.6635
Laplacian
QA
0.8449
0.7928
0.7881
0.8365
0.7898
0.7857
D2T
0.6438
0.8519
0.6809
0.6147
0.8646
0.6264
Appendix
Table A2: Cross-domain evaluation. Models are trained on the column domain (Source) and evaluated on the row domain (Target). Bold values indicate in-domain performance (diagonal, Target=Source). Darker shading corresponds to higher cross-domain performance.
Model / Method
RT-QA
RT-D2T
RT-Summ
HalluRAG
Overall Avg.
F
AUROC
F
AUROC
F
AUROC
F
AUROC
Avg-F
Avg-A
LLaMA-7B
Lookback-lens
0.7218
0.8467
0.7249
0.8551
0.5852
0.6635
0.6623
0.7856
0.6736
0.7877
Attn-variance
0.5077
0.6979
0.4714
0.5886
0.4840
0.6348
0.4446
0.5209
0.4769
0.6106
Attn-entropy
0.7292
0.8502
0.7060
0.8457
0.5489
0.6637
0.6282
0.6909
0.6531
0.7626
Laplacian
0.7074
0.8365
0.7334
0.8646
0.5833
0.6619
0.6775
0.7754
0.6754
0.7846
Appendix
Table A3: Full performance comparison on RagTruth and HalluRAG with chunk size set to 8. For each model, the best result is highlighted in bold , and the second-best result is underlined .
Figure A1 : Ablation study on different frequency cutoffs at token and span levels on hallucination detection performance. The top row (a-d) shows results at the token level, while the bottom row (e-h) shows results at the span level.
Model/Level
Padding
RT-QA
RT-D2T
RT-Summ
HalluRAG
Overall Avg.
F
AUROC
F
AUROC
F
AUROC
F
AUROC
Avg-F
Avg-A
LLaMA-7B
level1
zero
0.7194
0.8526
0.6898
0.8569
0.5929
0.7165
0.6384
0.7550
0.6601
0.7953
period
0.7146
0.8514
0.6887
0.8517
0.5799
0.7091
0.6360
0.7449
0.6548
0.7893
symm
0.7215
0.8557
0.6875
0.8545
0.5880
0.7182
0.6353
0.7521
0.6581
0.7951
level2
zero
0.7157
0.8522
0.6893
0.8531
0.5822
0.7088
0.6359
0.7464
0.6558
0.7901
Appendix
Table A4: Performance comparison on token level using Wavelet-high across levels and padding methods. Best results within each model are in bold ; second-best are underlined .
Model/Level
Padding
RT-QA
RT-D2T
RT-Summ
HalluRAG
Overall Avg.
F
AUROC
F
AUROC
F
AUROC
F
AUROC
Avg-F
Avg-A
LLaMA-7B
level1
zero
0.7313
0.8611
0.7479
0.8785
0.6020
0.7169
0.6846
0.8047
0.6915
0.8153
period
0.7271
0.8572
0.7426
0.8748
0.5973
0.7008
0.6786
0.7963
0.6864
0.8073
symm
0.7331
0.8680
0.7478
0.8821
0.6045
0.7199
0.6812
0.7928
0.6917
0.8157
level2
zero
0.7277
0.8594
0.7461
0.8760
0.5996
0.6997
0.6800
0.7953
0.6884
0.8076
Appendix
Table A5: Performance comparison when chunk size is 8 using Wavelet-high across levels and padding methods. Best results within each model are in bold ; second-best are underlined .
Figure A2 : Full results of comparing Full-, Low-, and High-Pass Fourier attention features. Average AUROC across models under token- and span-level evaluation settings.
Figure A3 : Full results for layer-wise importance. Solid and dashed lines correspond to token-level and span-level detection, respectively. The shaded region indicates the standard deviation of head-level importance within each layer.
Table A6: Original vs. Top- k head only Performance.
Model
Setting
Operator
RagTruth-Avg
HalluRAG
F
AUROC
F
AUROC
LLaMA-7B
Original
Laplacian
0.6588
0.8003
0.6370
0.7429
Wavelet-high
0.6673
0.8087
0.6384
0.7550
Fourier-high
0.6685
0.8205
0.6478
0.7629
Context-only
Laplacian
0.6504
0.8014
0.6340
0.7396
Wavelet-high
0.6541
0.8074
0.6402
0.7479
Appendix
Table A7 : Ablation study comparing context-only and generated-only attention features. Results are reported across spectral operators and models.
Figure A4 : Raw attention signal visualizations. Each subfigure compares raw attention distributions for a hallucinated token (left) and a non-hallucinated token (right). Red and yellow curves denote attention over context and generated tokens, respectively, when generating a hallucinated token, while blue and green curves denote attention over context and generated tokens for a non-hallucinated token.
Retrieval-Augmented Generation (RAG) is widely used to augment the input to Large Language Models (LLMs) with external information, such as recent or domain-specific knowledge. Nonetheless, current models still produce closed-domain hallucinations and generate content that is unsupported by the retrieved context. Current detection approaches typically treat hallucination as a post-hoc problem, relying on black-box consistency checks or probes over frozen internal representations. In this work, we demonstrate that hallucination detection based on internal state representation can also serve as a direct training signal. We introduce RAGognize, a dataset of naturally occurring closed-domain hallucinations with token-level annotations, and RAGognizer, a hallucination-aware fine-tuning approach that integrates a lightweight detection head into an LLM, allowing for the joint optimization of language modeling and hallucination detection. This joint objective forces the model to improve the separability of its internal states regarding hallucinations while simultaneously learning to generate well-formed and meaningful responses. Across multiple benchmarks, RAGognizer achieves state-of-the-art token-level hallucination detection while substantially reducing hallucination rates during generation, without degrading language quality or relevance.
Fabian Ridder, Laurin Lessel, Malte Schilling
Computer Science Department, University of Münster, Münster, Germany
In this work, we examine the topology of information flow patterns within attention graphs to effectively distinguish hallucinated from non-hallucinated responses. We analyze the Forman-Ricci curvature to identify structural patterns indicating information bottlenecks in attention graphs. We then introduce a method that captures both semi-local and global information-flow characteristics of attention heads associated with hallucinated responses. We evaluate our approach extensively across several LLMs and established benchmarks. Empirical results demonstrate that our proposed single-pass approach provides consistent improvements over existing attention-based and multi-response baselines across two hallucination-detection benchmarks, while achieving competitive performance across diverse LLM architectures. Further analysis reveals that impaired context sharing among tokens during causal generation is strongly associated with hallucination occurrences in LLMs. In particular, hallucinated responses are consistently characterized by an over-reliance on self-attention, diffused context retrieval from earlier tokens, or information over-squashing, especially in the final transformer layer.
Amir Jalilifard, Anderson Rocha, Eric Wong +1
Institute of Computing, Universidade Estadual de Campinas (UNICAMP), Campinas, SP, Brazil · Department of Computer and Information Science, University of Pennsylvania, Philadelphia, PA, USA
Large Language Models (LLMs) are powerful and widely adopted, but their practical impact is limited by the well-known hallucination phenomenon. While recent hallucination detection methods have made notable progress, we find most of them overlook the dynamic nature and underlying mechanisms of it. To address this gap, we propose HalluSAE, a phase transition-inspired framework that models hallucination as a critical shift in the model's latent dynamics. By modeling the generation process as a trajectory through a potential energy landscape, HalluSAE identifies critical transition zones and attributes factual errors to specific high-energy sparse features. Our approach consists of three stages: (1) Potential Energy Empowered Phase Zone Localization via sparse autoencoders and a geometric potential energy metric; (2) Hallucination-related Sparse Feature Attribution using contrastive logit attribution; and (3) Probing-based Causal Hallucination Detection through linear probes on disentangled features. Extensive experiments on Gemma-2-9B demonstrate that HalluSAE achieves state-of-the-art hallucination detection performance.
Boshui Chen, Zhaoxin Fan, Ke Wang +5
Beijing Advanced Innovation Center for Future Blockchain and Privacy Computing, School of Artificial Intelligence, Beihang University, Beijing, China. · State Key Laboratory of Virtual Reality Technology and Systems, Beihang University, Beijing, China. · Beijing Academy of Blockchain and Edge Computing, Beijing, China. +1