Efficient Hallucination Detection for LLMs Using Uncertainty-Aware Attention Heads

Artem Vazhentsev, Lyudmila Rvanova, Gleb Kuzmin, Ekaterina Fadeeva, Ivan Lazichny, Alexander Panchenko, Maxim Panov, Mrinmaya Sachan, Preslav Nakov, Timothy Baldwin, Artem Shelmanov

TL;DR

The paper introduces RAUQ (Recurrent Attention-based Uncertainty Quantification), an unsupervised, plug-and-play method to detect large language model (LLM) hallucinations in real time. By discovering that specific "uncertainty-aware" attention heads sharply decrease their focus on the immediately preceding token when generating false information, RAUQ computes reliable sequence-level uncertainty in a single forward pass. It consistently outperforms state-of-the-art baselines across multiple tasks while adding less than 1% computational overhead.

What Problem Does This Paper Address?

Large Language Models are notoriously prone to "hallucinations"—generating text that sounds fluent but is factually incorrect. To deploy LLMs safely in high-stakes domains like medicine or law, we need reliable ways to measure the model's confidence in its own outputs, a field known as Uncertainty Quantification (UQ).

Current UQ methods suffer from a harsh trade-off:

  1. Sampling-based methods (e.g., Semantic Entropy) generate multiple alternative responses to gauge consistency. While accurate, they are computationally ruinous, often increasing inference latency by 400% to 800%.
  2. Supervised methods train auxiliary classifiers on internal model states. These yield good results in-domain but generalize poorly to new tasks or topics.

The authors of this paper look for a middle ground: a fast, unsupervised, and robust UQ method that leverages the internal mechanics of "white-box" LLMs (models where we have access to weights and activations) without requiring extra generation cycles.

Methods

RAUQ operates on a key mechanistic insight: when an LLM is uncertain or hallucinating, its internal attention patterns change. Specifically, the model shifts its focus away from the immediate local context (the previous token) and relies more heavily on generic global priors.

The RAUQ framework consists of three main steps performed during standard inference:

  1. Uncertainty-Aware Head Selection: Not all attention heads are informative. RAUQ automatically scans the intermediate layers of the LLM to find specific heads that maintain a high average attention weight to the immediately preceding token ($i-1$) across the generated sequence.
  2. Recurrent Confidence Propagation: LLM tokens are conditionally dependent. If a model generates an early token with low confidence, it might still be highly confident in subsequent tokens conditioned on that error. RAUQ uses a recurrent formula to propagate uncertainty step-by-step, fusing the current token's probability (or entropy) with the selected attention head's weight and the previous step's accumulated confidence.
  3. Sequence-Level Aggregation: To compute a final score for the entire response, RAUQ takes the mean logarithm of the token-level confidence scores for each layer, and then selects the maximum uncertainty score across the intermediate layers as an upper-bound estimate.

Datasets

The authors evaluated RAUQ across 12 diverse benchmarks spanning three core NLP tasks using 9 different LLMs (ranging from 360M to 70B parameters):

  • Question Answering (QA): TruthfulQA, SciQ, MMLU, TriviaQA, CoQA, MedQUAD, and GSM8k.
  • Text Summarization: CNN/DailyMail, SamSum, and XSum.
  • Machine Translation (MT): WMT19 (German–English) and WMT14 (French–English).

Key Insights and Ideas

  • The "Lookback" Signal: When an LLM generates a factually correct token, certain attention heads act as anchors, heavily attending to the token right before it. When a hallucination occurs, this local attention drops precipitously.
Figure 1. Attention weights in the 29th layer of Llama-3.1 8B from each generated token to its preceding token, given the prompt What is King Henry holding in the Portrait of Henry VIII?. The y axis specifies the generated tokens, and the x axis specifies the attention heads. Warmer colors indicate higher attention values. The output contains the factually incorrect token falcon (the correct answer is gloves and dagger). Notably, the 25th attention head stands out by consistently assigning relatively high attention to the preceding token. However, for the hallucinated token falcon, this attention drops sharply – potentially serving as a signal for hallucination detection.
  • Averaging Obscures the Truth: If you average attention weights across all heads in a layer, the hallucination signal gets completely washed out. You must dynamically isolate the specific "uncertainty-aware" heads.
  • The Power of Recurrence: Simply looking at a token's isolated probability isn't enough to catch hallucinations because models can be confidently wrong. Tracking how uncertainty flows and compounds across the sequence via a recurrent mechanism is crucial for sequence-level accuracy.

Key Results

  • State-of-the-Art Performance: Measured by the Prediction Rejection Ratio (PRR)—which evaluates how effectively a system can filter out bad responses—RAUQ consistently outperformed 15 unsupervised and sampling-based baselines. For instance, on a Gemma-2 9B model handling translation, RAUQ beat the next-best single-generation method by a wide margin (0.051 PRR improvement).
  • Negligible Overhead: Unlike sampling methods that require 6 to 10 seconds per prompt due to repeated generations, RAUQ processes instances in 1.17 seconds (compared to 1.16 seconds for standard inference). This translates to an overhead of just 0.3%, making it viable for real-time applications.
  • Strong Out-of-Domain Generalization: When compared against supervised UQ models, RAUQ maintained stable performance across different datasets, whereas supervised models suffered massive performance drops when tested out-of-domain.

Limitations and Future Work

  • White-Box Constraint: RAUQ requires direct access to the model's internal attention matrices and token logits. It cannot be directly applied to commercial "black-box" APIs like GPT-4 or Claude.
  • Hyperparameter Sensitivity: The algorithm relies on a single hyperparameter ($\alpha$) to balance the weight of token probabilities versus attention scores. While the authors found a stable default ($\alpha=0.2$ for base models, $\alpha=0.9$ for instruction-tuned models), performance can still be optimized further with dataset-specific tuning.
  • Future Directions: The authors propose adapting RAUQ to black-box settings in future work by using smaller, local white-box "proxy" LLMs to mirror and predict the uncertainty patterns of the larger black-box target model.

Summary updated

Abstract

While large language models (LLMs) have become highly capable, they remain prone to factual inaccuracies, commonly referred to as "hallucinations." Uncertainty quantification (UQ) offers a promising way to mitigate this issue, but most existing methods are computationally intensive and/or require supervision. In this work, we propose Recurrent Attention-based Uncertainty Quantification (RAUQ), an unsupervised and efficient framework for identifying hallucinations. The method leverages an observation about transformer attention behavior: when incorrect information is generated, certain "uncertainty-aware" attention heads tend to reduce their focus on preceding tokens. RAUQ automatically detects these attention heads and combines their activation patterns with token-level confidence measures in a recurrent scheme, producing a sequence-level uncertainty estimate in just a single forward pass. Through experiments on twelve datasets spanning question answering, summarization, and translation across nine different LLMs, we show that RAUQ consistently outperforms state-of-the-art UQ baselines. Importantly, it incurs minimal overhead, requiring less than 1\% additional computation. Since it requires neither labeled data nor extensive parameter tuning, RAUQ serves as a lightweight, plug-and-play solution for real-time hallucination detection in white-box LLMs.
BibTeX
@inproceedings{vazhentsev2026efficient,
  author = {Artem Vazhentsev and Lyudmila Rvanova and Gleb Kuzmin and Ekaterina Fadeeva and Ivan Lazichny and Alexander Panchenko and Maxim Panov and Mrinmaya Sachan and Preslav Nakov and Timothy Baldwin and Artem Shelmanov},
  title = {{Efficient Hallucination Detection for LLMs Using Uncertainty-Aware Attention Heads}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=nddfPlfS09},
}
Figure