The Geometry of Truth: Layer-wise Semantic Dynamics for Hallucination Detection in Large Language Models
Amir Hameed Mir
TL;DR
This paper introduces Layer-wise Semantic Dynamics (LSD), a geometry-based framework that detects hallucinations in large language models by analyzing the evolution of hidden-state semantics across transformer layers. LSD aligns layerwise representations with ground-truth embeddings through margin-based contrastive learning and computes trajectory-based metrics (alignment, velocity, acceleration) to distinguish factually correct outputs from hallucinations. Empirical results on TruthfulQA and synthetic data show strong separability (F1 ≈ 0.92, AUROC ≈ 0.96, clustering ≈ 0.89) with a single forward pass, outperforming sampling-based baselines while enabling real-time monitoring and interpretability. The work provides both practical detection capabilities and deeper insights into how factual grounding manifests as convergent trajectories in semantic space, offering a principled path toward robust, scalable truth verification in LLMs.
Abstract
Large Language Models (LLMs) often produce fluent yet factually incorrect statements-a phenomenon known as hallucination-posing serious risks in high-stakes domains. We present Layer-wise Semantic Dynamics (LSD), a geometric framework for hallucination detection that analyzes the evolution of hidden-state semantics across transformer layers. Unlike prior methods that rely on multiple sampling passes or external verification sources, LSD operates intrinsically within the model's representational space. Using margin-based contrastive learning, LSD aligns hidden activations with ground-truth embeddings derived from a factual encoder, revealing a distinct separation in semantic trajectories: factual responses preserve stable alignment, while hallucinations exhibit pronounced semantic drift across depth. Evaluated on the TruthfulQA and synthetic factual-hallucination datasets, LSD achieves an F1-score of 0.92, AUROC of 0.96, and clustering accuracy of 0.89, outperforming SelfCheckGPT and Semantic Entropy baselines while requiring only a single forward pass. This efficiency yields a 5-20x speedup over sampling-based methods without sacrificing precision or interpretability. LSD offers a scalable, model-agnostic mechanism for real-time hallucination monitoring and provides new insights into the geometry of factual consistency within large language models.
