Paper: 2603.20161 Authors: Qi Cao, Andrew Gambardella, Takeshi Kojima, Yutaka Matsuo, Yusuke Iwasawa Institution: The University of Tokyo Categories: cs.CL
Abstract
Large language models often generate plausible-sounding but incorrect responses with high confidence, making it critical to quantify their uncertainty. Existing methods rely on repeated sampling or auxiliary models, introducing substantial computational overhead. This paper proposes Semantic Token Clustering (STC), an efficient uncertainty quantification method that requires only a single generation and no external models, achieving performance comparable to state-of-the-art while dramatically reducing computational cost.
The Problem: Overconfident LLMs
Why Uncertainty Matters
LLMs demonstrate impressive capabilities but have critical limitations:
- No guarantee of truthfulness: Outputs can be factually incorrect
- Overconfidence problem: High confidence even when wrong
- Plausible-sounding errors: Mistakes are hard to detect
- High-stakes domains: Healthcare, law, science require reliability
Current Approaches and Their Limitations
Supervised Methods:
- Train probes to predict correctness
- Require labeled data and additional training
- Poor generalization to out-of-distribution data
Unsupervised Methods:
- Logit-based (Perplexity): Ignore semantic consistency
- Sampling-based (Semantic Entropy): Require multiple generations (expensive)
- External models (CCP): Depend on NLI models (computational overhead)
Key Gap: Existing methods either overlook semantic information or require expensive repeated sampling/external models.
The Solution: Semantic Token Clustering
Core Insight
When an LLM is confident about an answer, probability mass is distributed across semantically equivalent tokens:
- “television” vs. “TV” vs. “tv”
- “United States” vs. “USA” vs. “America”
Looking at individual token probabilities underestimates the model’s true confidence. We should aggregate probability mass over semantic clusters.
Method Overview
Pre-computation Stage (offline):
- Embedding clustering: Group vocabulary tokens by semantic similarity
- Store cluster assignments for fast lookup
Inference Stage (online):
- Generate response (single pass)
- At each decoding step, identify semantic cluster for predicted token
- Prefix matching: Include tokens with matching prefixes (“television”, “Television”, “televis…”)
- Aggregate probabilities: Sum probability mass over cluster
- Compute uncertainty score from aggregated probabilities
Mathematical Formulation
Given input x and generated response y, estimate uncertainty:
U(x, y) = g(p̂(C = 0 | x, y))
where:
Cis binary correctness indicatorgis monotonically increasing link functionp̂is estimated from cluster-aggregated probabilities
At each token position, cluster probability:
P_cluster = Σ P(token) for all tokens in semantic cluster
Uncertainty is computed from the entropy or confidence of cluster probabilities.
Key Advantages
1. Leveraging Internal Representations
- Uses token embedding clustering to capture semantic structure
- Directly exploits LLM’s internal semantic knowledge
- No need for external semantic similarity models
2. Self-Contained Implementation
- No fine-tuning required
- No supervised data needed
- No external models (NLI, etc.)
- Works with any white-box LLM out-of-the-box
3. Computational Efficiency
- Single generation: No repeated sampling
- Offline clustering: Expensive operations done once
- Fast inference: Minimal runtime overhead
- Ideal for resource-constrained and low-latency scenarios
Experimental Results
Datasets
Evaluated on question-answering tasks:
- NQ (Natural Questions)
- TQA (TriviaQA)
Performance (AUROC)
The method achieves comparable or better performance than state-of-the-art baselines:
| Method | Semantic Aware | Single Sample | External Model Free | Overhead | Performance |
|---|---|---|---|---|---|
| Perplexity | ✗ | ✓ | ✓ | Low | 0.70 |
| Semantic Entropy | ✓ | ✗ | ✗ | High | 0.88 |
| CCP | ✓ | ✓ | ✗ | High | 0.87 |
| STC (Ours) | ✓ | ✓ | ✓ | Low | 0.88 |
Key Findings
- Matches multi-sample methods with single generation
- Outperforms single-sample baselines that ignore semantics
- Dramatically lower computational cost than semantic-aware methods
- Robust across different model sizes and architectures
Technical Deep Dive
Embedding Clustering
Approach:
- Extract token embeddings from LLM’s embedding layer
- Apply clustering algorithm (K-means, hierarchical, etc.)
- Group semantically similar tokens together
Example clusters:
- Cluster 1: [“television”, “TV”, “tv”, “telly”]
- Cluster 2: [“USA”, “United States”, “America”, “US”]
- Cluster 3: [“yes”, “yeah”, “yep”, “affirmative”]
Prefix Matching
Motivation: Capture morphological variations and capitalization
- “television” → “Television”, “televisions”, “televis…”
- “United States” → “united states”, “United states”
Implementation:
- For predicted token, find all vocabulary tokens with matching prefix
- Add their probabilities to cluster probability
Uncertainty Scoring
Multiple options for computing final uncertainty:
- Entropy:
H = -Σ P_cluster * log(P_cluster) - Confidence:
U = 1 - max(P_cluster) - Margin:
U = P_cluster[1] - P_cluster[2]
Paper uses entropy-based scoring for best results.
Comparison with Baselines
vs. Perplexity
- Perplexity: Token-level probability, ignores semantics
- STC: Cluster-level probability, captures semantic equivalence
- Result: STC significantly outperforms
vs. Semantic Entropy
- Semantic Entropy: Multiple generations + NLI model for semantic clustering
- STC: Single generation + embedding clustering
- Result: Similar performance, 10x+ faster
vs. CCP (Claim Conditioned Probability)
- CCP: Single generation but requires NLI model
- STC: Single generation, no external model
- Result: Similar performance, lower overhead
Practical Implications
When to Use STC
Ideal for scenarios requiring:
- Low latency: Real-time applications
- Resource constraints: Limited compute budget
- High throughput: Processing many queries
- Reliability: Detecting potentially incorrect outputs
Applications
- Conversational AI: Flag uncertain responses for human review
- Question Answering: Provide confidence scores with answers
- Content Generation: Identify sections needing fact-checking
- Decision Support: Highlight high-uncertainty predictions in critical domains
Integration
Easy to integrate into existing LLM pipelines:
# Pseudo-code
def generate_with_uncertainty(prompt):
# Pre-computed: token_clusters
response, logits = model.generate(prompt, return_logits=True)
uncertainties = []
for token, logit in zip(response, logits):
cluster = token_clusters[token]
cluster_prob = sum(logit[t] for t in cluster)
uncertainty = -log(cluster_prob)
uncertainties.append(uncertainty)
avg_uncertainty = mean(uncertainties)
return response, avg_uncertainty
Limitations and Future Work
Current Limitations
- White-box requirement: Needs access to token probabilities (not available in API-only models)
- Clustering quality: Depends on embedding space quality
- Fixed clusters: Doesn’t adapt clusters to specific contexts
- Token-level only: Doesn’t capture sentence-level semantic consistency
Future Directions
- Dynamic clustering: Adapt clusters based on context
- Hierarchical uncertainty: Combine token, sentence, and document-level uncertainty
- Black-box adaptation: Extend to API-only models
- Multi-modal: Apply to vision-language models
- Calibration: Improve uncertainty calibration for better reliability
Takeaways
- Semantic clustering is key: Aggregating probability over semantically similar tokens dramatically improves uncertainty estimation
- Single generation suffices: No need for expensive repeated sampling
- Internal representations are powerful: LLM embeddings encode rich semantic structure
- Efficiency matters: Practical deployment requires low-overhead methods
- Self-contained is better: Avoiding external models simplifies deployment and reduces dependencies
This work demonstrates that efficient and accurate uncertainty quantification is possible by cleverly leveraging the semantic structure already encoded in LLMs. The method’s simplicity, efficiency, and strong performance make it highly practical for real-world deployment.
For applications requiring reliable LLM outputs, STC provides a principled way to identify potentially incorrect responses with minimal computational overhead – a critical capability for deploying LLMs in high-stakes domains.
论文: 2603.20161 作者: Qi Cao, Andrew Gambardella, Takeshi Kojima, Yutaka Matsuo, Yusuke Iwasawa 机构: 东京大学 分类: cs.CL
摘要
大型语言模型经常以高置信度生成听起来合理但不正确的响应,因此量化其不确定性至关重要。现有方法依赖于重复采样或辅助模型,引入了大量计算开销。本文提出了语义令牌聚类(STC),这是一种高效的不确定性量化方法,只需要单次生成且无需外部模型,在大幅降低计算成本的同时实现了与最先进方法相当的性能。
问题:过度自信的 LLM
为什么不确定性很重要
LLM 展示了令人印象深刻的能力,但存在关键限制:
- 不保证真实性:输出可能在事实上不正确
- 过度自信问题:即使错误也有高置信度
- 听起来合理的错误:错误难以检测
- 高风险领域:医疗保健、法律、科学需要可靠性
当前方法及其限制
监督方法:
- 训练探针来预测正确性
- 需要标记数据和额外训练
- 对分布外数据泛化能力差
无监督方法:
- 基于 logit(困惑度):忽略语义一致性
- 基于采样(语义熵):需要多次生成(昂贵)
- 外部模型(CCP):依赖 NLI 模型(计算开销)
关键差距:现有方法要么忽略语义信息,要么需要昂贵的重复采样/外部模型。
解决方案:语义令牌聚类
核心洞察
当 LLM 对答案有信心时,概率质量分布在语义等价的令牌上:
- “television” vs. “TV” vs. “tv”
- “United States” vs. “USA” vs. “America”
查看单个令牌概率会低估模型的真实置信度。我们应该在语义簇上聚合概率质量。
方法概述
预计算阶段(离线):
- 嵌入聚类:按语义相似性对词汇令牌进行分组
- 存储簇分配以便快速查找
推理阶段(在线):
- 生成响应(单次传递)
- 在每个解码步骤,识别预测令牌的语义簇
- 前缀匹配:包括具有匹配前缀的令牌(“television”、“Television”、“televis…”)
- 聚合概率:对簇上的概率质量求和
- 从聚合概率计算不确定性分数
数学公式
给定输入 x 和生成的响应 y,估计不确定性:
U(x, y) = g(p̂(C = 0 | x, y))
其中:
C是二元正确性指标g是单调递增的链接函数p̂从簇聚合概率估计
在每个令牌位置,簇概率:
P_cluster = Σ P(token) 对于语义簇中的所有令牌
不确定性从簇概率的熵或置信度计算。
主要优势
1. 利用内部表示
- 使用令牌嵌入聚类来捕获语义结构
- 直接利用 LLM 的内部语义知识
- 无需外部语义相似性模型
2. 自包含实现
- 无需微调
- 无需监督数据
- 无外部模型(NLI 等)
- 开箱即用适用于任何白盒 LLM
3. 计算效率
- 单次生成:无重复采样
- 离线聚类:昂贵操作只做一次
- 快速推理:最小运行时开销
- 适用于资源受限和低延迟场景
实验结果
数据集
在问答任务上评估:
- NQ(自然问题)
- TQA(TriviaQA)
性能(AUROC)
该方法实现了与最先进基线相当或更好的性能:
| 方法 | 语义感知 | 单样本 | 无外部模型 | 开销 | 性能 |
|---|---|---|---|---|---|
| 困惑度 | ✗ | ✓ | ✓ | 低 | 0.70 |
| 语义熵 | ✓ | ✗ | ✗ | 高 | 0.88 |
| CCP | ✓ | ✓ | ✗ | 高 | 0.87 |
| STC(我们的) | ✓ | ✓ | ✓ | 低 | 0.88 |
关键发现
- 单次生成匹配多样本方法
- 优于忽略语义的单样本基线
- 比语义感知方法的计算成本低得多
- 在不同模型大小和架构上稳健
技术深入探讨
嵌入聚类
方法:
- 从 LLM 的嵌入层提取令牌嵌入
- 应用聚类算法(K-means、层次聚类等)
- 将语义相似的令牌分组在一起
示例簇:
- 簇 1:[“television”, “TV”, “tv”, “telly”]
- 簇 2:[“USA”, “United States”, “America”, “US”]
- 簇 3:[“yes”, “yeah”, “yep”, “affirmative”]
前缀匹配
动机:捕获形态变化和大小写
- “television” → “Television”、“televisions”、“televis…”
- “United States” → “united states”、“United states”
实现:
- 对于预测的令牌,找到所有具有匹配前缀的词汇令牌
- 将它们的概率添加到簇概率
不确定性评分
计算最终不确定性的多个选项:
- 熵:
H = -Σ P_cluster * log(P_cluster) - 置信度:
U = 1 - max(P_cluster) - 边际:
U = P_cluster[1] - P_cluster[2]
论文使用基于熵的评分以获得最佳结果。
与基线的比较
vs. 困惑度
- 困惑度:令牌级概率,忽略语义
- STC:簇级概率,捕获语义等价
- 结果:STC 显著优于
vs. 语义熵
- 语义熵:多次生成 + NLI 模型进行语义聚类
- STC:单次生成 + 嵌入聚类
- 结果:相似性能,快 10 倍以上
vs. CCP(声明条件概率)
- CCP:单次生成但需要 NLI 模型
- STC:单次生成,无外部模型
- 结果:相似性能,更低开销
实际影响
何时使用 STC
适用于需要以下场景:
- 低延迟:实时应用
- 资源约束:有限的计算预算
- 高吞吐量:处理许多查询
- 可靠性:检测潜在不正确的输出
应用
- 对话 AI:标记不确定的响应以供人工审查
- 问答:为答案提供置信度分数
- 内容生成:识别需要事实检查的部分
- 决策支持:在关键领域突出显示高不确定性预测
集成
易于集成到现有 LLM 管道中:
# 伪代码
def generate_with_uncertainty(prompt):
# 预计算:token_clusters
response, logits = model.generate(prompt, return_logits=True)
uncertainties = []
for token, logit in zip(response, logits):
cluster = token_clusters[token]
cluster_prob = sum(logit[t] for t in cluster)
uncertainty = -log(cluster_prob)
uncertainties.append(uncertainty)
avg_uncertainty = mean(uncertainties)
return response, avg_uncertainty
限制和未来工作
当前限制
- 白盒要求:需要访问令牌概率(在仅 API 模型中不可用)
- 聚类质量:取决于嵌入空间质量
- 固定簇:不会根据特定上下文调整簇
- 仅令牌级:不捕获句子级语义一致性
未来方向
- 动态聚类:根据上下文调整簇
- 分层不确定性:结合令牌、句子和文档级不确定性
- 黑盒适应:扩展到仅 API 模型
- 多模态:应用于视觉-语言模型
- 校准:改进不确定性校准以提高可靠性
要点
- 语义聚类是关键:在语义相似的令牌上聚合概率显著改善不确定性估计
- 单次生成就足够:无需昂贵的重复采样
- 内部表示很强大:LLM 嵌入编码丰富的语义结构
- 效率很重要:实际部署需要低开销方法
- 自包含更好:避免外部模型简化部署并减少依赖
这项工作表明,通过巧妙地利用 LLM 中已经编码的语义结构,高效和准确的不确定性量化是可能的。该方法的简单性、效率和强大性能使其在实际部署中非常实用。
对于需要可靠 LLM 输出的应用,STC 提供了一种原则性的方法,以最小的计算开销识别潜在不正确的响应——这是在高风险领域部署 LLM 的关键能力。