Beyond Next Token Probabilities: Learnable, Fast Detection of Hallucinations and Data Contamination on LLM Output Distributions

Guy Bar-Shalom, Fabrizio Frasca, Derek Lim, Yoav Gelberg, Yftah Ziser, Ran El‐Yaniv, Gal Chechik, Haggai Maron · DOI

Abstract

The automated detection of hallucinations and training data contamination is pivotal to the safe deployment of Large Language Models (LLMs). These tasks are particularly challenging in settings where no access to model internals is available. Current approaches in this setup typically leverage only the probabilities of actual tokens in the text, relying on simple task-specific heuristics. Crucially, they overlook the information contained in the full sequence of next-token probability distributions. We propose to go beyond hand-crafted decision rules by learning directly from the complete observable output of LLMs -- consisting not only of next-token probabilities, but also the full sequence of next-token distributions. We refer to this as the LLM Output Signature (LOS), and treat it as a reference data type for detecting hallucinations and data contamination. To that end, we introduce LOS-Net, a lightweight attention-based architecture trained on an efficient encoding of the LOS, which can provably approximate a broad class of existing techniques for both tasks. Empirically, LOS-Net achieves superior performance across diverse benchmarks and LLMs, while maintaining extremely low detection latency. Furthermore, it demonstrates promising transfer capabilities across datasets and LLMs.

Introduction

Ensuring the reliability of Large Language Models (LLMs) requires robust mechanisms to detect when a model is "hallucinating" (generating factually incorrect information) or "leaking" (reproducing training data verbatim). Most existing detection methods operate under "gray-box" constraints, where only the model's output probabilities are accessible. However, these methods typically rely on Actual Token Probabilities (ATP)—the probability assigned to the specific token generated—and use hand-crafted heuristics like mean or minimum probability.

This paper argues that such approaches ignore a significant source of information: the Token Distribution Sequence (TDS). By analyzing the entire probability distribution of all possible next tokens, we can gain deeper insights into the model's internal confidence and uncertainty.

The LLM Output Signature (LOS)

The core contribution of this work is the definition of the LLM Output Signature (LOS), which integrates both the ATP and the TDS. While ATP provides a single scalar per token, the TDS captures the "shape" of the model's prediction space. For instance, a high-entropy distribution where probability is spread across many tokens suggests model confusion, a common precursor to hallucinations.

The LLM Output Signature (LOS) combines the sequence of chosen tokens (ATP) with the full distribution of possible tokens (TDS).

LOS-Net: A Learnable Detection Architecture

To leverage the high-dimensional data within the LOS, the authors propose LOS-Net, a lightweight, attention-based model designed for efficient detection.

Architecture and Preprocessing

  1. Top-K Filtering: To handle massive vocabularies, LOS-Net considers only the top $K$ probabilities (e.g., $K=1000$). Research indicates that even $K=10$ captures the vast majority of relevant probability mass.
  2. Rank Encoding: A learnable encoding identifies the rank of the actual generated token within the sorted distribution, providing context for the ATP within the broader TDS.
  3. Transformer Encoder: A small Transformer (approx. 1M parameters) processes the sequence. Its small size ensures detection latency remains negligible ($10^{-5}$s).

Theoretically, LOS-Net is a universal approximator for a wide range of existing heuristics, such as Min-K%, meaning it can learn to replicate and exceed the performance of traditional hand-crafted rules.

Experimental Results

LOS-Net was evaluated on Hallucination Detection (HD) using datasets like HotpotQA and IMDB, and Data Contamination Detection (DCD) using WikiMIA and BookMIA. Testing spanned several models, including Mistral-7b and Llama3-8b.

LOS-Net performance compared to various heuristics and white-box probes across multiple datasets and models.

Performance and Efficiency

As shown in the results, LOS-Net consistently outperforms gray-box baselines. In the IMDB dataset with Mistral-7b, LOS-Net achieved an AUC improvement of over 30 points compared to standard probability-based heuristics. Notably, it often matches or exceeds the performance of "white-box" activation probes that require access to internal model states.

Beyond accuracy, LOS-Net is exceptionally fast. While methods like Semantic Entropy require multiple generations and comparisons (taking seconds), LOS-Net operates in microseconds ($10^{-5}$s). Furthermore, the model exhibits strong cross-model generalization, successfully detecting contamination in models it was not trained on.

Conclusion

By moving beyond simple next-token probabilities to the full LLM Output Signature, LOS-Net provides a powerful, fast, and learnable framework for AI safety. It demonstrates that the "shape" of uncertainty in LLM outputs is a rich signal for detecting both hallucinations and data leakage, offering a scalable solution for monitoring models in production environments.

Full code is available at https://github.com/BarSGuy/Beyond-next-token-probabilities.

Summary updated

BibTeX
@inproceedings{barshalom2026beyond,
  author = {Guy Bar-Shalom and Fabrizio Frasca and Derek Lim and Yoav Gelberg and Yftah Ziser and Ran El‐Yaniv and Gal Chechik and Haggai Maron},
  title = {{Beyond Next Token Probabilities: Learnable, Fast Detection of Hallucinations and Data Contamination on LLM Output Distributions}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2026},
  doi = {10.1609/aaai.v40i36.40254},
}
Figure