NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Hallucination Detection: A Probabilistic Framework Using Embeddings Distance Analysis

Emanuele Ricco, Lorenzo Cima, Roberto Di PietroarXiv 2025

TL;DR

This paper introduces a novel, mathematically grounded method for detecting hallucinations in Large Language Models (LLMs) by analyzing structural differences in their generated text embeddings. The authors demonstrate that hallucinated content exhibits distinct embedding distance patterns compared to factual content, leading to a new detection tool with promising accuracy.

What Problem Does This Paper Address?

Large Language Models (LLMs) are prone to "hallucinations" – generating plausible-sounding but factually incorrect, misleading, or fabricated information. This is a major roadblock to their reliable deployment in real-world applications. Existing detection methods often rely on heuristics or require human oversight. This paper tackles the critical need for automated, robust hallucination detection by exploring whether hallucinated text has inherent structural differences that can be mathematically identified.

Methods

The core of the proposed methodology lies in analyzing the embedding space of text. The authors hypothesize that hallucinated responses, due to their factual inaccuracies, will have different structural properties in this high-dimensional space compared to genuine responses.

  1. Embedding Generation: They extract keywords from both hallucinated and non-hallucinated responses and convert these keywords into numerical embeddings using BERT. Each response is thus represented by multiple embeddings.
  2. Minkowski Distance Analysis: The key innovation is the use of Minkowski distances to measure the "intra-distances" (distances between embeddings within the same category – hallucinated or non-hallucinated) and "inter-distances" (distances between embeddings of different categories). Minkowski distances are a generalization of Euclidean distance, allowing for different norms (p-values) to capture various aspects of distance.
  3. Probabilistic Framework: They then build a probabilistic framework. By analyzing the distributions of these embedding distances, they observe statistically significant differences between hallucinated and non-hallucinated responses. This difference is found to be "scale-free," meaning it holds across different distance norms, numbers of keywords, and response sets.
  4. Detection Algorithm: This observed structural difference is leveraged to build a classifier. The algorithm calculates log-likelihoods of test response embeddings against pre-computed distributions of hallucinated and non-hallucinated training embeddings, ultimately assigning a class (hallucinated or not).

Datasets

The authors generated their own dataset for this research.

  • Custom Dataset: They used two LLMs, Llama2 (with a September 2022 cutoff) and Llama3 (with a December 2023 cutoff), to generate responses to 64 questions covering events between September 2022 and September 2023. This setup was designed so that Llama2 would likely hallucinate responses about events after its knowledge cutoff, while Llama3 would have the necessary information. The dataset includes varying numbers of responses per question (r) and keywords per response (n).

Key Insights and Ideas

  • Structural Differences in Embeddings: The most significant insight is that hallucinated text, when represented as embeddings, exhibits a demonstrably different structure compared to factual text. This isn't just about semantic meaning but about the geometric arrangement of these representations.
  • Minkowski Distances as a Revealing Metric: The choice of Minkowski distances, particularly with fractional norms (p < 1), proved effective in highlighting these subtle structural differences, amplifying the divergence between the two response types.
  • Scale-Free Phenomenon: The observed differences are not dependent on specific experimental settings (like the number of keywords or responses) or the chosen distance norm. This suggests a fundamental property of LLM hallucinations rather than an artifact of the experimental setup.
  • Probabilistic Approach is Key: Moving beyond heuristic rules, the paper establishes a mathematically rigorous, probabilistic framework for hallucination detection, offering a more principled approach.

Key Results

  • Statistically Significant Differences: The study found statistically significant differences in the embedding distance distributions between hallucinated and non-hallucinated responses across various configurations of keywords, response counts, and distance norms.
  • Detection Accuracy: The developed detection tool achieved an accuracy of 66% for a specific configuration (r=8, n=1, p=0.5), which is competitive with existing state-of-the-art methods.
  • Performance Trends: Accuracy generally improved with an increasing number of responses (r), while the F1 score for hallucinated responses showed a more complex relationship, sometimes decreasing with more responses, suggesting that simpler models (fewer keywords) might be more effective for F1. Fractional distance norms (p=0.5) generally yielded higher accuracy.

Limitations and Future Work

  • Dataset Generation: The dataset was entirely generated by the authors using Llama2 and Llama3. While designed to induce hallucinations, there's a possibility of some Llama3 responses being misclassified as genuine. Future work could involve using existing, more diverse hallucination detection benchmarks.
  • Computational Complexity: The brute-force calculation of distances in the training phase has a complexity of O(qr²), which could be a bottleneck for very large datasets. Future research could focus on reducing this complexity.
  • KDE Limitations: The reliance on Kernel Density Estimation (KDE) for probability density estimation is noted. Exploring alternative methods for detecting and classifying hallucinations, potentially with generative models, is suggested.
  • Model Size: The experiments were conducted on smaller LLMs (7B and 8B parameters). The authors plan to investigate if their findings hold for larger models, expecting improved detection performance with increased model size.

Summary updated

BibTeX
@misc{ricco2025hallucination,
  author = {Emanuele Ricco and Lorenzo Cima and Roberto Di Pietro},
  title = {{Hallucination Detection: A Probabilistic Framework Using Embeddings Distance Analysis}},
  year = {2025},
  url = {https://openreview.net/forum?id=BTc6fIjkSK},
}
Figure