Abstract
Large Language Models (LLMs) frequently generate factually incorrect but confident-sounding "hallucinations." Reliable Uncertainty Quantification (UQ) is essential for deploying LLMs in high-stakes domains. This paper introduces a novel token-level density-based UQ method that utilizes Mahalanobis Distance (MD) across internal model layers. By analyzing the "density" of individual tokens rather than entire sequences, the proposed approach significantly improves truthfulness detection. Experimental results across 11 diverse datasets demonstrate that this method achieves state-of-the-art performance with only a 5-8% computational overhead, offering a highly efficient alternative to expensive sampling-based techniques.
Introduction
The propensity of Large Language Models to hallucinate remains a significant barrier to their adoption in professional fields like medicine or law. Current UQ methods generally fall into two categories: sampling-based and density-based. Sampling-based methods, while effective, are computationally prohibitive as they require multiple model passes. Traditional density-based methods, which analyze internal embeddings, have historically struggled with generative tasks because they operate at the sequence level, often missing the specific tokens where a hallucination originates.
This research addresses these limitations by proposing a token-level density-based UQ framework. By adapting the Mahalanobis Distance to work at the individual token level across multiple transformer layers, the authors bridge the gap between efficiency and accuracy in uncertainty detection.
Methodology
The core of the proposed approach is Token-Level Density-Based UQ. Unlike previous methods that aggregate embeddings for a whole sentence, this method analyzes the internal state of every token as it is generated.
The process involves several key steps:
- Mahalanobis Distance (MD): MD measures how far a token's embedding is from the distribution of high-quality, truthful training data. Tokens falling into low-density regions of the embedding space are flagged as potentially untruthful.
- Multi-Layer Integration: Rather than relying solely on the final layer, the method extracts features from all layers of the decoder. These high-dimensional features are reduced using Principal Component Analysis (PCA) and processed by a linear regressor.
- Supervised Refinement (SATMD/SATRMD): The authors introduce supervised variants where a small regressor is trained to map distance scores to correctness metrics like ROUGE-L or Accuracy.
- Relative Mahalanobis Distance (RMD): To distinguish between general predictive difficulty and actual hallucinations, RMD compares the distance from truthful data against a "background" distribution (e.g., the C4 dataset).
Experimental Evaluation
The method was evaluated using Llama 8b v3.1 and Gemma 9b v2 models across 11 datasets spanning summarization (XSum, SamSum, CNN), long-form QA (PubMedQA, MedQUAD, TruthfulQA, GSM8k), and reading comprehension (CoQA, SciQ, TriviaQA, MMLU).
Key Insights
A critical finding is that the "middle layers" of a transformer often contain the most predictive signal for truthfulness. Figure 3 illustrates how the Prediction Rejection Ratio (PRR) varies across layers for different methods.
The researchers also noted that their method is exceptionally efficient. While sampling-based methods like Semantic Entropy require 5-10x the compute, this token-level approach adds only 5.3% to 7.6% overhead to a single generation pass.
Results
The proposed SATRMD+MSP (Supervised Average Token Relative Mahalanobis Distance combined with Maximum Sequence Probability) consistently outperformed standard baselines. Notably, the method demonstrated strong Out-of-Domain (OOD) generalization. A model trained on summarization tasks could effectively detect uncertainty in medical multiple-choice questions, suggesting that the internal representation of "uncertainty" is consistent across different task types.
Conclusion and Future Work
Token-level density-based UQ provides a scalable and accurate solution for monitoring LLM truthfulness. While the current implementation requires a small amount of supervised data for optimal performance, its efficiency makes it a viable candidate for real-time applications. Future research will explore the applicability of these methods to larger "frontier" models and investigate pre-token features that might predict errors before they are fully generated.
Summary updated