TL;DR
This paper introduces "Temperature as Uncertainty" (TaU), a novel method that repurposes the temperature hyperparameter in contrastive learning to estimate input-specific uncertainty. TaU effectively detects out-of-distribution samples and can be applied post-hoc to existing pre-trained models, offering a simple yet powerful way to imbue contrastive representations with confidence scores.
What Problem Does This Paper Address?
Contrastive learning has achieved remarkable success in learning powerful visual representations without explicit labels, often matching or exceeding supervised methods. However, a critical limitation for real-world deployment is the lack of uncertainty estimation. Knowing when a model is "unsure" about its predictions is crucial for robust decision-making, anomaly detection, and preventing errors. Current contrastive learning frameworks typically learn one-to-one mappings from inputs to embeddings, providing no inherent measure of confidence. This paper aims to bridge this gap by introducing a method to quantify this uncertainty.
Methods
The core idea of TaU is to treat the temperature parameter, traditionally a fixed scalar in contrastive learning objectives, as an input-dependent variable. The authors observe that temperature controls the sensitivity of the contrastive loss to specific embedding locations. By learning temperature as a function of the input, they propose it can serve as a measure of embedding confidence.
Specifically, they modify the standard contrastive loss function (Eq. 1) by replacing the fixed temperature $\tau$ with a learned function $\tau(x)$. This learned temperature $\tau(x)$ is outputted by the encoder network alongside the embedding. The authors propose a sigmoid activation followed by a scaling factor to ensure the temperature is positive and within a reasonable range. Algorithm 1 outlines the process of integrating this learned temperature into the SimCLR framework. For practical implementation, they suggest modifying the encoder to output $d+1$ dimensions, where the first $d$ are the embedding and the $(d+1)$-th is the learned temperature.
Datasets
The paper uses the following datasets:
- CIFAR10: Used as the inlier dataset for training and evaluating TaU.
- CIFAR100, SVHN, TinyImageNet: Used as out-of-distribution (OOD) datasets to evaluate the uncertainty estimation capabilities of TaU. SVHN is noted as being particularly dissimilar to CIFAR10.
- ImageNet: Used for pre-training larger models (ResNet50) whose embeddings are then used for post-hoc TaU uncertainty estimation.
- COCO, LSUN, CelebA: Additional datasets used in the experiments for evaluating TaU on pre-trained embeddings.
Key Insights and Ideas
- Temperature as a proxy for uncertainty: The central insight is that the temperature hyperparameter, often seen as a mysterious scaling factor, can be re-purposed as a direct indicator of input-specific uncertainty. Higher temperatures imply less sensitivity to embedding changes, suggesting higher uncertainty.
- Input-dependent temperature: Moving from a global, fixed temperature to an input-dependent one is the key innovation. This allows the model to express varying levels of confidence for different inputs.
- Post-hoc applicability: A significant advantage is that TaU can be learned on top of existing pre-trained representations (e.g., from supervised, SimCLR, BYOL models). This makes it highly practical, allowing users to add uncertainty estimation to models without retraining from scratch.
- Competitive performance: TaU not only provides uncertainty estimates but also maintains competitive performance on downstream tasks like linear evaluation, suggesting that adding uncertainty doesn't significantly degrade representation quality.
Key Results
- OOD Detection: TaU demonstrates strong performance in out-of-distribution detection, outperforming several established baselines (e.g., MC Dropout, Hedged Instance Embedding, Ensembles) on datasets like SVHN, which is significantly different from the training data. For example, on SVHN, TaU + SimCLR achieves an AUROC of 0.968, significantly higher than many baselines.
- Linear Evaluation: TaU-based models show only a slight decrease (2-3 percentage points) in accuracy on linear evaluation and k-NN evaluation compared to their deterministic counterparts, indicating a good trade-off between uncertainty and performance.
- Pretrained Models: TaU successfully generates uncertainty scores on top of various pre-trained embeddings (Supervised, SimCLR, BYOL), achieving high AUROC values for OOD detection across multiple datasets. For instance, TaU + Supervised on CIFAR100 yields an AUROC of 0.874.
Limitations and Future Work
- Limited to NCE-based contrastive methods: The current TaU approach is primarily designed for contrastive learning frameworks that utilize Noise Contrastive Estimation (NCE). It shows limited success with methods that rely solely on stop gradients, such as SimSiam, BYOL, and Barlow Twins.
- Future Directions: The authors suggest exploring TaU-like techniques for detecting corrupted or adversarial examples, which are other critical aspects of robust AI systems. Further investigation into why CLIP embeddings behave differently with TaU is also warranted.
Summary updated