InternalInspector I2: Robust Confidence Estimation in LLMs through Internal States.

Mohammad Beigi, Ying Shen, Runing Yang, Zihao Lin, Qifan Wang, Ankith Mohan, Jianfeng He, Ming Jin, Chang-Tien Lu, Lifu Huang · DOI · OpenReview

Abstract

Large Language Models (LLMs) frequently exhibit high confidence in erroneous outputs, a phenomenon known as being "confidentially wrong." Traditional methods for estimating model confidence—such as analyzing output logits or self-evaluation—often fail to capture the underlying reliability of a generation. We present InternalInspector ($I^2$), a supervised framework that probes the internal neural dynamics of LLMs to estimate prediction confidence. By extracting and analyzing activation, attention, and feed-forward states across all layers, $I^2$ leverages the "internal knowledge advantage" to distinguish between factual reasoning and hallucinations. Our experiments on LLaMA-2-7B across diverse NLP tasks demonstrate that $I^2$ significantly improves calibration and accuracy, outperforming existing black-box and shallow probing baselines.

Introduction

The rapid deployment of Large Language Models (LLMs) in high-stakes domains is often hindered by the challenge of "calibration." Ideally, a model’s predicted probability of an answer being correct should align with its actual accuracy. However, current LLMs are notorious for hallucinating facts with high-confidence scores, making them unreliable without external verification.

Existing approaches to confidence estimation generally fall into two categories: black-box methods and shallow probing. Black-box methods involve prompting the model for self-evaluation or calculating entropy from output probabilities. These are often computationally expensive or fail to reflect the model's true internal state. Shallow probing methods look at the final hidden state but ignore the complex processing that occurs throughout the model's depth. InternalInspector ($I^2$) addresses these gaps by treating the model's internal states as a rich source of diagnostic information.

The Internal Knowledge Advantage

The theoretical foundation of $I^2$ rests on the "Internal Knowledge Advantage." Using mutual information theory, the authors demonstrate that the internal states ($\Theta$) of a transformer contain more information about the ground truth than the final text output ($Y$) alone. In essence, the model often "knows" it is guessing or hallucinating before the final token is even generated. By inspecting the interplay between different components of the transformer architecture, we can capture the latent signals of uncertainty that are lost by the time the model produces a final logit distribution.

The InternalInspector ($I^2$) Framework

InternalInspector introduces a structured, supervised approach to monitor the decision-making process within an LLM.

1. Comprehensive State Extraction

For any given input, $I^2$ extracts three distinct types of internal states from every layer of the model (e.g., LLaMA-2-7B) at the final token position:

  • Activation States: The general hidden representations.
  • Attention States: Capturing contextual relationships.
  • Feed-Forward (FFN) States: Representing factual knowledge retrieval.

2. Feature Learning and Architecture

These states are stacked into a 3D tensor ($Layers \times Dimensions \times 3$), creating a "neural image" of the model's reasoning process. This tensor is processed by an encoder—either a ResNet18-based CNN or a small Transformer—to identify patterns associated with correct versus incorrect reasoning.

3. Supervised Contrastive Learning

A key technical innovation of $I^2$ is the use of a joint objective function. The framework utilizes Supervised Contrastive Learning to map the internal states of correct predictions close together in a latent space while pushing states associated with hallucinations far apart. This is combined with a standard cross-entropy loss to maximize the inspector's ability to classify the truthfulness of a generation.

Experimental Results

Performance Across Benchmarks

InternalInspector was evaluated using LLaMA-2-7B across several task categories, including Factual QA (TriviaQA, MMLU), Commonsense Reasoning (CommonsenseQA, BoolQA), and Reading Comprehension (SQuAD, OpenBookQA).

  • Accuracy Improvements: $I^2$ achieved up to a 20.4% improvement in aligning confidence scores with actual correctness compared to the strongest baselines.
  • Calibration: The framework significantly reduced the Expected Calibration Error (ECE) by as much as 8.9% on factual tasks, ensuring that the model's confidence scores are more representative of its actual performance.
  • Hallucination Detection: On the HaluEval benchmark, $I^2$ achieved 69.1% accuracy, outperforming specialized internal-state baselines like CSS and SAPLMA.

Layer-Wise and Component Analysis

The research yielded critical insights into the internal mechanics of LLMs:

  • The "Goldilocks" Layers: The most informative signals for confidence estimation reside in the middle layers (13-17). Shallow layers are primarily concerned with raw input processing, while the deepest layers are overly specialized for token prediction. The middle layers capture the core semantic reasoning.
  • Functional Specialization: Ablation studies confirmed that FFN states are the most critical for factual recall, supporting the theory that FFNs act as key-value memories. Conversely, Attention states are more vital for reading comprehension tasks where context is paramount.

Limitations and Future Work

While highly effective, InternalInspector requires access to the internal weights and states of the model, making it inapplicable to closed-source APIs like GPT-4. Additionally, extracting high-dimensional states across all layers during training introduces significant computational overhead. Future research may focus on more specialized architectures for the inspector model to better capture the nuanced "neural signatures" of hallucinations and extending the framework to even larger model scales.

Conclusion

InternalInspector ($I^2$) demonstrates that the path to more reliable LLMs lies within their internal dynamics. By moving beyond surface-level outputs and probing the multi-layered reasoning process of the transformer, $I^2$ provides a robust, well-calibrated mechanism for estimating confidence and detecting hallucinations in open-weight models.

Summary updated

BibTeX
@inproceedings{beigi2024internalinspector,
  author = {Mohammad Beigi and Ying Shen and Runing Yang and Zihao Lin and Qifan Wang and Ankith Mohan and Jianfeng He and Ming Jin and Chang-Tien Lu and Lifu Huang},
  title = {{InternalInspector I2: Robust Confidence Estimation in LLMs through Internal States.}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.751},
}
Figure