SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Large-Scale Regression. POVERTYMAP-WILDS [94] is an image-based regression task, where the goal is to better target humanitarian aid in Africa by estimating the asset wealth index of an area using satellite images. As the task is significantly easier when buildings are visible in the images, the evaluation set is split into images containing urban and images containing rural areas. The accuracy of the models is evaluated on both splits by the Pearson coefficient between their predictions and the ground truth, and the worst Pearson coefficient is used as the main evaluation metric. All models are based on a ResNet-18 [32]. See Figure 3 for the Pearson coefficient and sQCE on the o.o.d. evaluation split and Appendix G.3.2 for further details.
Finetuning of CNNs. 1WILDCAM-WILDS [5] is an image classification task that consists of animal photos taken by camera traps across the world. The model's task is to determine which of 182 animal species can be seen in the image. As rare animal species, which are of special interest to researchers, are naturally underrepresented in the dataset, the macro F1 score is used to evaluate the predictive performance. The o.o.d. evaluation split consists of images from new camera locations. All models are based on a ResNet-50 [32]. See Figure 2a for the macro F1 score and sECE on the o.o.d. evaluation split and Appendix G.3.3 for further details. FMOW-WILDS (Functional Map of the World) [9] is an image classification task, where the inputs are satellite images and the class is one of 62 building and land use categories. The o.o.d. evaluation split consists of images from different years than the images in the training set. Models are separately evaluated on five geographical regions of the world, with the lowest accuracy taken as the main evaluation metric. All models are based on a DenseNet-121 [35]. See Figure 2b for the accuracy and sECE for the region of the o.o.d. evaluation split the models perform worst on and Appendix G.3.4 for further details. RXRx1-WILDS [85] is an image classification task, where the inputs are three-channel images of cells, and the classes are 1139 applied genetic treatments. The o.o.d. evaluation split is formed by images from different experimental batches than the training data. Following Koh et al. [47], we only use three of the six available input channels to limit the computational complexity of the models. This makes the task considerably harder and leads to the low accuracy of the models, but makes our results comparable to those of Koh et al. [47]. All models are based on a ResNet-50 [32]. See Figure 2c for the accuracy and sECE on the o.o.d. evaluation split and Appendix G.3.5 for further details.
Finetuning of Transformers. CIVIL COMMENTS-WILDS [8] is a binary text classification dataset, where the model's task is to classify whether a given comment is toxic or not. The comments are grouped based on whether they mention certain demographic groups, such as LGBTQ or Muslim identities. Models are evaluated based on the group on which they achieve the lowest accuracy on the evaluation set. All models are based on the DistilBERT architecture [76]. See Figure 4a for the accuracy and sECE on the group of the o.o.d. evaluation split the models perform worst on and Appendix G.3.6 for further details. Amazon-WILDS [68] consists of textual product reviews, where
(a) IWILDCAM-WILDS
(c) RXRx1-WILDS
(b) FMOw-WILDS
Figure 2: Accuracy Metrics vs. sECE on the o.o.d. evaluation splits of the image classification finetuning tasks IWILDCAM-WILDS, FMOW-WILDS, and RXRx1-WILDS. Note the split y-axis in Figure 2c. All MultiX algorithms are more accurate and better calibrated than any single-mode approximation. Except for RXRx1, BBB is better calibrated than MCD and SWAG. iVON's calibration is inconsistent: On IWILDCAM it is better calibrated than BBB, but on FMOW it barely performs better than MAP. On RXRx1, the VI algorithms except for SVGD are significantly less accurate than all other models. We experimented with different hyperparameters in Appendix G.3.5. Laplace is very well calibrated on IWILDCAM, but underperforms on FMOW and RXRx1. SVGD performs very similarly to MAP regarding both metrics, even though it uses a multi-mode posterior approximation.
the task is to predict the star rating from one to five. The o.o.d. evaluation split consists of reviews from reviewers that are not part of the training split. Models are evaluated based on the accuracy of the reviewer at the  $10\%$  quantile. All models are based on DistilBERT [76]. See Figure 4b for the accuracy and sECE on the o.o.d. evaluation split and Appendix G.3.7 for further details.
5.2 The Corrupted CIFAR-10 Dataset
CIFAR-10-C [33] is a corrupted version of the evaluation split of the image classification dataset CIFAR-10 [48], where images are corrupted with increasing levels of noise, blur, and weather and digital artifacts. We compare the considered algorithms on the standard evaluation split of CIFAR-10 as well as the corruption levels 1, 3, and 5 of CIFAR-10-C. Following Izmailov et al. [37], all of our models on CIFAR-10-(C) are based on the ResNet-20 architecture. See Appendix G.3.6 for details.
5.3 Generalization to Realistic Distribution Shift
We measure the generalization capability of the models with the task-specific accuracy metrics proposed by Koh et al. [47] that are based on the real-world origin of the respective tasks. The metrics typically emphasize the performance on groups or classes that are underrepresented in the training data, as avoiding bias against these groups is crucial in safety-critical applications of BDL.
Except for the text classification tasks, MultiX always generalizes better than single-mode posterior approximations. Overall, the relative ordering of the MultiX models depends on the dataset and in many cases does not correlate with the relative ordering of the corresponding single-mode approximations.
Large-Scale Regression. All models achieve similar Pearson coefficients, with MultiX being slightly more accurate. The Deep Ensemble is competitive with the best performing algorithm of the WILDS leaderboard with a Pearson coefficient of 0.52 compared to 0.53 of C-Mixup [92]. However, due to the large standard errors resulting from the different difficulties of the folds, the results are not significant. Note that Koh et al. [47] report similarly large standard errors.
Finetuning of CNNs. Confirming the overall trend, MultiX models generalize better than single-mode models, with MultiSWAG and MultiMCD performing particularly well. Except for RXRx1 the
models perform competitively with the best models from the WILDS leaderboard. On iWILDCAM, the single-mode posterior approximations SWAG and MCD are competitive with the Deep Ensemble. SVGD performs similarly to MAP, even though it is based on an ensemble, likely due to the repulsive forces pushing the particles away from the well-performing pre-trained model. While the VI algorithms' accuracy is similar to the accuracy of MAP on iWILDCAM and FMOW, all VI algorithms except SVGD perform significantly worse than the non-VI algorithms on RXRx1. Laplace is well calibrated on iWILDCAM, but significantly less accurate than the other algorithms on FMOW and RXRx1. This seems to represent a fundamental approximation failure of Laplace, and not only a sampling issue, since increasing the number of samples lead to only a small increase in accuracy (see Appendix G.3.4 and Appendix G.3.5).
Finetuning of Transformers. BBB and Rank-1 VI are the most accurate models on both tasks, with no benefit from the multiple components of Rank-1 VI. Interestingly, iVON is significantly less accurate than BBB, even though it is also based on mean-field VI, indicating that the natural gradient-based training is disadvantageous on the transformer-based BERT architecture. To see whether the better performance of BBB is due to less regularization compared to MAP, we also experiment with a smaller weight decay factor for MAP on CIVILCOMMENTS. While we find that the accuracy increases, BBB is still more accurate (see Appendix G.3.6). Finally, we also check whether the better performance of BBB is due to its last-layer nature. We experiment with last-layer versions of MCD and SWAG on AMAZON (see Appendix G.3.7), but find that both are still significantly less accurate than BBB.
MultiX is no more accurate than the corresponding single-mode approximation, contrary to the results on all other datasets. We suspect that this effect is to a large part due to the finetuning nature of the tasks, where all ensemble members start close to each other in parameter space and therefore converge to the same posterior mode. Note that the failure of ensembles is most likely due to the task and the network architecture and not due to the training procedure: While we train for fewer epochs than on the image classification tasks, the datasets are larger. On IWILDCAM we perform 97k parameter updates, compared to 84k parameter updates on CIVIL COMMENTS.
Figure 3: POVERTYMAP-WILDS: Worst urban/rural Pearson coefficient between the model's predictions and the ground truth plotted against the sQCE on the o.o.d. test split of the image-based regression task. All models achieve similar, but noisy [47], Pearson coefficients, indicating similar generalization capabilities. Multi-mode approximations are consistently better calibrated than single-mode approximations (note that Rank-1 VI's components and SVGD's particles give them multi-mode approximation capabilities). Regarding calibration, the relative ordering of the single-mode models does not translate to the MultiX models: BBB is among the best-calibrated single-mode models, but MultiBBB is the worst calibrated MultiX model. Laplace and SWAG are very similarly calibrated, therefore the data points of SWAG are hidden behind the data points of Laplace. iVON performs significantly worse than the other algorithms and is therefore excluded.
5.4 Calibration under Realistic Distribution Shift
We measure calibration with the sECE for classification tasks and with the sQCE for regression tasks (see Section 4). We additionally report the unsigned ECE/QCE and the log-likelihood for the regression task in Appendix G.
MultiX is almost always less overconfident than single-mode approximations. When all models are already comparatively well calibrated, MultiX tends to become underconfident. Thus, we find that MultiX is typically only less confident, but not automatically better calibrated than single-mode approximations. On the transformer-based text classification tasks, MultiX is almost never better calibrated than the respective single-mode approximation.
Large-Scale Regression. MultiX, when based on a probabilistic single-mode approximation, is generally better calibrated than the Deep Ensemble. SVGD is better calibrated than the Deep Ensemble, showing the benefit of the repulsive forces between the particles. Rank-1 VI is the best calibrated model, indicating that multi-modality over all parameters as with the Deep Ensemble is not necessary to capture the multi-modality of the parameter posterior.
Finetuning of CNNs. Again, we find that MultiX generally performs better than a Deep Ensemble. However, MultiSWAG in particular is more overconfident than the Deep Ensemble, even though SWAG is better calibrated than MAP. BBB is better calibrated than other single-mode approximations such as SWAG and MCD. Rank-1 VI performs similar to BBB on all tasks, indicating that the low-rank components are not sufficient to capture the multi-modality of the parameter posterior in the finetuning setting. On IWILDCAM, Laplace is the best calibrated single-mode approximation, and correspondingly MultiLaplace is the most underconfident multi-mode approximation. This result is unique to IWILDCAM, as Laplace tends to be overconfident on the other image classification datasets.
Finetuning of Transformers. Except for MultiBBB on Amazon, ensembles are similarly calibrated than the respective single-mode approximations. SWAG is the least confident model on both tasks, which leads to underconfidence on Amazon. MCD's calibration is inconclusive, as it is better calibrated than MAP on Amazon, but more overconfident on CIVIL COMMENTS. BBB and Rank-1 VI are not better calibrated than MAP and on Amazon significantly more overconfident than MAP.
5.5 Posterior Approximation Quality
While approximate inference is commonplace in BDL, the large size of the neural networks typically makes it computationally intractable to measure how well a model approximates the true parameter posterior. Following Wilson et al. [90] and using the HMC samples provided by Izmailov et al. [37], we measure how well the models approximate the predictive distribution of HMC by the total variation (TV) between the model's predictions and HMC and the top-1 agreement with HMC on CIFAR-10-(C) [33, 48]. While the TV in the predictive space is indicative of the parameter posterior approximation quality, it does not allow for definite conclusions about the parameter space. Figure 5 displays the TV of the evaluated models under increasing levels of image corruption. For further results regarding the accuracy, sECE, ECE, and top-1 agreement with HMC see Appendix G.2.
Overall, a good probabilistic single-mode approximation is the most important factor for a good posterior approximation. MultiX, when based on probabilistic single-mode approximations, consistently approximates the parameter
posterior better than single-mode-only approximations and the Deep Ensemble. MultiiVON approximates the posterior best across all corruption levels as measured by the TV, with MultiSWAG being a close contender. Even single-mode approximations such as MCD and SWAG achieve better TVs
(a) CIVIL COMMENTS-WILDS
(b) AMAZON-WILDS
Figure 4: Text classification with pretrained transformers. Except for Multi-BBB on AMAZON-WILDS, MultiX performs nearly identically to the corresponding single-mode approximation. VI improves the accuracy of the models. MCD is the least accurate model on CIVILCOMMENTS. We experiment with different dropout rates in Appendix G.3.6 but find that MCD never outperforms MAP.
Figure 5: CIFAR-10-(C): Total variation (TV, smaller is better) between the model's predictions and HMC's predictions on the evaluation split of CIFAR-10 (corruption 0) and under increasing levels of image corruption by noise, blur, and weather and digital artifacts (corruption 1, 3, 5). MultiX consistently approximates the posterior better than the corresponding single-mode approximations, with MultiiVON and MultiSWAG achieving the smallest TV. The single-mode approximations SWAG, MCD, and iVON approximate the posterior better than the Deep Ensemble.
under data corruption than the Deep Ensemble. As expected, MAP has the highest TV, with only a small improvement made by Laplace.
We presented a comprehensive evaluation of a wide range of modern, scalable BDL algorithms, using distribution-shifted data based on real-world applications of deep learning. We focused on the generalization capability, calibration, and posterior approximation quality under distribution shift. Overall, our analysis resulted in the following takeaway messages:
1. Finetuning only the last layers of pre-trained models with BDL algorithms gives a significant boost of generalization accuracy and calibration on realistic distribution-shifted data, while incurring a comparatively small runtime overhead. These models are in many cases competitive to or even outperform methods that are specially designed for OOD generalization such as IRM [3] and Fish [80].
2. For CNNs, ensembles are more accurate and better calibrated on OOD data than single-mode posterior approximations by a wide margin, even when initializing all ensemble members from the same pre-trained checkpoint with only the last layers differently initialized, i.e. when not using the standard protocol of randomly initializing all ensemble members. Ensembling probabilistic single-mode posterior approximations such as SWAG or MCD yields only a small additional increase in accuracy and calibration.
3. When finetuning large transformers, ensembles, which are typically considered to be the SOTA in BDL, yield no benefit. Compared to all other evaluated BDL algorithms, classical mean-field variational inference achieves significant accuracy gains under distribution shift.
Limitations. While we evaluate on a wide range of datasets from different domains and using different network architectures, the choice of tasks is still limited. In particular, we do not consider LSTMs [34] as Ovadia et al. [72] do. Given the limitations of WILDS [47], we evaluate on a single large-scale regression dataset. As both text classification experiments use DistilBERT [76], it is conceivable that the failure of ensembles is limited to this particular architecture. We do not include algorithms that are based on function-space priors [30, 56, 75, 84]. Except for the results on CIFAR-10-(C) and POVERTYMAP, all results were obtained by finetuning pre-trained models and are therefore only valid in this setting. The HMC samples used in Section 5.5 have been criticized for not faithfully representing the true parameter posterior due to low agreement between the predictions of different chains [78].
Broader Context. Bayesian deep learning aims to provide reasonable uncertainty estimates in safety-critical applications. Hence, we do not expect any societal harm from our work, as long as it is ensured by proper evaluation that accuracy and calibration requirements are met before deployment.
This work was supported by funding from the pilot program Core Informatics of the Helmholtz Association (HGF). The authors acknowledge support by the state of Baden-Württemberg through bwHPC, as well as the HoreKa supercomputer funded by the Ministry of Science, Research and the Arts Baden-Württemberg and by the German Federal Ministry of Education and Research.
[93] J. Yao et al. “Quality of Uncertainty Quantification for Bayesian Neural Network Inference”. In: Proceedings at the International Conference on Machine Learning: Workshop on Uncertainty & Robustness in Deep Learning (ICML). 2019.
[94] Christopher Yeh et al. "Using publicly available satellite imagery and deep learning to understand economic well-being in Africa". In: Nature Communications 11.1 (May 2020).
[95] Wei Zhao et al. "3D Deep Learning from CT Scans Predicts Tumor Invasiveness of Subcentimeter Pulmonary Adenocarcinomas". In: Cancer Research 78.24 (2018), pp. 6881-6889.
A Approximate Inference
This section provides further details on the algorithms introduced in Section 3.1.
A.1 Variational Inference
Variational inference (VI) minimizes the KL divergence [50] between the true posterior  $p(\pmb{\theta} \mid \mathcal{D})$  and the approximate posterior  $q(\pmb{\theta} \mid \mathcal{D})$  [6]. While the KL divergence cannot be computed by itself, as the true posterior is unknown, it can still be minimized by maximizing the evidence lower bound (ELBO) given the parameter prior  $p(\pmb{\theta})$ :
$$
\operatorname {E L B O} = \underset {\boldsymbol {\theta} \sim q (\boldsymbol {\theta} \mid \mathcal {D})} {\mathbb {E}} [ \log p (\mathcal {D} \mid \boldsymbol {\theta}) ] - \operatorname {K L} [ q (\boldsymbol {\theta} \mid \mathcal {D}) | | p (\boldsymbol {\theta}) ] \tag {4}
$$
Maximizing the ELBO means maximizing the likelihood of the training data, therefore fitting the data well, while staying close to the parameter prior [6].
Bayes By Backprop (BBB). BBB [7] is an application of VI to deep neural network. BBB approximates the parameter posterior with a diagonal Gaussian distribution that cannot model covariances between parameters. The per-parameter means and variances are learned with standard Stochastic Gradient Descent (SGD) [42] using the negative of the ELBO as the loss function. The ELBO by itself is not differentiable as it depends on the randomly chosen parameters. However, the reparameterization trick [44] applies to diagonal Gaussians and allows us to use the negative ELBO as the loss function. Further runtime performance improvements are possible by using the local reparameterization trick [45] or Flipout [88].
While there have been reports of BBB performing well when used on neural networks [7, 86], the current consensus of the research community seems to be that BBB falls short when compared to e.g. ensembles [20, 72, 89], even though it has been shown that the diagonal Gaussian posterior is not significantly less expressive than a posterior that models covariances [18, 20]. In recent years significant work has been done to improve the performance of VI in a deep learning setting. To assess whether these improved algorithms can compete with SOTA Bayesian algorithms, we also evaluate promising improvements on posterior parameterizations (Rank-1 VI, SVGD) and optimization procedures (iVON).
Rank-1 Variational Inference (Rank-1 VI). Rank-1 VI [17] enhances the posterior approximation of BBB by approximating a full-rank covariance matrix with a low-rank approximation. Rank-1 VI learns a diagonal Gaussian distribution over two vectors per layer, whose outer product is then element-wise multiplied to a learned point estimate of the layer's weights. The bias vector is kept as a point estimate. The limited number of additional parameters allows Rank-1 VI to learn a multi-component Gaussian distribution for the two low-rank vectors, which gives Rank-1 VI ensemble-like properties. Rank-1 VI is both less expressive than BBB with the mean field approximation in the sense that it has fewer variational parameters, and is more expressive as it can model covariances between parameters within a layer and can express multi-modality in a limited way.
Improved Variational Online Newton (iVON). The usage of SGD for the optimization of variational parameters is problematic, as these parameters form a complex, non-euclidean manifold [41]. Natural gradient descent (NGD), recently formalized as the Bayesian learning rule [39], exploits this structure to speed up training. VOGN [41, 70] applies NGD to neural networks but has scaling problems, as it requires per-example gradients in minibatch training. iVON, based on the improved Bayesian learning rule [53], no longer has this problem. While iVON still uses the mean-field approximation of BBB, it is expected to converge faster, and, importantly, halves the number of trainable parameters by implicitly learning per-parameter variances.
Stein Variational Gradient Descent (SVGD). SVGD [55] is a non-parametric VI algorithm that does not assume the posterior to be of a particular shape but approximates it with  $p$  particles (i.e. point estimates). The particles can be viewed as members of a Deep Ensemble [51], and the use of VI adds a repulsive component to the loss function based on the RBF kernel distance between the parameters of the particles. While this repulsive component can prevent the particles from converging to the same posterior mode, it prohibits the independent training of the particles.
A.2 Other Algorithms
Deep Ensembles. Lakshminarayanan et al. [51] introduce Deep Ensembles that combine the predictions of multiple independently trained neural networks to improve uncertainty estimates. Originally, Deep Ensembles have been seen as a competing approach to Bayesian algorithms [51]. However, ensembles can be considered to be a Bayesian algorithm that approximates the posterior with a sum of delta distributions [89]. We consider all ensembles to be Bayesian: While they are missing the principled posterior approximation approach of VI, basically hoping that the members converge to different posterior modes, the approach results in a posterior approximation that is in many cases better than the approximation of for example BBB (Section 5, [72, 89]).
Ensembles are usually considered SOTA in uncertainty estimation [72, 89]. However, the training time scales linearly in the number of ensemble members. This makes them highly expensive in cases where training a single member is already expensive, such as with large networks, and opens the space for new, cheaper posterior approximations.