Unsupervised Real-Time Hallucination Detection based on the Internal States of Large Language Models

Weihang Su, Changyue Wang, Qingyao Ai, Yiran Hu, Zhijing Wu, Yujia Zhou, Yiqun Liu

Introduction

Large Language Models (LLMs) frequently "hallucinate," producing factually incorrect information that appears plausible. Existing detection methods typically rely on post-processing, treating the LLM as a black box and verifying outputs against external sources or through self-consistency checks. These approaches are often computationally expensive and introduce significant latency. At ACL 2024, researchers from Tsinghua University introduced MIND (unsupervised Modeling of INternal states for hallucination Detection), a framework designed to identify hallucinations in real-time by analyzing the model's internal hidden states.

The Challenge of Real-Time Detection

Most current hallucination detection techniques suffer from two primary drawbacks:

  1. High Latency and Cost: Verifying a response often requires additional LLM calls, which can be slower and more expensive than the initial generation.
  2. Internal Signal Neglect: Post-hoc methods ignore the internal representations of the model during the generation process, missing potential signals of uncertainty or "confusion" embedded within the neural layers.

MIND addresses these issues by providing a reference-free, real-time solution that flags hallucinations as they occur, without requiring external ground-truth databases during inference.

The MIND Framework

The MIND framework operates through two key components: unsupervised data generation and a lightweight classifier.

Unsupervised Data Generation

To train the detector without costly human labeling, the researchers utilized Wikipedia. They truncated sentences before named entities and prompted the LLM to complete them. If the LLM's output matched the original Wikipedia text, it was labeled a "non-hallucination"; otherwise, it was marked as a "hallucination." This process allows for the creation of large-scale training sets with pseudo-labels.

Overview of the MIND framework: Unsupervised data generation and hallucination classification based on internal states.

The MIND Classifier

Instead of analyzing the generated text, MIND focuses on contextualized embeddings—the mathematical vectors representing tokens within the model. The researchers found that these embeddings exhibit distinct patterns when the model is hallucinating. A simple 4-layer Multilayer Perceptron (MLP) is trained to recognize these patterns. Because this classifier is lightweight and uses data already computed during inference, the overhead is minimal.

Key Insights: The Predictive Power of Internal States

A significant finding of the study is that the internal state of the very last token in the very last layer is highly predictive of a hallucination. This suggests that the model's "final thought" before outputting a word contains a detectable signal of its factual reliability.

Ablation study showing the accuracy (Acc) of hallucination detection using different layers and embedding combinations.

As shown in the table above, using the embeddings from the last layer consistently yields high accuracy, supporting the hypothesis that LLMs possess an internal "awareness" of their own uncertainty when transitioning from factual retrieval to speculative generation.

Evaluation and Results

The researchers evaluated MIND using a new benchmark, HELM (Hallucination detection Evaluation for multiple LLMs), which includes outputs from six diverse models (e.g., LLaMA-2, Falcon-40B) manually verified by humans.

  • Performance: MIND outperformed state-of-the-art (SOTA) methods like SelfCheckGPT in terms of Area Under the Curve (AUC) across most models.
  • Efficiency: MIND is remarkably efficient. While SelfCheckGPT-NLI takes approximately 15 seconds to verify a response, MIND requires only 0.05 seconds—roughly 300x faster.
  • Generalization: The unsupervised approach proved successful, demonstrating that structured knowledge from Wikipedia can effectively train robust hallucination detectors.

Conclusion and Future Directions

MIND represents a significant step toward efficient, real-time hallucination monitoring. By looking "inside" the LLM, it captures signals that text-based methods miss. Future work may involve combining internal state analysis with linguistic features or using MIND to trigger real-time mitigation strategies, such as Retrieval-Augmented Generation (RAG), when the model's internal states indicate high uncertainty.

Reference: Su, W., et al. (2024). Unsupervised Real-Time Hallucination Detection based on the Internal States of Large Language Models. Proceedings of ACL 2024.

Summary updated

BibTeX
@inproceedings{su2024unsupervised,
  author = {Weihang Su and Changyue Wang and Qingyao Ai and Yiran Hu and Zhijing Wu and Yujia Zhou and Yiqun Liu},
  title = {{Unsupervised Real-Time Hallucination Detection based on the Internal States of Large Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.854},
}
Figure