SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Verify Uncertainty Quality by OOD Detection. Tables 1 and 2 present the OOD detection results of our method compared with competitors on different pairs of datasets. We observe that existing methods, which assume having seen OOD data in the training, perform poorly in our settings, especially when the training observations are limited. Detector [12] yields larger standard errors than other methods since it operates on small samples of the datasets. This validates the argument that existing methods heavily rely upon the availability of OOD data during the training. We also observe that our framework outperforms all the baselines on almost all OOD detection tasks, which demonstrates its satisfactory performance. In particular, our method shows a great improvement on the DRD dataset in which the number of samples is small, indicating the advantage of using a BNN encoder. As the MNIST dataset has dense feature representations, the OOD features can be easily distinguished. Hence, the OOD performance of the methods is relatively better on MNIST than on CIFAR10.
Table 4: The OOD detection performance (in %) of competitive methods under various model architectures [20, 22, 14]. CNN refers to the two-layer standard CNN architecture used by Malinin and Gales [27]. We use CIFAR10 as the in-distribution dataset and SVHN as the OOD dataset. 'Freq' represents the frequentist architecture and 'Bayes' represents the Bayesian architecture.
# of parameters (Freq)	CNN	LeNet	AlexNet	ResNet
31,340	62,006	2,472,266	11,699,522
# of parameters (Bayes)	62,700	125,112	4,922,120	12,372,904
Model	AUROC	AUPR	AUROC	AUPR	AUROC	AUPR	AUROC	AUPR
MC Dropout [10]	63.85	74.79	68.58	78.53	74.72	82.57	61.46	76.04
Deep Ensembles [21]	78.44	89.10	61.01	62.69	72.14	59.83	58.11	78.26
Kendall and Gal [19]	67.77	80.87	55.36	69.82	70.88	73.15	50.01	83.86
EDL [32]	65.26	67.07	66.53	67.12	65.81	61.68	51.34	73.50
DPN [27]	63.98	77.30	57.44	73.84	67.10	80.75	76.36	86.46
PostNet [4]	73.68	66.85	76.04	69.30	81.67	76.52	82.19	79.43
Detectron [12]	73.84	88.50	76.01	90.00	80.58	85.00	78.27	89.50
BNN-ARHT (Ours)	85.36	89.37	82.01	91.61	82.10	70.04	88.16	93.19
Predictive Performance Is Preserved. As shown in Table 3, we also perform image classification to demonstrate the benefits of the post-hoc method (i.e., without modifying the original objective). We fix the neural network architecture as LeNet. For Kendall and Gal [19] and our method, we use the Bayesian counterpart of LeNet to perform the experiment. We observe that without modifying the original learning objective, the predictive performance of the encoder can be preserved and outperforms other methods. The BNN may underperform its frequentist counterpart due to the introduction of the KL regularization. Hence, in practice, a (pre-trained) frequentist encoder can be used to replace the BNN encoder if predictive performance is the focus. Section 5 shows the sacrifice in the OOD detection performance if a frequentist architecture is used.
Visualization of Uncertainty Scores. To better understand the uncertainty scores of in-distribution and OOD data under different uncertainty measures, Figure 4 presents the distributions of the ARHT uncertainty scores of in-distribution data (MNIST) and OOD data (Fashion-MNIST), respectively. We observe that the distributions of ARHT are of different shapes for in-distribution data and OOD data. This demonstrates the effectiveness of ARHT in identifying the unique characteristics of the distributions of the datasets.
5 Ablation Studies
Different Neural Network Architectures. We compare the performance with encoders under different architectures. We choose the standard CNN used in Malinin and Gales [27], LeNet [22], Alexnet [20], and ResNet18 [14] as the SOTA examples in encoding image features. For ResNet18, as the variance increases drastically with the increasing depth of the architecture, it is not feasible to replace all the layers with their Bayesian counterparts. Therefore, we replace only the last fully-connected layer and the second last convolutional layer with their Bayesian versions. Table 4 presents the comparison of OOD
detection of our method with the competitors under different neural network architectures. We observe that our method is able to obtain satisfactory performance over the competitors when the neural network architecture changes.
Figure 4: Distributions of the ARHT uncertainty scores for the in-distribution data (MNIST) and OOD data (Fashion-MNIST), respectively.
Effects of Key Hyperparameters. We evaluate our method with a range of hyperparameters to assess their impacts on our method. Figure 5 presents the OOD detection performance with different values of  $\lambda_0, n_2$ , and  $p$ . (1) Initial loading value  $\lambda_0$ : we observe that the performance of our model is robust to changes in  $\lambda_0$ . Since the ARHT relaxes the Gaussian assumption of embeddings, the change in the magnitude of the loading matrix would not heavily affect the covariance structure of the testing embeddings. Hence we can safely load  $\lambda$  to the covariance matrix to resolve the singularity problem, with no concern about the decrease in performance; (2) Number of training weight samples  $n_1$ :
Figure 5: Performance of our method with different values of  $\lambda_0$  (left),  $n_2$  (middle), and  $p$  (right) by fixing the network architecture as LeNet [22]. We use MNIST as the in-distribution dataset and Fashion-MNIST as the OOD dataset.
The size  $n_1$  is controlled by the hyperparameter  $s$  in our framework. We have conducted experiments with  $s$  ranging from 1 to 5 (Figure 6). The pattern shows that the performance decreases when  $s$  increases (i.e., more embedding samples from the in-distribution dataset). This demonstrates that the covariance structure affects ARHT more as  $s$  increases, and the contribution of testing embeddings is less weighed, which leads to slightly decreasing performance. (3) Number of testing weight samples  $n_2$ : The number of testing weight samples  $n_2$  is a key to approximate the testing embedding distributions. Since the approximation of the testing distribution is crucial to the performance of our method, we tune the hyper-parameter  $n_2$  to determine the optimal number of testing embeddings to choose for each task. We observe that even if the number of testing samples is small (e.g., 5), ARHT can still capture the distributional difference between the in-distribution and OOD data. This leads to a consistent performance as  $n_2$  varies. (4) Embedding dimension  $p$ : we also evaluate the OOD detection performance of our method with respect to the change in embedding dimensions ( $p = 8, 16, 32, 64, 128$ ).
We observe that our method is robust to changes in feature dimensions. This enables our framework to perform OOD detection on the representation level with customized embedding dimensions, relaxing the constraint on classification problems.
Feature Learning Objectives. One key component of our framework is the BNN encoder, which is trained by supervision (i.e., cross-entropy loss for image classification) on standard datasets. We evaluate the robustness of our method when the encoder is trained with different objectives (i.e., unsupervised contrastive learning loss). We select the margin of
contrastive learning loss as 0.2. The performance in AUROC on the OOD detection task decreases slightly from 99.98 to 98.42 (for MNIST vs. OMNIGLOT OOD detection). This shows that our framework is sensitive to the quality of the encoder, and a supervised learning objective is preferred to improve the encoding performance.
Figure 6: Ablation study with respect to  $s$  (In-distribution: CIFAR 10, OOD: SVHN).
6 Discussion: Impacts and Limitations of BNN and ARHT
We discuss why a BNN encoder is preferred for our framework, with Figure 7 illustrating the difference between features generated by BNN and frequentist DNN. A frequentist DNN gives one feature embedding to every input data point, and the uncertainty estimate ignores the covariance structure of the distribution because only the point estimate is provided. However, a BNN estimates the posterior embedding distribution for every data point, and the covariance structure can be incorporated to obtain a more accurate uncertainty estimate. Although some recent non-Bayesian method [32, 27] places parametric distributions on posterior embeddings (e.g., Dirichlet distribution on class probabilities), these parametric distributions are less accurate in approximating the posterior distributions than BNNs because the strong parametric assumption limits their capabilities in searching the candidate distributions.
To demonstrate why ARHT is preferred as an uncertainty metric, we further evaluate its performance over an array of uncertainty measures, including the maximum probability, entropy, and
differential entropy proposed by Malinin and Gales [27]. Detailed definitions of these metrics are presented in the appendix. We also include the frequently used Mahalanobis distance which possesses stronger assumptions on the Gaussianity of the embeddings. We fix the model architecture to be LeNet and compare its Bayesian and frequentist designs. Table 5 presents the summary of the comparison. We observe that using ARHT as the uncertainty score can achieve the best OOD detection performance than existing uncertainty measures when a BNN encoder is used.
Our method achieves a better performance using features generated by BNNs than those generated by frequentist counterparts, which demonstrates the advantage of using Bayesian encoders in our framework. However, BNN encoders require drawing  $n_2$  samples of weights for posterior inference, which requires higher time complexity than the frequentist counterparts. Further, BNNs are limited by the scalability constraints [11], which makes them difficult to have deeper structures. How to make BNNs deep remains a challenging topic [11, 36, 7, 29].
Support of Single-Sample Uncertainty. As the training set (as the in-distribution set) is available (at least for
Figure 7: Comparison of features generated by a frequentist DNN and those by a BNN. The uncertainty estimated by a frequentist DNN ignores the covariance structure of the posterior distribution, where a BNN provides a distributional estimate for each testing sample.
training or fine-tuning the encoder) in most of the problems, one can use samples from training sets and the testing samples to compute ARHT. One exception is the zero-shot case where we only have the pre-trained encoder but no original data (i.e., in-distribution samples). In this case, most of the uncertainty estimation methods cannot work since they require at least in-distribution data to fit their parametric assumptions (e.g., concentration rates of the Dirichlet distributions in classification problems). However, one may still obtain ARHT as an uncertainty estimate using methods to reconstruct/generate pseudo-training data from the pre-trained models, which is not the focus of our work but warrants future research.
7 Related Works
Uncertainty Estimation. Estimating uncertainty in neural networks has become an increasingly important topic in deep learning. Existing uncertainty estimation methods can be divided into two classes: Bayesian methods [19, 23] and non-Bayesian methods [32, 27, 21, 4, 9, 10]. Bayesian methods address the model-wise (i.e., epistemic) uncertainties by learning a posterior distribution of weights. The uncertainties in neural networks can be approximated by the predictions given by the weights sampled from the posterior distributions.
Despite the success of these methods, most works only focus on classification uncertainties and rely upon arbitrary distributional assumptions on the class probabilities. For instance, DPN [27] assumes that the classification probabilities follow a Dirichlet distribution and train the OOD detector based on the KL divergence of the prior and posterior Dirichlet distributions. These methods are not generalizable to tasks other than classification. Furthermore, most existing methods [32, 27, 10] assume that the samples from the target domain are available when training the OOD detector, which is unrealistic in most applications.
Table 5: Performance of the ARHT against other uncertainty measures, with the LeNet [22] architecture, the in-distribution dataset CIFAR10, and the OOD dataset SVHN.
Model	Frequentist	Bayesian
AUROC	AUPR	AUROC	AUPR
Maximum Probability	77.50	64.69	81.30	83.11
Entropy	80.22	88.47	82.49	78.14
Differential Entropy	79.59	86.98	66.15	75.27
RHT	79.06	62.82	82.29	64.07
ARHT	79.07	63.44	82.64	91.69
Hypothesis Testing in High Dimension. The task of uncertainty estimation can be redefined as a high-dimensional hypothesis testing problem. We report the detection of OOD samples if we reject the null hypothesis at significance level  $\alpha$ . The Hotelling  $T^2$  test [15, 18] in Eq. (2) assumes  $T \sim F(p, n - p)$  under the null hypothesis. The unnormalized version of  $T$  in Eq. (2) is known
as Mahalanobis distance. However, the Hotelling test statistic suffers from poor robustness and consistency when  $n$  and  $p$  are large and even becomes undefined when  $p > n$  or when  $S_{n}$  is singular [26]. This results in all test statistics (as uncertainty scores) concentrating on the singular point leading to trivial estimation of uncertainties. Figure 2 presents an example of comparisons of  $F(10,10)$  and  $F(1000,1000)$  to  $\mathcal{N}(0,1)$ . Chen et al. [5] attempt to overcome this issue by proposing the RHT statistic, which resolves the singularity issue of the covariance matrix but yet the inconsistency and poor performance of Hotelling's  $T^2$  statistic under the regime  $p / n \to \gamma$ . Li et al. [26] propose adaptable RHT and design an adaptive selection procedure for the loading parameter  $\lambda$  based on the work of Chen et al. [5], which resolves the inconsistency of Hotelling's  $T^2$ .
Bayesian Deep Learning. SOTA DNN architectures [33, 14, 34] demonstrate significant success in tasks from different domains. Their designs enable them to mine high-dimensional features into low-dimensional representations and address the aleatoric uncertainties. Despite the success, the DNNs typically only yield maximum likelihood estimates of weights under the frequentist framework and cannot address epistemic uncertainties [19]. Existing works of BNN assign prior distributions to the neural network weights so as to obtain the posterior distributions of weights given the observed data [36, 11, 29, 17]. This enables BNN to provide a more accurate approximation to the target distribution and address epistemic uncertainties. Particularly when the training observations are limited, using a BNN can prevent overfitting and generate more representative feature distributions.
We propose a novel uncertainty estimation framework by introducing high-dimensional hypothesis testing to feature representations. We introduce the ARHT as the uncertainty measure which is adaptable to individual data point and robust compared to existing uncertainty measures. Our proposed uncertainty measure operates on latent features and hence can be generalized to any other tasks beyond image classification (e.g., regression or feature representation learning). Empirical evaluations on OOD detection and image classification tasks validate the satisfactory performance of our method over the SOTAs. Ablation studies on key components of the proposed framework validate the robustness and generalizability of our method to variations. One of the best potential applications of our framework is continual learning, where the proposed method can accurately measure the uncertainty as the domain shifts when encountering non-stationary environments. Our framework can be potentially applied to various settings where distributional shifts and OOD detection are vital, such as medical imaging, computational histopathology, and reinforcement learning.
Acknowledgement. We thank the anonymous reviewers, the area chair, and the program chair for their insightful comments on our manuscript. This work was partially supported by the Research Grants Council of Hong Kong (17308321), the Theme-based Research Scheme (T45-401/22-N), and the National Natural Science Fund (62201483).
[1] Xuheng Cai, Chao Huang, Lianghao Xia, and Xubin Ren. Lightgcl: Simple yet effective graph contrastive learning for recommendation. In The Eleventh International Conference on Learning Representations, 2023.
[2] Tsai Hor Chan, Fernando Julio Cendra, Lan Ma, Guosheng Yin, and Lequan Yu. Histopathology whole slide image analysis with heterogeneous graph representation learning. In Proceedings of the IEEE conference on computer vision and pattern recognition, 2023.
[3] Tsai Hor Chan, Chi Ho Wong, Jiajun Shen, and Guosheng Yin. Source-aware embedding training on heterogeneous information networks. Data Intelligence, pages 1-14, 2023.
[4] Bertrand Charpentier, Daniel Zügner, and Stephan Gunnemann. Posterior network: Uncertainty estimation without ood samples via density-based pseudo-counts. Advances in Neural Information Processing Systems, 33:1356-1367, 2020.
[5] Lin S Chen, Debashis Paul, Ross L Prentice, and Pei Wang. A regularized hotelling's t 2 test for pathway analysis in proteomic studies. Journal of the American Statistical Association, 106 (496):1345-1360, 2011.
Overview. In the appendix, we first provide more explanations on the ARHT test statistic in Section A. We then present a detailed summary of the datasets in Section B. Additional experiment results and analysis are reported in Section C. Detailed descriptions of distributions used for BNN training are provided in Section D. We further present the implementation settings, hyperparameters and settings of baseline methods in Section E. We give the definitions of uncertainty measures used for comparison in Section F, together with an algorithm of our framework (Algorithm 1).
A Additional Discussion on ARHT
Why using ARHT? One of our motivations is to formulate uncertainty estimation as a hypothesis testing problem, where we interpret high-dimensional test statistics as distance measures. The ARHT can be viewed as a distance measure between each testing sample and the in-distribution sample, where a larger ARHT indicates the sample is more likely to be OOD. The detection of OOD is then determined by a threshold, while the optimal threshold can be obtained by the Benjamini-Hochberg (BH) procedure. One advantage of ARHT is that it directly operates on the sampling distributions of the latent features, and hence it does not require parametric assumptions on the latent features or logits (e.g., assuming a Dirichlet distribution on class probabilities), which makes it a more robust metric for uncertainty estimation.
Motivation of loading  $\lambda I_{p}$ : This is a standard way to ensure the covariance matrix to be positive definite (and thus invertible) and hence improve the numerical stability.
Why does ARHT follow the standard normal distribution? : The major part of Li et al. [26] is to prove why  $\mathrm{ARHT}(\lambda)$  follows the standard Gaussian distribution. The proof is complex and hence is not focused in this paper. Intuitively,  $\mathrm{ARHT}(\lambda)$  can be viewed as a "standardized" version of RHT (i.e., known as Mahalanobis distance) by its theoretical mean and SD, for which the derivations are detailed in Li et al. [26]
Intuitive explanation and detailed derivation of the BH procedure: Although the BH procedure may not be intuitive to the general audience, it is well-known in the statistics community due to multiple testing issues. Intuitively, we consider the OOD detection procedure for each testing image as a hypothesis testing problem. Then, such a procedure for the whole testing set can be viewed as a multiple-testing problem (i.e., conducting a large number of tests). However, applying a universal threshold for all tests (e.g.,  $\alpha = 0.05$ ) is too conservative and leads to many false discoveries. Hence, the BH procedure is applied to assign a threshold adaptable to each sample according to the  $p$ -values of all tests such that the false discovery rate (FDR) can be minimized.
B Additional Information on Datasets
Table 6 presents a summary of the datasets used for the experiments. We use eight image datasets to evaluate our method, including natural images and medical images.
Table 6: Summary of datasets, including the number of classes for classification, and the split of training and testing sets.
Dataset	No. Classes	No. Training	No. Testing
MNIST	10	60,000	10,000
Fashion-MNIST	10	60,000	10,000
OMNIGLOT	50	13,180	19,280
SVHN	10	73,257	26,032
CIFAR-10	10	60,000	10,000
CIFAR-100	100	60,000	10,000
TinyImageNet	200	80,000	20,000
DRD	2	50	100
Diabetes Retinopathy Detection (DRD). For this experiment, we define in-distribution samples as healthy (no DR; with label 0), and OOD samples as DR (mild, moderate, severe, or proliferative DR; corresponding to labels 1-4). We select 50 healthy images to train the encoder, and compute  $\mu_{1}$  and
$\Sigma_{1}$  from these samples using the trained encoder. For testing, we select 50 images as in-distribution data and 50 images as the OOD data. All images are resized to  $64 \times 64$  for computational convenience. We train the encoder with a task to classify whether the input image is the left eye or right eye. The examples of healthy and DR are presented in Figure 8.
Figure 8: Health and unhealthy (DR) samples from the Diabetes Retinopathy Detection (DRD) dataset [8].
(a) Healthy samples,  $y = 0$
(b) Unhealthy samples,  $y = 1$
We first present the OOD detection results on a more realistic dataset (i.e., TinyImageNet), with a more realistic architecture (e.g., ResNet50). We also include more baseline methods for comparison. Additionally, to study the effect of the encoder quality on OOD detection performance, we use the training accuracy at different epochs to measure the quality of the encoder, and assess how the OOD detection performance changes accordingly.
C.1 More Realistic Datasets.
We have conducted additional experiments on OOD detection, with CIFAR10 as the in-distribution dataset and TinyImageNet as the OOD dataset. The results are presented in Tables 7 and 8, which show that the uncertainty estimation still performs satisfactorily when being generalized to larger datasets.
Table 7: The OOD detection performance (in %) of our method, BNN-ARHT, compared to various competitors, using the LeNet [22] architecture. We use CIFAR 10 as the in-distribution dataset and TinyImageNet as the OOD dataset.
Model	AUC	AUPR
MC Dropout [10]	66.98	64.46
Deep Ensembles [21]	66.41	63.97
Kendall and Gal [19]	63.23	63.06
EDL [32]	51.64	66.31
DPN [27]	61.68	58.33
BNN-ARHT (Ours)	67.77	66.74
C.2 Scalability
We aim to use the Bayesian counterpart of a smaller architecture to demonstrate the capability of BNNs to generate latent feature distributions (for details see the discussion section in the main text). One can generate ideal feature distributions using very large frequentist vision models (e.g., ViT), which however induces enormous complexity in training and inference.
Table 8: The OOD detection performance (in %) of our method, BNN-ARHT, compared with various competitors, using the LeNet [22] architecture. We use TinyImageNet as the in-distribution dataset and CIFAR10 as the OOD dataset.
Model	AUC	AUPR
MC Dropout [10]	64.36	60.47
Deep Ensembles [21]	66.41	63.97
Kendall and Gal [19]	58.54	55.29
EDL [32]	50.37	70.39
DPN [27]	59.59	59.87
BNN-ARHT (Ours)	69.27	71.54
Table 9: The OOD detection performance (in %) of our method, BNN-ARHT, compared with various competitors, using the ResNet50 architecture. We use CIFAR 10 as the in-distribution dataset and SVHN as the OOD dataset.
Model	AUC	AUPR
MC Dropout [10]	68.32	78.24
Deep Ensembles [21]	65.13	82.19
Kendall and Gal [19]	72.24	81.43
EDL [32]	51.21	73.78
DPN [27]	62.33	79.11
Detectron [12]	73.16	82.5
BNN-ARHT (Ours)	73.46	78.27