Contrastive Representational Decoding for Hallucination Detection
Cicy Kuriakose Agnes
Abstract
Large Language Models generate fluent and convincing responses, yet they frequently produce hallucinations, plausible but factually inaccurate responses. These pose a major barrier to their reliable use in high stake applications. A particularly difficult case is high confidence hallucination, where the generated answer is incorrect even though token probabilities or other output-level uncertainty measures indicate high confidence. This limits hallucination detectors based primarily on entropy, probability margins, or repeated sampling. The latent space of LLMs has recently been shown to be useful for detecting hallucinations. They offer signals for distinguishing between truthful and hallucinated answers. However, internal embeddings are optimized for next token prediction. We investigate whether modeling these internals and enhancing these signals provide a more reliable signal of factual correctness. The central hypothesis is that truthful and hallucinated responses form different distributed patterns across transformer layers, even when their final output confidence is similar. We propose a model, that uses the hidden states of the LLM across transformer depth and learns to decode whether a generated answer is grounded or hallucinated. Rather than depending on one manually selected layer, the detector learns a common representation from multiple layers. For each question, the target LLM first generates a response. Hidden states corresponding to generated answer tokens are pooled separately for every transformer layer, producing a sequence $h_1,\ldots,h_L$, where $h_l\in\mathbb{R}^{d}$ is the representation obtained from layer $l$. A learned projection head $f_{\theta}:\mathbb{R}^{d}\rightarrow\mathbb{R}^{p}$ maps these activations into a lower-dimensional normalized space, followed by normalization. The projection is trained using supervised contrastive learning. Collapsing layers with a contrastive loss amplifies correctness structure by removing layer noise and preserving latent consistency signals. Hidden-state views obtained from different layers of the same response are treated as positive views, while representations belonging to other examples in the batch act as negatives. Thus, instead of forcing a classifier to learn directly from raw activations, the projection stage first learns the structure shared by representations associated with each response. A lightweight MLP is then trained on the projected representation to predict whether the answer is truthful or hallucinated. Using this intermediate unsupervised model, the requirement of neat labelled data can be reduced. Preliminary experiments evaluate the approach on TruthfulQA and HaluEval using instruction-tuned models: Llama 3.1 8B, Qwen 2.5-7B, and Gemma-2 9B. Across the current experiments, representations from the middle-to-late portion of the network consistently contain strong hallucination-discriminative information. A next experiment is to explicitly control output uncertainty. We will construct ``confidently wrong'' settings in which truthful and hallucinated answers have closely matched entropy or token likelihood. Logit-based confidence detectors should then have little discriminative information by construction. If the representation-based detector continues to separate the two classes, this would provide stronger evidence that hallucination information is encoded internally beyond the final probability distribution. We will further test cross-dataset and cross-model transfer, determine whether the learned representation can operate with extremely small labeled datasets, and investigate whether changes in layer-wise representations can provide token-level warning before a hallucinated span is completed.
Chat is not available.
Successful Page Load