Token-Level Density-Based Uncertainty Quantification Methods for Eliciting Truthfulness of Large Language Models

Artem Vazhentsev, Lyudmila Rvanova, Ivan Lazichny, Alexander Panchenko, Maxim Panov, Timothy Baldwin, Artem Shelmanov

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.

Figure 1: Overview of the token-level density-based uncertainty quantification pipeline, showing the extraction of token embeddings across layers and the application of Mahalanobis Distance and PCA.

The process involves several key steps:

  1. 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.
  2. 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.
  3. 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.
  4. 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.

Figure 3: Layer-wise Prediction Rejection Ratio (PRR) across various datasets and models, highlighting that middle layers often provide superior signals for uncertainty detection.

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

BibTeX
@inproceedings{vazhentsev2025token,
  author = {Artem Vazhentsev and Lyudmila Rvanova and Ivan Lazichny and Alexander Panchenko and Maxim Panov and Timothy Baldwin and Artem Shelmanov},
  title = {{Token-Level Density-Based Uncertainty Quantification Methods for Eliciting Truthfulness of Large Language Models}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-long.113},
}
Figure