Uncertainty Estimation & Confidence Calibration¶
~2 минуты чтения
Предварительно: Фреймворки оценки LLM
Source: DNV Technology Insights "Practical Guide to Uncertainty Estimation" (2025), ArXiv "Uncertainty Quantification and Confidence Calibration" (2025), ICML 2025 Workshop
Концепция¶
Зачем UQ для LLMs: - High-stakes domains: healthcare, legal, finance - LLMs generate plausible-sounding but incorrect outputs - Need to know WHEN to trust model outputs
Types of Uncertainty:
| Type | Description | Example |
|---|---|---|
| Epistemic | Knowledge gap (reducible with more data) | "What are 2025 emission standards?" for 2023-trained model |
| Aleatory | Inherent ambiguity (irreducible) | "Is this pump safe?" without context |
| Model-Intrinsic | Architecture/training uncertainty | Different valid answers from sampling |
| Content | Outside training distribution | Domain-specific questions |
UQ Methods by Model Access¶
| Level | Access | Methods |
|---|---|---|
| Black-box | API only | Sampling, verbalization, external validators |
| Grey-box | Probabilities/embeddings | Logit analysis, semantic clustering |
| White-box | Full model | BNN, MC Dropout, internal activations |
Sampling-Based Uncertainty¶
class SamplingUncertainty:
"""Estimate uncertainty via multiple samples"""
def __init__(self, model, n_samples=10, temperature=0.7):
self.model = model
self.n_samples = n_samples
self.temperature = temperature
def estimate_uncertainty(self, prompt):
"""Generate multiple responses and measure consistency"""
responses = []
for _ in range(self.n_samples):
response = self.model.generate(
prompt,
temperature=self.temperature
)
responses.append(response)
# Semantic clustering of responses
embeddings = self.model.embed(responses)
clusters = self.cluster_responses(embeddings)
# Uncertainty metrics
metrics = {
"num_clusters": len(clusters),
"largest_cluster_ratio": max(len(c) for c in clusters) / self.n_samples,
"entropy": self.compute_cluster_entropy(clusters),
"semantic_diversity": self.compute_diversity(embeddings)
}
# High uncertainty = many clusters, low largest cluster ratio
is_uncertain = (
metrics["num_clusters"] > 3 or
metrics["largest_cluster_ratio"] < 0.5
)
return {
"uncertainty_metrics": metrics,
"is_uncertain": is_uncertain,
"responses": responses
}
Calibration Methods¶
Post-hoc Calibration:
class CalibratedConfidence:
"""Calibrate confidence scores post-hoc"""
def __init__(self, calibration_data):
self.calibrator = self.fit_calibrator(calibration_data)
def fit_calibrator(self, data):
"""Learn mapping: model_confidence -> actual_accuracy"""
from sklearn.isotonic import IsotonicRegression
confidences = [d[2] for d in data]
accuracies = [1.0 if d[3] else 0.0 for d in data]
calibrator = IsotonicRegression(out_of_bounds='clip')
calibrator.fit(confidences, accuracies)
return calibrator
def calibrate(self, confidence_score):
return self.calibrator.predict([[confidence_score]])[0]
Интервью вопросы¶
Q: Что такое epistemic vs aleatory uncertainty?
A: Epistemic -- uncertainty из-за недостатка знаний (reducible с большим data). Aleatory -- inherent uncertainty из-за ambiguity/randomness (irreducible). Пример epistemic: "2025 emission standards" для модели обученной до 2023. Пример aleatory: "Is this pump safe?" -- зависит от условий не указанных в question.
Q: Как оценить uncertainty с black-box API доступом?
A: (1) Sampling-based: generate multiple responses, cluster by semantics, measure diversity. (2) Verbalized confidence: ask model to express its uncertainty. (3) External validators: use separate model/classifier. (4) Post-hoc calibration: learn mapping от model confidence к actual accuracy.
Q: Что такое calibrated confidence?
A: Calibrated confidence = confidence score matches actual accuracy. Если модель говорит "90% confident" -- она должна быть права в 90% случаев. LLMs часто overconfident. Calibration methods: Isotonic Regression, Platt Scaling, Temperature Scaling.
See Also¶
- Наблюдаемость LLM -- monitoring confidence in production
- Гардрейлы LLM -- guardrails based on uncertainty