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

TL;DR

When deploying Large Language Models (LLMs) via restricted APIs, detecting hallucinations and data contamination usually relies on simple, handcrafted heuristics over the probabilities of the generated tokens. This paper introduces LOS-Net, a lightweight model that learns directly from the full next-token probability distributions (the "LLM Output Signature"), achieving state-of-the-art detection accuracy with near-zero latency.

What Problem Does This Paper Address?

To safely deploy LLMs, we need to know when they are fabricating information (hallucinating) or leaking copyrighted training data (contamination). Doing this in a "gray-box" setting—where you only have API access to output probabilities rather than internal hidden states—is incredibly challenging.

Current gray-box approaches typically look only at the probabilities of the actual tokens generated, a metric the authors call Actual Token Probabilities (ATP). However, this discards a massive amount of information. For example, if a model predicts a token with a 50% probability, ATP treats it the same whether the remaining 50% is concentrated entirely on one alternative token (low uncertainty) or spread thinly across thousands of tokens (high uncertainty). This paper addresses this information loss by leveraging the full next-token probability distribution.

Methods

The authors introduce a unified data representation called the LLM Output Signature (LOS), which combines the standard ATP with the Token Distribution Sequence (TDS)—the complete next-token probability matrix across the entire vocabulary.

Figure 1: Left: The LLM processes the input “What does the cat chase?” and generates the output “A big mouse”. Right: The corresponding query/response Token Distribution Sequences (TDS) and Actual Token Probabilities (ATP), together constituting the LLM Output Signature (LOS). We propose to detect instances of hallucinations and data contamination by learning directly over this unified data representation, beyond task specific heuristics operating on partial information thereof.

To make this high-dimensional data practical to work with, they implement a few clever tricks:

  1. Top-K Filtering: They sort each row of the distribution matrix and retain only the top $K$ probabilities, drastically reducing computational complexity and standardizing the input across different model vocabularies.
  2. Rank Encoding: They explicitly encode the rank of the actual token within the sorted distribution to capture the "gap" between what the model generated and what it most expected to generate.
  3. LOS-Net Architecture: They feed this processed signature into a lightweight (~1M parameters) encoder-only Transformer.

Crucially, the authors provide a theoretical proof showing that LOS-Net can mathematically approximate a broad class of "Gated Scoring Functions," meaning it unifies and generalizes many popular existing heuristic methods (like Min-K%).

Datasets

The approach was evaluated across two distinct tasks using several benchmarks:

  • Hallucination Detection (HD): Evaluated on HotpotQA (multi-hop question answering without context), IMDB (movie review sentiment classification), and Movies (factual accuracy regarding actor roles).
  • Data Contamination Detection (DCD): Evaluated on WikiMIA-32/64 (Wikipedia snippets categorized by creation timestamp) and BookMIA (excerpts from books used to simulate real-world copyright infringement auditing).

Key Insights and Ideas

  • Uncertainty is in the Shape: The shape of the next-token probability distribution contains vital clues about model confidence that single-token probabilities completely mask.
  • Top-K is More Than Enough: Surprisingly, taking just the top $K=10$ tokens captures over 99% of the total probability mass. This means LOS-Net can be effectively deployed even on highly restricted commercial APIs (like OpenAI's) that only expose a small number of top logprobs.
  • Strong Cross-Model Generalization: The patterns of uncertainty captured by LOS-Net transfer remarkably well across different model sizes and architectures without requiring heavy retraining.

Key Results

  • Massive Accuracy Gains: LOS-Net consistently outperformed existing gray-box baselines. On the IMDB hallucination dataset, it boosted AUC by approximately 31 points for Mistral-7b and 17 points for Llama3-8b compared to the best traditional baselines.
  • Beating White-Box Probes: In several setups, the gray-box LOS-Net actually outperformed "Activation Probes"—methods that require full, restrictive white-box access to the model's internal hidden states.
  • Blazing Fast Latency: LOS-Net features an incredibly low inference latency of $\sim 10^{-5}$ seconds per instance. This is five orders of magnitude faster than popular uncertainty-estimation methods like Semantic Entropy (which requires generating multiple alternative responses and takes ~7 seconds per sample), making LOS-Net highly viable for real-time, online error detection.
Cross-LLM transfer performance on the IMDB dataset

Limitations and Future Work

The primary limitation of LOS-Net is that it is a supervised learning approach. Unlike zero-shot heuristics that work out-of-the-box, LOS-Net requires a labeled dataset of hallucinations or contaminated text to train its transformer backbone.

For future work, the authors suggest extending the LLM Output Signature to incorporate "exact-token" flags or adapting the framework to handle multi-prompting scenarios to capture even richer behavioral signatures from the models.

Summary updated

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. Full code is available at https://github.com/BarSGuy/Beyond-next-token-probabilities.
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