Introduction
Large Language Models (LLMs) frequently exhibit overconfidence, generating factually incorrect "hallucinations" with the same authoritative tone as verified truths. This lack of reliable confidence estimation poses significant risks in high-stakes applications. Traditional approaches to confidence estimation generally rely on logit-based probabilities, self-evaluation (asking the model if it is sure), or consistency-based methods (checking agreement across multiple outputs). However, these methods often fail because logits only reflect the final output step, and self-evaluation can lead to circular reasoning. This paper introduces InternalInspector (I²), a framework that shifts the focus from final outputs to the model's internal dynamics—the complex interplay of neurons across all layers—to detect hallucinations.
Methodology
InternalInspector (I²) treats the internal states of an LLM as a diagnostic signal. Rather than relying solely on the final hidden state, I² extracts three distinct types of data from every layer of the model:
- Activation States ($h$): The general output of each layer.
- Attention States ($a$): Representations of how the model weights different parts of the input.
- Feed-Forward (FFN) States ($m$): The components responsible for knowledge retrieval within the transformer block.
These states are aggregated into a 3D tensor (Layers × Features × State Types). The framework utilizes Supervised Contrastive Learning to train a secondary classifier (either CNN or Transformer-based). This classifier learns to distinguish the "fingerprint" of a correct thought process from an incorrect one by comparing anchor embeddings of correct answers with positive (other correct) and negative (incorrect) examples.
Experimental Evaluation
The framework was evaluated using popular open-source models, including LLaMA-2-7B, Mistral 7B, and GPT2-XL, across a diverse suite of benchmarks:
- Factual QA: TriviaQA and MMLU.
- Commonsense Reasoning: CommonsenseQA and BoolQA.
- Reading Comprehension: SQuAD and OpenBookQA.
- Hallucination Detection: HaluEval.
Results and Analysis
InternalInspector consistently outperformed existing baselines, such as SAPLMA and CSS, across all tested domains. As shown in the results table, I² achieved significant gains in both accuracy (ACC) and Expected Calibration Error (ECE).
Key Findings
- Accuracy and Calibration: On factual QA tasks, I² achieved up to a 20.4% improvement in aligning confidence scores with actual correctness while significantly reducing ECE. This indicates that when the model reports high confidence, it is much more likely to be correct.
- The "Internal Knowledge Advantage": Theoretical analysis suggests internal states contain more information about the "oracle" truth than the final text output. The model often "knows" it is wrong internally before it generates the incorrect word.
- State Specialization: Different states serve different functions; FFN states are most influential for factual recall, while attention states are critical for reading comprehension.
- Layer Importance: States from the middle layers (e.g., layers 13-17 in a 32-layer model) were found to be more predictive of correctness than those from the earliest or latest layers.
- Hallucination Detection: On the HaluEval benchmark, I² reached an accuracy of 69.1%, significantly outperforming the next best internal-state method (CSS at 56.2%).
Conclusion and Limitations
InternalInspector provides a robust, state-based approach to confidence estimation that effectively identifies hallucinations by looking "under the hood" of LLMs. While highly effective, the primary limitation is its requirement for access to internal weights and activations, making it currently inapplicable to proprietary "black box" models accessed via API. Future work will explore more complex encoder architectures and the scaling behavior of these internal dynamics in larger models.
Summary updated