TL;DR
Traditional uncertainty quantification for Large Language Models (LLMs) is computationally expensive, requiring multiple sampled generations or slow auxiliary models. This paper introduces Semantic Token Clustering (STC), a method that extracts reliable uncertainty scores from a single generation by grouping vocabulary tokens into semantic clusters. STC matches the accuracy of state-of-the-art methods while slashing inference-time overhead by an average of 98%, making real-time uncertainty estimation practical.
What Problem Does This Paper Address?
LLMs are notoriously overconfident, often generating false or hallucinated statements with high apparent certainty. To safely deploy these models in high-stakes fields like law or medicine, we need reliable Uncertainty Quantification (UQ)—a way for the system to flag when it is guessing.
Existing unsupervised UQ methods fall into two main buckets, both of which have major drawbacks:
- Sampling-based methods: These generate multiple responses to the same prompt and use external Natural Language Inference (NLI) models to check if the answers mean the same thing. This is incredibly slow and expensive.
- Single-sample methods: These look at the token probabilities of a single generated response but still rely on external models to evaluate semantic consistency, introducing significant computational lag.
The core issue is that an LLM's probability mass is often fractured across semantically identical tokens (e.g., "TV" vs. "television"). If a model splits its confidence equally between these two options, a naive look at single-token probability makes the model appear highly uncertain, even though it is 100% sure of the underlying concept.
Methods
The authors propose Semantic Token Clustering (STC), a self-contained, two-stage framework that fixes the probability-splitting problem without needing extra generations or external models.
1. Pre-computation Stage (Offline)
Before inference even begins, the entire vocabulary of the LLM is clustered based on semantic similarity. The authors concatenate each token's input and output embeddings to create a unified semantic representation. They then apply an unsupervised clustering algorithm (Agglomerative Clustering) to group the vocabulary into 16,000 distinct semantic clusters (e.g., grouping "television", "TV", and "tv" together). Because this happens offline, it adds zero overhead to inference time.
2. Inference Stage (Online)
During text generation, STC calculates uncertainty at each decoding step by aggregating the probability mass of the entire semantic cluster rather than just the single chosen token.
To handle tokenization quirks (where words are split into arbitrary sub-tokens like "tele" and "vision"), they introduce Prefix Matching. This dynamically checks if alternative candidate tokens serve as a prefix for the rest of the generated sequence, ensuring surface-form consistency is maintained.
The final uncertainty score is computed as one minus the product of these aggregated cluster probabilities across all decoding steps.
Datasets
The method was evaluated across three popular open-domain question-answering benchmarks:
- TriviaQA (TQA)
- Natural Questions (NQ)
- WebQuestions (WQ)
The authors tested STC using a diverse suite of open-source models, including Llama-2-7B, Llama-3-8B, Mistral-7B, and the Qwen2.5 family (3B, 7B, and 14B). To ensure a robust evaluation of factual correctness, they used GPT-4.1 as an automated judge rather than relying on brittle string-matching metrics like ROUGE.
Key Insights and Ideas
- The Vocabulary Already Knows Semantics: Instead of generating 5 to 10 separate sentences to see what else the model might say, we can look directly at the next-token logit distribution. The alternative semantic paths are already encoded right there in the vocabulary embeddings.
- Complementary Mechanisms: Static embedding clustering and dynamic prefix matching work hand-in-hand. Embedding clustering captures abstract semantic relationships (synonyms), while prefix matching elegantly resolves tokenizer-induced artifacts.
- CPU-Friendly Inference: Because the heavy lifting (clustering) is shifted entirely to an offline pre-computation step, the online uncertainty calculation consists of simple lookups and additions. This allows the UQ step to run efficiently on standard CPUs without requiring expensive GPU acceleration.
Key Results
STC achieves an exceptional balance between predictive performance (measured via AUROC) and computational efficiency.
- State-of-the-Art Accuracy: As shown in the efficiency plots, STC (represented by the red star in the upper-left corners) consistently matches or outperforms complex sampling-based baselines like Semantic Entropy and single-sample methods like CCP.
- Massive Speedups: Compared to Claim Conditioned Probability (CCP)—the closest single-sample baseline—STC reduces inference-time overhead by an average of 98%.
- Ablation Validation: Removing either the embedding clustering or the prefix matching causes noticeable performance drops, proving that both components are vital to capturing the full semantic intent of the model.
Limitations and Future Work
- White-Box Restriction: STC requires direct access to token logits and embeddings. This means it cannot be used with closed-source, API-only models (like OpenAI's GPT-4 or Anthropic's Claude) where internal representations are hidden.
- The Polysemy Problem: The method currently relies on static token embeddings. Words with multiple meanings (e.g., "bank" as a riverbank vs. a financial institution) might be incorrectly clustered together regardless of context. The authors note that moving toward context-aware, contextualized token representations is a promising next step.
- Calibration: STC provides a relative uncertainty score but does not explicitly calibrate these scores into absolute probabilities of correctness. Implementing post-hoc calibration techniques remains an open area for future work.
Summary updated