Hallucination Detection in LLMs Using Spectral Features of Attention Maps

Jakub Binkowski, Denis Janiak, Albert Sawczyn, Bogdan Gabrys, Tomasz Jan KajdanowiczEMNLP 2025

TL;DR

This paper introduces LapEigvals, a novel method for detecting hallucinations in Large Language Models (LLMs) by analyzing the spectral properties of their attention maps. By treating attention maps as graph adjacency matrices and examining the eigenvalues of their Laplacian, LapEigvals achieves state-of-the-art performance in hallucination detection, outperforming previous attention-based methods.

What Problem Does This Paper Address?

Large Language Models (LLMs) have demonstrated remarkable capabilities across various tasks, but they are still prone to "hallucinations" – generating nonsensical or unfaithful content. This is a critical issue, especially for safety-critical applications. While existing methods leverage attention map properties to detect these hallucinations, their effectiveness is limited. This paper aims to improve hallucination detection by exploring a novel perspective on attention maps and developing a more robust and accurate detection method.

Methods

The core contribution of this paper is the LapEigvals method. It treats LLM attention maps as weighted adjacency matrices of directed graphs, where tokens are nodes and attention scores are edge weights. The method then constructs a Laplacian matrix from these attention maps. The key insight is that the eigenvalues of this Laplacian matrix capture important information about the graph structure, which can indicate disruptions in information flow that correlate with hallucinations. Specifically, the top-k eigenvalues of the Laplacian are extracted as features for a logistic regression probe to classify whether a generated output is a hallucination. The authors also employ Principal Component Analysis (PCA) to reduce the dimensionality of these features before feeding them into the probe.

Datasets

The authors used 7 publicly available question-answering (QA) datasets for their experiments:

  • NQ-Open
  • SQuADv2
  • TruthfulQA
  • HaluEvalQA
  • CoQA
  • TriviaQA
  • GSM8K

These datasets were used to generate LLM answers, which were then labeled as hallucinated or non-hallucinated using an "LLM-as-judge" approach, with GPT-4o-mini serving as the primary judge model.

Key Insights and Ideas

  • Attention maps as graphs: Viewing attention maps as graph structures provides a new lens for understanding LLM internal states and their relation to hallucinations.
  • Spectral properties of Laplacian: The eigenvalues of the Laplacian matrix derived from attention maps are powerful indicators of information flow disruptions, which are linked to hallucinations.
  • Robustness to temperature: LapEigvals shows improved performance at higher sampling temperatures, which typically lead to more hallucinations, suggesting its effectiveness in challenging scenarios.
  • All layers are better: Using features from all layers of an LLM consistently outperforms using features from a single layer, indicating that hallucination-related information is distributed across the model.

Key Results

  • LapEigvals achieved state-of-the-art performance among attention-based methods on 6 out of 7 tested datasets.
  • The method demonstrated superiority over previous attention-based methods like AttentionScore and AttnLogDet, with higher AUROC scores across various LLMs and datasets.
  • Ablation studies showed that LapEigvals is robust to the number of eigenvalues used and performs well even with a small number of top eigenvalues.
  • The method showed a smaller generalization gap compared to baselines, indicating better robustness across training and testing splits.
  • LapEigvals also demonstrated greater robustness to prompt variations compared to baselines.

Limitations and Future Work

  • Supervised method: LapEigvals requires labeled hallucinated and non-hallucinated examples, which can be noisy or lead to overfitting.
  • LLM architecture dependency: The method is not architecture-agnostic and may require adaptation for LLMs with different head and layer configurations.
  • Minimum length requirement: Attention maps of at least k tokens are needed, posing a limitation for very short sequences.
  • Closed LLMs: The method cannot be applied to closed-source LLMs that do not provide access to internal states.
  • Domain and task generalization: The current evaluation is limited to English and specific QA tasks, and applying it to untested domains carries risks.

The authors suggest that self-supervised learning could yield more robust and generalizable approaches. They also highlight the potential for further investigation into the connections between their findings and recent advancements in LLM research concerning information flow patterns.

Summary updated

BibTeX
@inproceedings{binkowski2025hallucination,
  author = {Jakub Binkowski and Denis Janiak and Albert Sawczyn and Bogdan Gabrys and Tomasz Jan Kajdanowicz},
  title = {{Hallucination Detection in LLMs Using Spectral Features of Attention Maps}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure