SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Figure 2: Among ViTs and ResNets, respectively, Losspred and MInfoNCE transfer best both in terms of uncertainty estimates (y-axis), measured by our R-AUROC, and embedding quality (x-axis), measured by Recall@1. Three seeds per model and architecture.
Figure 3: Best hyperparameters chosen for R@1 and for R-AUROC for each model. For some models, there is one best hyperparameter for both, resulting in a point, but most have a large trade-off. Average performance across three seeds.
already seen that Losspred can achieve both with only a slight trade-off to the best method in each category. In this section, we further detail this question within each model class.
Fig. 3 shows the performance of the best hyperparameters chosen according to R-AUROC or according to the  $\mathbf{R}@\mathbf{1}$ . If there was no trade-off, the points would lay at the same position or only have a short line connecting them. This is the case for MCInfoNCE, ELK, nivMF, HET-XL, and Ensemble on ViTs and MCInfoNCE, MCDropout, and InfoNCE on ResNets. The remaining 14 of the 22 approaches show large tradeoffs, e.g.,  $-0.21\mathrm{R@1}$  for  $+0.01$  R-AUROC for HIB on ViTs. Whereas this comparison regards only the two extreme ends of the spectrum, Appendix C.2 measures the rank correlation across all tested hyperparameters. It shows a similar conclusion, with 15 out of 22 approaches trading off uncertainty and prediction. However, from another perspective, Losspred, nivMF, and MCInfoNCE are model classes that provide good performance in both simultaneously. Hence, the question of whether there is a general trade-off between uncertainty estimation and prediction is still up to debate. Studying these models and mitigating the model-internal trade-offs is an interesting future work that we hope URL can enable.
Figure 4: The R-AUROC on upstream data does not indicate the performance on downstream data (left). Yet, the percentage of upstream images where a cropped version receives a higher uncertainty is indicative (right). Plots show all hyperparameters, including non-optimal ones.
4.5 Models with good uncertainties upstream are not necessarily good downstream
We have seen that CE is unable to transfer its well-calibrated upstream uncertainty estimates to downstream datasets. This brings up the question of how much the upstream and downstream uncertainty quantification abilities coincide in general. Fig. 4 (left) shows that the majority of models achieves an R-AUROC above 0.7 on the upstream seen classes. But this does not indicate a good downstream performance (Rank Corr. 0.09), neither across nor within model classes (unlike up- and downstream R@1, which transfers better, see Appendix C.3). This demonstrates that transferable uncertainty quantification will not solve itself by merely becoming better on the upstream data.
This also opens a question about model choice: If the upstream performance cannot tell how well the model's uncertainty predictions will perform downstream, how should we select pretrained models? In this paper, we used downstream validation data. However, if we are limited to upstream data, we may test the uncertainty module in a more general task that also holds downstream. In Fig. 4 (right), we calculate how often the model assigns a higher uncertainty value to a cropped version of an image than to the original image. The rank correlation of 0.54 with the downstream R-AUROC signals that models that perform well on this general uncertainty task also tend to generalize better to the downstream data. This means that general uncertainty tasks might be good heuristics to choose models, reinforcing practices in recent literature (Kirchhof et al., 2023).
4.6 URL captures how well-aligned a model is with human uncertainty
While the R-AUROC is simple and theoretically founded, readers might still wonder why we want to drive the development of models based on this rather technical-seeming metric. In this section, we show that the R-AUROC reflects how well-aligned the model is with human uncertainties.
To verify this, we use five additional downstream datasets from Schmarje et al. (2022): CIFAR-10H (Peterson et al., 2019), Benthic (Langenkämper et al., 2020; Schoening et al., 2020), Pig (Schmarje et al., 2022), Turkey (Volkmann et al., 2022, 2021), and Treversity#1 (Arnold Arboretum, 2020). They present human annotators with naturally ambiguous images and record their uncertainty by collecting multiple class annotations per image. The entropy of this distribution measures the human uncertainty  $h(x) = \mathcal{H}(P_{\mathrm{human}}(Y|x))$ . We can then measure the alignment of the model  $f$ 's uncertainties with human uncertainties via rank correlation  $a(f) = \mathrm{RankCorr}(\{u(x),h(x)\}_x)$ . Fig. 5 (left) shows that this alignment metric  $a(f)$  is positively correlated with the R-AUROC (Rank Corr. 0.80). Further, Fig. 5 (right) shows that the same holds for the correlation between R-AUROC and how well a model detects the uncertainty introduced synthetically via cropping (Rank Corr. 0.71), as in the previous section. This means that the R-AUROC is not just a technical metric, but reveals
Figure 5: If a model has a high R-AUROC, it is likely also well-aligned with human uncertainties (left). Further, it is likely able to detect uncertainties induced via synthetical cropping (right). All results on five further downstream datasets from Schmarje et al. (2022).
how well a model's uncertainty estimate is aligned with human and synthetical notions of uncertainty, despite not requiring access to human uncertainty ground truths.
4.7 URL is no out-of-distribution detection benchmark
Last, we want to clarify how URL is different from out-of-distribution (OOD) detection benchmarks like (Ovadia et al., 2019). While both test uncertainty estimates on OOD data, the goal is different: In OOD detection benchmarks, the uncertainty estimates are tasked to be generally higher for OOD than for in-distribution (ID) samples. In URL, we look only at the OOD data and see if the uncertainties within this data are correctly sorted. This is because our use-case is not to build OOD or anomaly detectors, but pretrained models whose uncertainty estimates generalize to new datasets. In Appendices C.4 and C.5 we show that methods with good OOD detection abilities are not necessarily good in URL or vice versa. This demonstrates that URL is concerned with predictive uncertainty estimation (and generalization), which is largely driven by aleatoric uncertainty, rather than epistemic uncertainty estimation, which is tested in OOD benchmarks.
Summary This paper proposes the uncertainty-aware representation learning (URL) benchmark. On top of the Recall@1, URL adds an easy-to-implement metric that evaluates how well models estimate uncertainties on unseen downstream data. Besides having a theoretical foundation, it also behaves similarly to practical metrics like the alignment with human uncertainties. In benchmarking eleven state-of-the-art approaches on ResNet and ViT backbones, we found that the challenge URL poses is far from being solved. We hope that URL guides the field to overcome this challenge and yield models with reliable pretrained uncertainty estimates.
Outlook We gathered some insights that might guide future developments: Both unsupervised and supervised methods can learn transferable uncertainty estimates. This is not necessarily at stakes with the embedding and prediction quality. However, many methods have internal trade-offs in their hyperparameters. A deeper analysis of the reasons for this trade-off could allow us to control and mitigate it. Loss prediction and probabilistic embedding methods are currently the most promising approaches. They may be combined to enhance each other and define a new state-of-the-art.
Limitations Although URL allows using any upstream benchmark, we have focused on ImageNet-1k to train all current methods on the same ground. We leave the investigation of further scaled datasets to forthcoming research. Further, we hyperparameter-tuned each model individually with the
same budget, but the vast number of hyperparameters in some models, like SNGP, means that our active learning search may have missed some fruitful combinations. Finally, our study concentrates on zero-shot uncertainty estimates. It will be an interesting endeavour to see if pretrained models with good zero-shot estimates also accelerate learning uncertainties in few-shot scenarios.
This work was funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Germany's Excellence Strategy – EXC number 2064/1 – Project number 390727645. The authors thank the International Max Planck Research School for Intelligent Systems (IMPRS-IS) for supporting Michael Kirchhof.
Shervin Ardeshir and Navid Azizan. Uncertainty in contrastive learning: On the predictability of downstream performance. arXiv preprint arXiv:2207.09336, 2022.
Arnold Arboretum. The TreeVersity dataset, 2020. URL https://arboretum.harvard.edu/research/data-resources/.
Yoshua Bengio, Aaron Courville, and Pascal Vincent. Representation learning: A review and new perspectives. IEEE Transactions on Pattern Analysis and Machine Intelligence, 35(8):1798-1828, 2013.
Lukas Biewald. Experiment tracking with weights and biases, 2020. URL https://www.wandb.com/.
Victor Bouvier, Simona Maggio, Alexandre Abraham, and Léo Dreyfus-Schmidt. Towards clear expectations for uncertainty estimation. arXiv preprint arXiv:2207.13341, 2022.
Ting Chen, Simon Kornblith, Mohammad Norouzi, and Geoffrey Hinton. A simple framework for contrastive learning of visual representations. In Proceedings of the 37th International Conference on Machine Learning (ICML), 2020.
Sanghyuk Chun, Seong Joon Oh, Rafael Sampaio De Rezende, Yannis Kalantidis, and Diane Larlus. Probabilistic embeddings for cross-modal retrieval. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2021.
Sanghyuk Chun, Wonjae Kim, Song Park, Minsuk Chang Chang, and Seong Joon Oh. ECCV caption: Correcting false negatives by collecting machine-and-human-verified image-caption associations for ms-coco. In European Conference on Computer Vision (ECCV), 2022.
Mark Collier, Rodolphe Jenatton, Basil Mustafa, Neil Houlsby, Jesse Berent, and Effrosyni Kokiopoulou. Massively scaling heteroscedastic classifiers. arXiv preprint arXiv:2301.12860, 2023.
Thomas M Cover. Elements of information theory. John Wiley & Sons, 1999.
Peng Cui, Dan Zhang, Zhijie Deng, Yinpeng Dong, and Jun Zhu. Learning sample difficulty from pre-trained models for reliable prediction. arXiv preprint arXiv:2304.10127, 2023.
Tim R. Davidson, Luca Falorsi, Nicola De Cao, Thomas Kipf, and Jakub M. Tomczak. Hyperspherical variational auto-encoders. 34th Conference on Uncertainty in Artificial Intelligence (UAI), 2018.
Mostafa Dehghani, Josip Djolonga, Basil Mustafa, Piotr Padlewski, Jonathan Heek, Justin Gilmer, Andreas Steiner, Mathilde Caron, Robert Geirhos, Ibrahim Alabdulmohsin, et al. Scaling vision transformers to 22 billion parameters. arXiv preprint arXiv:2302.05442, 2023.
Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Li Fei-Fei. Imagenet: A large-scale hierarchical image database. In Computer Vision and Pattern Recognition (CVPR), 2009.
A FAQ on URL benchmark and R-AUROC
A.1 Why AUROC with respect to  $\mathbf{R}@\mathbf{1}$  and not accuracy?
First attempts in zero-shot learning literature measured the accuracy on unseen classes. This required learning not only an embedder, but also constructing classifier labels, usually through prototypes or attributes. Subsequent approaches in representation and deep metric learning seeked generally transferable embeddings, where no information is known about the test classes. So, it was impossible to give class logits and calculate an accuracy. Instead they measure the R@1. We have the same goal of transferring uncertainty estimates to unknown test conditions, so we built up the uncertainty benchmark on predicting whether the R@1 will be correct or wrong. This measures the risk inherent to the embedding, rather than the (classification) downstream task, which is unknown in advance. However, the risk in the embedding is a bottleneck to the potential subsequent classification layer and we indeed observe in Appendix C.3 that R@1 and accuracy are highly correlated, so that the difference is negligible.
A.2 Why a ranking-based metric (AUROC) and not probability-based calibration?
The AUROC measures if the predicted uncertainties are ranked such that the most uncertain have the most erroneous predictions. It is intriguing to use a different metric, which is to predict the probability of error directly as a value in  $[0, 1]$ . However, this metric fundamentally cannot be calibrated before the downstream task is known: In classification, we do not know how many classes there will be and beyond classification, our uncertainty metric should indicate the prediction risk, but without knowing the loss or its range in before, we cannot calibrate the uncertainty estimates. Therefore, the best strategy is to give a correctly ranked uncertainty metric, which is what AUROC measures. It can be calibrated into the  $[0, 1]$  region for the downstream task at hand once data is available. Another point is that a  $[0, 1]$  estimate has the trivial solution of always giving a random prediction the certainty being the prior over the classes. A ranking based metric cannot do that, as that would have an AUROC of 0.5. The AUROC thus forces the model to quantify how uncertain it is, not only that it is uncertain.
A.3 Does URL measure predictive, aleatoric, or epistemic uncertainty?
The R-AUROC in our setup measures the predictive uncertainty, in other words, the overall expected risk of a prediction. We believe this overall uncertainty is most relevant when seeking a reliable model. Note, however, that the AUROC uses a rank-based relative comparison of the uncertainty estimates. This means that a constant high uncertainty on out-of-distribution data does not suffice; instead, the model needs to quantify how uncertain it is, not just that it is uncertain. This is influenced both by the inherent ambiguity of the downstream sample (aleatoric) and how far it is from the upstream data (epistemic).
A.4 How is the AUROC implemented precisely?
We use the TorchMetrics implementation (Detlefsen et al., 2022). It applies the trapezoidal rule and uses every uncertainty value as a possible threshold.
A.5 Why CUB200-2011, CARS196, and Stanford Online Products?
Our definition of URL is agnostic of the datasets and can be applied to any downstream dataset. For this paper, we use CUB200-2011 (Wah et al., 2011), CARS196 (Krause et al., 2013), and Stanford Online Products (Song et al., 2016), because they are commonly used as zero-shot learning and representation learning datasets. We hope that this status prevents data-leakage to upstream pretraining datasets.
A.6 Can URL also be implemented for downstream datasets that don't have labels?
Throughout this paper, we measure the R@1 by seeing if the next neighbor of a test image has the same class label. This is to ensure the compatibility with representation learning benchmarks. One can also define a self-supervised R@1 (e.g., seeing if a crop of the same image is detected as belonging
to that image). In this case, R-AUROC automatically generalizes to this form of supervision, as it still measures errors in  $\mathbb{R}@\mathbb{1}$ , regardless of how it was computed.
A.7 Can URL be applied beyond vision tasks?
Yes. URL can be deployed whenever there is a downstream dataset on which we measure a R@1.
B Reimplementations and hyperparameters
All methods benchmarked in this paper are re-implemented and hyperparameter tuned to ensure a consistent comparison. First, let us explain the hyperparameters shared by all approaches: As backbones, we use ResNet-50 (He et al., 2016) architectures with  $224 \times 224$  inputs and 2048-dim max-pooled embeddings, and ViT-Medium (Dosovitskiy et al., 2021) with an input size of  $256 \times 256$  split into  $16 \times 16$  patches. All models are tuned for 32 epochs with a Lamb optimizer (You et al., 2020). 16 minibatches of size 128 are accumulated to reach a summed batch size of 2048, unless otherwise noted. The learning rate is fixed at the first epoch, then warmed up for five epochs and cooled down using a cosine scheduler (Loshchilov and Hutter, 2017). The learning rate is a hyperparameter for all approaches, searched over a range of [0.0001, 0.01]. The hyperparameter search is extended by more runs if the optimal value is close to a boundary. Let us now describe the approaches and their additional hyperparameters in detail. All optimal hyperparameters are reported in the code appendix.
B.1 Cross-Entropy (CE)
The CE baseline applies a cross-entropy loss to the class-logits output by a final linear layer appended to the embeddings. It has no hyperparameters except the learning rate.
B.2 InfoNCE
InfoNCE (Oord et al., 2018) uses two random crops per input image that are considered positive, whereas the remaining batch is considered negative. This results in a doubled VRAM usage, so that the batch size is reduced to 21 minibatches of 96 images each. InfoNCE uses an (inverse) temperature parameter  $t$ , tuned within [8, 64]. All embeddings  $e$  are normalized to lay on the unit sphere, where  $e_1^+$  and  $e_2^+$  denote the positive and  $e^-$  all negative embeddings. The final loss is
$$
\mathcal {L} = - t \cdot e _ {1} ^ {+ \top} e _ {2} ^ {+} + \log \sum_ {e ^ {-} \in \text {B a t c h}} \exp \left(t \cdot e _ {1} ^ {+ \top} e ^ {-}\right) + \log \sum_ {e ^ {-} \in \text {B a t c h}} \exp \left(t \cdot e _ {2} ^ {+ \top} e ^ {-}\right). \tag {1}
$$
B.3 MCInfoNCE
MCInfoNCE (Kirchhof et al., 2023) works similar to InfoNCE, except that it does not directly compare the embeddings, but samples from estimated posteriors  $s_{1,i}^{+} \sim \mathrm{vMF}(e_{1}^{+}, \kappa(e_{1}^{+}))$ ,  $s_{2,i}^{+} \sim \mathrm{vMF}(e_{2}^{+}, \kappa(e_{2}^{+}))$ ,  $s_{i}^{-} \sim \mathrm{vMF}(e^{-}, \kappa(e^{-}))$ . The concentration, i.e., inverse uncertainty,  $\kappa$  is estimated from a 3-layer MLP attached to the embeddings. Its initial value is either randomly initialized or warmed up to 0.001, which is a hyperparameter. The second hyperparameter is its (inverse) temperature  $t \in [8,64]$ . Like InfoNCE, it uses a reduced batch size of 21 times 96. The loss is obtained by calculating the InfoNCE loss for 16 samples  $s_{i}$  from the respective posteriors.
$$
\mathcal {L} = \frac {1}{1 6} \sum_ {i = 1} ^ {1 6} - t \cdot s _ {1, i} ^ {+} ^ {\top} s _ {2, i} ^ {+} + \log \sum_ {s _ {i} ^ {-} \in \text {B a t c h}} \exp \left(t \cdot s _ {1, i} ^ {+} ^ {\top} s _ {i} ^ {-}\right) + \log \sum_ {s _ {i} ^ {-} \in \text {B a t c h}} \exp \left(t \cdot s _ {2, i} ^ {+} ^ {\top} s _ {i} ^ {-}\right) \tag {2}
$$
B.4 Expected Likelihood Kernel (ELK)
ELK uses a ProxyNCA formulation, as proposed in Kirchhof et al. (2022). Like MCIinfoNCE, it parametrizes posteriors  $\zeta = \mathrm{vMF}(e,\kappa(e))$  from each image's normalized embeddings  $e$  and a 3-layer MLP for  $\kappa$ . Its initial value is either randomly initialized or warmed up to 0.001, which is a hyperparameter. ELK is supervised and learns vMF class distributions  $\rho_c$  for each class  $c = 1,\dots,C$ . The concentrations of these classes are scaled up by the hyperparameter  $t \in [8,64]$ , which takes a
similar role to the inverse temperature in the previous losses. These are compared to the embedding posteriors via a distribution-to-distribution similarity function  $\mathsf{e1k\_sim}$ . This is solved analytically, not requiring sampling. With  $\rho^{*}$  denoting the true class of the given sample, the loss can be written as
$$
\mathcal {L} = - \operatorname {e l k} _ {-} \operatorname {s i m} \left(\zeta , \rho^ {*}\right) + \log \sum_ {c = 1} ^ {C} \exp \left(\operatorname {e l k} _ {-} \operatorname {s i m} \left(\zeta , \rho_ {c}\right)\right). \tag {3}
$$
B.5 Non-isotropic von Mises-Fisher (nivMF)
nivMF (Kirchhof et al., 2022) has the same hyperparameters and loss as ELK, except that the class proxy distributions  $\rho_{c}$  are non-isotropic vMFs. Since the expected-likelihood between the image embeddings' vMFs and the classes' non-isotropic vMFs has no analytical solution, it is Monte-Carlo approximated with 16 samples.
$$
\mathcal {L} = - \text {a p p r o x} _ {\text {e l k}} \text {s i m} (\zeta , \rho^ {*}) + \log \sum_ {c = 1} ^ {C} \exp \left(\text {a p p r o x} _ {\text {e l k}} \text {s i m} (\zeta , \rho_ {c})\right). \tag {4}
$$
B.6 Hedged Instance Embeddings (HIB)
HIB (Oh et al., 2019), like MCInfoNCE, takes samples from estimated posteriors  $s_{n,i} \sim \mathrm{vMF}(e_n, \kappa(e_n))$ , where  $e_n$  are the image's  $L_2$  normalized embeddings  $e_n$  and  $\kappa$  is estimated by a 3-layer MLP. Its initial value is either randomly initialized or warmed up to 0.001, which is a hyperparameter. HIB then calculates a matching probability by comparing the samples of every pair of images  $n, m$  in the batch:  $p_{n,m} = \sum_{i=1}^{16} \text{sigmoid} \left( t \cdot s_{n,i}^{\top} s_{m,i} + b \right)$ , where  $t \in [8,64]$  is a hyperparameter similar to the (inverse) temperature and  $b \in [-8,8]$  is a second hyperparameter. The matching probability should be high for images with the same label and low for images with different labels. Let  $\mathcal{I}_{\text{same}}$  denote the pairs of images with the same label and  $\mathcal{I}_{\text{different}}$  the pairs with different labels, both without self-matches. Then the loss is
$$
\mathcal {L} = - \frac {1}{| \mathcal {I} _ {\text {s a m e}} |} \sum_ {(n, m) \in \mathcal {I} _ {\text {s a m e}}} \log p _ {n, m} + \frac {1}{| \mathcal {I} _ {\text {d i f f e r e n t}} |} \sum_ {(n, m) \in \mathcal {I} _ {\text {d i f f e r e n t}}} \log p _ {n, m}, \tag {5}
$$
where  $|\cdot|$  denotes the cardinality of the set. As opposed to the original implementation, we use cosine distances instead of  $L_{2}$  distances and remove the prior regularizer. This is to make HIB more comparable to the other approaches in this paper. We also changed the second term from encouraging low log match probabilities for different labels  $(- \log (1 - p_{n,m}))$  to discouraging high ones  $(+\log p_{n,m})$ , which stabilized training. HIB requires additional VRAM and thus uses 21 batches of size 96 (43 of size 48 on ViTs).
B.7 Heteroscedastic Classifier (HET-XL)
HET-XL (Collier et al., 2023) predicts a distribution in the embedding space for each image. It then takes samples and calculates a Monte Carlo estimate of the expected model output under the embedding distribution. As opposed to the other probabilistic embedding approaches from above, it operates in Euclidean space by predicting a Gaussian distribution  $\mathcal{N}(\phi(x; \theta), \Sigma'(x; \theta_{\mathrm{cov}}))$  with a low-rank approximation of the covariance matrix  $\Sigma'(x; \theta_{\mathrm{cov}}) = V(x)^{\top}V(x) + \mathrm{diag}(d(x))$ .  $V(x)$  and  $d(x)$  are output by a linear layer attached to the embeddings. The number of columns in  $V$  increases the rank of the low-rank approximation, but also the number of parameters that the final linear layer has to predict, and thus the memory requirements. We thus set this hyperparameter to 1 (exploratory experiments with a rank of 10 did not show increased performance). The final loss is
$$
\mathcal {L} _ {\text {c r o s s - e n t r o p y}} \left(\mathbb {E} _ {\epsilon^ {\prime}} \left[ \operatorname {s f t m a x} _ {\tau} \left(W ^ {\top} \left(\phi (x; \theta) + \epsilon^ {\prime} (x)\right) \right], y\right) \quad \text {w i t h} \quad \epsilon^ {\prime} (x) \sim \mathcal {N} \left(0, \Sigma^ {\prime} (x; \theta_ {\mathrm {c o v}})\right), \right. \tag {6}
$$
where the softmax temperature  $\tau$  is a learnable parameter.
B.8 Spectral-normalized Neural Gaussian Processes (SNGP)
SNGP (Liu et al., 2020) predicts a Gaussian distribution
$$
\left. \mathcal {N} \left(\phi (x) ^ {\top} \beta , \phi (x) ^ {\top} \left(I + \Phi^ {\top} \Phi\right) ^ {- 1} \phi (x)\right) \right. \tag {7}
$$