[Paper Review] Temperature as Uncertainty in Contrastive Learning
This paper proposes Temperature as Uncertainty (TaU), a method to generate input-dependent uncertainty scores in contrastive representation learning by reinterpreting the temperature hyperparameter as a learned measure of embedding confidence. By making temperature vary per input, TaU enables out-of-distribution detection with minimal performance drop on downstream tasks, and can be applied post-hoc to pretrained models with no retraining.
Contrastive learning has demonstrated great capability to learn representations without annotations, even outperforming supervised baselines. However, it still lacks important properties useful for real-world application, one of which is uncertainty. In this paper, we propose a simple way to generate uncertainty scores for many contrastive methods by re-purposing temperature, a mysterious hyperparameter used for scaling. By observing that temperature controls how sensitive the objective is to specific embedding locations, we aim to learn temperature as an input-dependent variable, treating it as a measure of embedding confidence. We call this approach "Temperature as Uncertainty", or TaU. Through experiments, we demonstrate that TaU is useful for out-of-distribution detection, while remaining competitive with benchmarks on linear evaluation. Moreover, we show that TaU can be learned on top of pretrained models, enabling uncertainty scores to be generated post-hoc with popular off-the-shelf models. In summary, TaU is a simple yet versatile method for generating uncertainties for contrastive learning. Open source code can be found at: https://github.com/mhw32/temperature-as-uncertainty-public.
Motivation & Objective
- To address the lack of uncertainty estimation in contrastive representation learning, which limits real-world deployment in safety-critical applications.
- To explore whether the temperature hyperparameter—commonly treated as a fixed scalar—can be repurposed as a learned, input-specific measure of uncertainty.
- To enable uncertainty estimation without retraining models, allowing post-hoc application to existing off-the-shelf checkpoints.
- To evaluate whether TaU improves out-of-distribution detection while maintaining competitive performance on standard downstream benchmarks.
Proposed method
- Repurpose the temperature hyperparameter τ in contrastive learning as an input-dependent variable, learned via a neural network head that outputs τ(x) for each input x.
- Modify the contrastive loss (e.g., SimCLR or MoCo-v2) to use τ(t(x_i)) instead of a fixed τ, where t(x_i) is a transformed view of input x_i.
- Train the encoder network to output both the embedding f(x) and the inverse temperature τ(x), with τ(x) predicted via a sigmoid-scaled head to ensure positivity.
- Use the inverse temperature τ(x) as a proxy for uncertainty: higher τ indicates higher uncertainty (more forgiving loss), lower τ indicates higher confidence.
- Apply TaU to pretrained models by fine-tuning a small adapter head on top of frozen features to predict τ(x), enabling post-hoc uncertainty estimation.
- Use the predicted τ(x) to compute uncertainty-aware similarity scores and evaluate OOD detection performance via AUROC on benchmark datasets.
Experimental results
Research questions
- RQ1Can the temperature hyperparameter in contrastive learning be reinterpreted as a learned, input-dependent measure of uncertainty?
- RQ2Does learning temperature per input improve out-of-distribution detection performance compared to fixed-temperature baselines?
- RQ3Can uncertainty be effectively added to pretrained contrastive models post-hoc without retraining the main encoder?
- RQ4How does TaU compare in downstream linear evaluation accuracy to standard contrastive models with fixed temperature?
- RQ5Does TaU generalize well across diverse OOD datasets, especially when the OOD data is semantically distant from the training distribution?
Key findings
- TaU outperforms baseline uncertainty methods—including ensembling and Bayesian posteriors—on out-of-distribution detection, especially on distant OOD sets like SVHN, where it exceeds baselines by 13% AUROC.
- On CIFAR100 and TinyImageNet, TaU matches or slightly exceeds all baselines, including SimCLR + kNN, with a 0.5–2% performance gap.
- TaU incurs only a 2–3 percentage point drop in linear evaluation accuracy compared to standard SimCLR and MoCo-v2, indicating minimal downstream performance cost.
- TaU can be successfully applied post-hoc to pretrained models (e.g., supervised, SimCLR, BYOL, CLIP), with high AUROC on CIFAR10 (0.913) and SVHN (0.978) when using supervised or SimCLR features.
- CLIP embeddings show poor OOD detection with TaU (AUROC ~0.05), suggesting model-specific limitations or distributional mismatches, though it performs well on COCO and LSUN.
- The method is ineffective for contrastive frameworks that replace negative samples with stop gradients (e.g., SimSiam, BYOL), indicating a limitation to NCE-based objectives.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.