SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Jianing Zhu $^{1}$  Geng Yu $^{2}$  Jiangchao Yao $^{2,3}$  Tongliang Liu $^{4}$
Gang Niu $^{5}$  Masashi Sugiyama $^{5,6}$  Bo Han $^{1,5\dagger}$
$^{1}$ Hong Kong Baptist University  $^{2}$ CMIC, Shanghai Jiao Tong University
$^{3}$ Shanghai AI Laboratory  $^{4}$ Sydney AI Centre, The University of Sydney
$^{5}$ RIKEN Center for Advanced Intelligence Project  $^{6}$ The University of Tokyo
{csjnzhu, bhanml} @comp.hkbu.edu.hk
{warriors30, sunarker} @sjtu.edu.cn tongliang.liu@sydney.edu.au
Out-of-distribution (OOD) detection is important for deploying reliable machine learning models on real-world applications. Recent advances in outlier exposure have shown promising results on OOD detection via fine-tuning model with informatively sampled auxiliary outliers. However, previous methods assume that the collected outliers can be sufficiently large and representative to cover the boundary between ID and OOD data, which might be impractical and challenging. In this work, we propose a novel framework, namely, Diversified Outlier Exposure (DivOE), for effective OOD detection via informative extrapolation based on the given auxiliary outliers. Specifically, DivOE introduces a new learning objective, which diversifies the auxiliary distribution by explicitly synthesizing more informative outliers for extrapolation during training. It leverages a multi-step optimization method to generate novel outliers beyond the original ones, which is compatible with many variants of outlier exposure. Extensive experiments and analyses have been conducted to characterize and demonstrate the effectiveness of the proposed DivOE. The code is publicly available at: https://github.com/tmlr-group/DivOE.
Out-of-distribution (OOD) detection [Nguyen et al., 2015, Hendrycks and Gimpel, 2017] gains increasing attention in deploying machine learning models into open-world scenarios, as deep learning systems are expected to conduct reliable predictions on in-distribution (ID) data while identifying OOD inputs [Bommasani et al., 2021, Hendrycks et al., 2022]. It becomes more critical in safety-critical applications like financial or medical intelligence, where the false prediction for samples out of pre-defined label space can sometimes be a disaster. Extensive explorations [Hendrycks et al., 2019, Liu et al., 2020, Tack et al., 2020, Mohseni et al., 2020, Sehwag et al., 2021, Yang et al., 2021, 2022] in recent years has been contributed to improving the model ability for OOD detection.
Compared with post-hoc methods [Hendrycks and Gimpel, 2017, Liang et al., 2018, Liu et al., 2020, Huang et al., 2021, Sun et al., 2022] which designs different score functions for OOD uncertainty estimation, Outlier Exposure (OE) [Hendrycks et al., 2019] is another kind of method owning better performance improvement on OOD detection [Mohseni et al., 2020, Sehwag et al., 2021, Ming et al., 2022, Katz-Samuels et al., 2022, Wang et al., 2023]. The latter engages surrogate OOD data during
$^{\dagger}$ Correspondence to Bo Han (bhanml@comp.hkbu.edu.hk).
Figure 1: Illustration about the research problem on auxiliary outliers studied in our work for OE. Left panel: the general assumption on the auxiliary outliers, in which the surrogate OOD distribution  $\mathcal{D}_{\mathrm{out}}^s$  can not always be broad enough to well represent the unseen OOD distribution  $\mathcal{D}_{\mathrm{out}}$  since it is impractical or even infeasible to accurately pre-define and collect those boundary outliers (especially those close to  $\mathcal{D}_{\mathrm{in}}$ ); Right panel: an empirical verification on OOD detection performance (evaluated by FPR95, the lower is the better) with the gradually decreased number of given auxiliary outliers. Our proposed DivOE can perform better via extrapolation than previous sampling-based methods, given different numbers of auxiliary outliers. More experimental details are provided in Appendix C.
training and regularizes the model via fine-tuning those auxiliary outliers. The conceptual idea is to learn the knowledge from auxiliary outliers for effectively identifying OOD inputs. Under such a learning framework, there is an intuitive gap between the surrogate OOD data and the unseen OOD inputs [Fang et al., 2022, Ming et al., 2022] as illustrated in Figure 1. It will be a fundamental problem for boosting the model's discriminative capability on the OOD inputs. Given the finite auxiliary outliers, it naturally motivates the following critical research question: How could we utilize the given outliers for effective OOD detection if the auxiliary outliers are not informative enough?
Addressing the essential distribution gap between surrogate OOD data and the unseen OOD inputs remains challenging [Hendrycks et al., 2019, Fang et al., 2022, Du et al., 2022, Yang et al., 2021], as it is hard to know the prior knowledge of potential OOD inputs would be encountered at inference stage [Hendrycks et al., 2022], and intentionally collect them. As the unseen OOD inputs in the real-world scenarios are complex [Cimpoi et al., 2014, Yu et al., 2015, Yang et al., 2022], the performance of OE-based methods is heavily affected by the given auxiliary outliers (as empirically presented in Figure 2). Given the finite auxiliary outliers, the surrogate OOD data are expected to have less discrepancy [Hendrycks et al., 2019, Fang et al., 2022] with the unseen OOD inputs, especially for the ones that are close to the decision boundary. Therefore, a potential idea is to expand the given outliers to cover more informative distributions and better generalize to the unseen OOD inputs.
Based on the previous analysis, we propose a new learning framework, i.e., Divsified Outlier Exposure (DivOE), to alleviate the pessimism of limited informative auxiliary outliers. At the high level, we aim to diversify the current distribution represented by the surrogate OOD data (e.g., Figure 2). In detail, we introduce a novel learning objective (i.e., Eq. (4)) that conducts informative extrapolation based on the given auxiliary outliers. Through a multi-step optimization target for generating a fraction of more informative outliers, DivOE can adaptively extrapolate and learn beyond the original OOD distribution. It realizes expanding the overall surrogate distribution of OOD data toward a broader coverage by maximizing the difference between the extrapolated one with its original counterpart.
We conduct extensive experiments to characterize and present our proposed methods. We have verified its effectiveness with a series of OOD detection benchmarks mainly on two common ID datasets, i.e., CIFAR-10 and CIFAR-100, and also demonstrated its scalability using the ImageNet dataset with the large-scaled auxiliary outliers sampled from ImageNet21K. Under the various evaluations, our DivOE via informative extrapolation, can obtain the better OOD discriminative capability for the models and consistently achieve the lower averaged FPR95 compared with different baselines. Finally, a range of ablation studies from various aspects of the learning framework and further discussions from different perspectives are provided. Our main contributions are summarized as follows,
- Conceptually, we study a more general and practical research setting in outlier exposure for OOD detection, considering the auxiliary outliers having limited information that can not well represent the whole decision areas for ID and OOD data. (in Section 3.1)
- Technically, we propose a novel learning framework, namely Diversified Outlier Exposure (DivOE), for facilitating fine-tuning with auxiliary outliers, which conducts informative extrapolation to adaptatively diversify outlier exposure. (in Sections 3.2 and 3.3)
- Empirically, extensive explorations from different perspectives are conducted to verify the effectiveness of DivOE in improving OOD detection performance, and we perform various ablations or further discussions to provide a thorough understanding. (in Section 4)
In this section, we briefly introduce the preliminaries and related work in OOD detection.
We consider multi-class classification as the original training task [Nguyen et al., 2015], where  $\mathcal{X} \subset \mathbb{R}^d$  denotes the input space and  $\mathcal{Y} = \{1, \dots, C\}$  denotes the label space. A reliable classifier should be able to figure out the OOD input, which can be considered a binary classification problem. Given  $\mathcal{P}$ , the distribution over  $\mathcal{X} \times \mathcal{Y}$ , we consider  $\mathcal{D}_{\mathrm{in}}$  as the marginal distribution of  $\mathcal{P}$  for  $\mathcal{X}$ , namely, the distribution of ID data. At test time, the environment can present a distribution  $\mathcal{D}_{\mathrm{out}}$  over  $\mathcal{X}$  of OOD data. In general, the OOD distribution  $\mathcal{D}_{\mathrm{out}}$  is defined as an irrelevant distribution of which the label set has no intersection with  $\mathcal{Y}$  and thus should not be predicted by the model  $f(\cdot)$ . A decision model  $g(\cdot)$  can be made with the threshold  $\lambda$ :
$$
g _ {\lambda} (x; f) = \left\{ \begin{array}{l l} \mathrm {I D} & S (x; f) \geq \lambda \\ \text {O O D} & S (x; f) <   \lambda \end{array} , \right. \tag {1}
$$
Building upon the model  $f \in \mathcal{H} : \mathcal{X} \to \mathbb{R}^c$  trained on ID data with the logit outputs, the goal of decision is to utilize the scoring function  $S : \mathcal{X} \to \mathbb{R}$  to distinguish the inputs of  $\mathcal{D}_{\mathrm{in}}$  from that of  $\mathcal{D}_{\mathrm{out}}$  by  $S(x; f)$ . If the score value is larger than the threshold  $\lambda$ , the associated input  $x$  is classified as ID and vice versa. We consider several representative scoring functions designed for OOD detection in our exploration, e.g., MSP [Hendrycks and Gimpel, 2017], ODIN [Liang et al., 2018], and Energy [Liu et al., 2020]. More detailed definitions are provided in Appendix A.
To mitigate the issue of over-confident predictions for [Hendrycks and Gimpel, 2017, Liu et al., 2020] some OOD data, another line of research directions [Hendrycks et al., 2019, Tack et al., 2020] utilize the auxiliary unlabeled dataset to regularize the model behavior. Among them, one representative baseline is outlier exposure (OE) [Hendrycks et al., 2019]. OE can further improve the detection performance by making the model  $f(\cdot)$  finetuned from a surrogate OOD distribution  $\mathcal{D}_{\mathrm{out}}^{\mathrm{s}}$ , and its corresponding learning objective is defined as follows,
$$
\mathcal {L} _ {\mathrm {O E}} = \mathbb {E} _ {\mathcal {D} _ {\text {i n}}} \left[ \ell_ {\mathrm {C E}} (f (x), y) \right] + \lambda \mathbb {E} _ {\mathcal {D} _ {\text {o u t}} ^ {\mathrm {s}}} \left[ \ell_ {\mathrm {O E}} (f (x)) \right], \tag {2}
$$
where  $\lambda$  is the balancing parameter,  $\ell_{\mathrm{CE}}(\cdot)$  is the Cross-Entropy (CE) loss, and  $\ell_{\mathrm{OE}}(\cdot)$  is the Kullback-Leibler divergence to the uniform distribution, which can be written as  $\ell_{\mathrm{OE}}(h(x)) = -\sum_k\operatorname{softmax}_k f(x) / C$ , where  $\operatorname{softmax}_k(\cdot)$  denotes the  $k$ -th element of a softmax output. The OE loss  $\ell_{\mathrm{OE}}(\cdot)$  is designed for model regularization, encouraging the model to learn knowledge from the surrogate OOD inputs and return low-confident predictions [Hendrycks and Gimpel, 2017].
OOD Detection. [Hendrycks and Gimpel, 2017] formally benchmarks the OOD detection problem, proposing to use softmax prediction probability as a conventional baseline method. Subsequent works [Sun et al., 2021] keep focusing on designing post-hoc metrics to distinguish ID samples from OOD samples, among which ODIN [Liang et al., 2018] introduces small perturbations into input images to facilitate the separation of softmax score, Mahalanobis distance-based confidence score [Lee et al., 2018b] exploits the feature space by obtaining conditional Gaussian distributions, energy-based score [Liu et al., 2020] aligns better with the probability density. Except directly designing new score functions, some works [Lin et al., 2021, Sun et al., 2022, Djurisic et al., 2023] pay attention to various aspects to enhance the OOD detection such that LogitNorm [Wei et al., 2022] produces confidence scores by training with a constant vector norm on the logits, DICE [Sun and Li, 2022] reduces the variance of the output distribution by leveraging the model sparsification, and ASH [Djurisic et al., 2023] explores the manipulation of feature representation to enhance OOD detection. In addition, Zhu et al. [2023] improves detection performance by investigating the quality of ID data.
OOD Detection with Auxiliary Outliers. Another promising direction toward OOD detection involves the auxiliary outliers for model regularization. From the data perspective, some works
Figure 2: Empirical demonstration about informative outliers in OE and the diversification effect of the proposed DivOE. In the two left panels, we illustrate auxiliary outliers in different informative levels and divide them into five groups according to the degree of diversity. Empirically, we show that the OOD detection performance of OE can be benefited by the most diversified Group1 among these trials. We leave the experimental details in Appendix C for reference. In the two right panels, we compare the TSNE visualization of the original outliers with our extrapolated outliers in DivOE.
explore generating virtual outliers such that VOS [Du et al., 2022] and NPOS [Tao et al., 2023] regularize the decision boundary by adaptively sampling virtual outliers from the low-likelihood region. On the other hand, other works exploit information from natural outliers, such that outlier exposure is introduced by [Hendrycks et al., 2019], given that real OOD data are available in enormous quantities. Recently, some works highlight the importance of sampling strategy, such that NTOM [Chen et al., 2021] greedily utilizes informative auxiliary data to tighten the decision boundary for OOD detection, and POEM [Ming et al., 2022] adopts Thompson sampling to contour the decision boundary precisely. The performance of training with outliers is usually superior to that without outliers, as shown in many other works [Fort et al., 2021, Salehi et al., 2021, Sun et al., 2023]. From the optimization perspective, Wang et al. [2023] introduces implicit regularization via model perturbation, and Wang et al. [2022], Yang et al. [2023] present early trials to improve OOD performance in terms of the AUROC with tighter generalization bounds and new evaluation metrics.
3 Method: Diversified Outiler Exposure
In this section, we introduce our new framework, i.e., Diversified Outlier Exposure (DivOE), which conducts informative extrapolation during fine-tuning with auxiliary outliers. First, we present and discuss the critical motivation that inspires our method (Section 3.1). Second, we introduce its newly derived learning objective and explain the underlying implications (Section 3.2). Lastly, we present the algorithmic realization of DivOE and discuss its compatibility with other methods (Section 3.3).
First, collecting OOD samples near the boundary still remains challenging as we can hardly know which kind of samples are truly located in the decision boundary between ID and OOD space. Second, as empirically shown in the left-middle panel of Figure 2, if the auxiliary outliers are not sufficiently informative (e.g., less diversified), the performance of outlier exposure will be limited due to the under-represented OOD distributions, which can be reflected by the higher FPR95 score (indicating a higher error on OOD detection). Thus, it naturally arises the following research question,
How could we utilize the given outliers for effective OOD detection if the auxiliary outliers are not informative enough to represent the unseen OOD distribution?
Especially for those OOD inputs that are close to the decision boundary, the auxiliary outliers may not well characterize such a broad distributional area [Fang et al., 2022, Wang et al., 2023, Zhang et al., 2023]. Therefore, a new mechanism is required to diversify the outlier exposure by exploring more potential OOD distribution for effective OOD detection. As in the right two panels of Figure 2, DivOE realizes this expectation by explicitly extrapolating the OOD data engaged during training.
3.2 DivOE via Informative Extrapolation
As aforementioned, the OE paradigm heavily relies on the auxiliary outliers sampled from the surrogate OOD distribution. Given the auxiliary outliers that are not informative enough to represent the
unseen OOD data, the model is expected to learn beyond the current surrogate OOD distribution. One conceptual idea to achieve this goal is to extrapolate based on the current surrogate distribution. Under such a concurrent learning paradigm, the model can be regularized by the original surrogate OOD distribution and simultaneously generalize beyond the given auxiliary outliers for OOD detection. To this intuition, we consider an adaptively evolved version of the surrogate OOD distribution  $\mathcal{D}_{\mathrm{out}}^s$  under the learning framework of OE as follows,
$$
\mathcal {L} _ {\mathrm {O E}} ^ {*} = \mathbb {E} _ {\mathcal {D} _ {\text {i n}}} \left[ \ell_ {\mathrm {C E}} (f (x), y) \right] + \lambda \mathbb {E} _ {\mathcal {D} _ {\text {o u t}} ^ {\mathrm {e}}} \left[ \ell_ {\mathrm {O E}} (f (\tilde {X})) \right], \tag {3}
$$
where  $\mathcal{D}_{\mathrm{out}}^e$  indicates the extrapolated surrogate distribution during training and  $\tilde{X}$  indicates the newly manipulated samples that are different from those in the original objective (i.e., Eq. (2)) of OE. In the above learning objective, the left part is for the original classification task, and the right part is for the newly proposed informative extrapolation in our DivOE. With the conceptual target for diversifying the current surrogate OOD distribution, we consider reformulating the specific objective as,
$$
\mathbb {E} _ {\mathcal {D} _ {\text {o u t}} ^ {\mathrm {e}}} \left[ \ell_ {\mathrm {O E}} (f (\tilde {X})) \right] = (1 - \beta) \ell_ {\mathrm {O E}} (f; \mathcal {D} _ {\text {o u t}} ^ {s}) + \beta \underbrace {\max  _ {\Delta} \left[ \ell_ {\mathrm {O E}} (f ; \mathcal {D} _ {\text {o u t}} ^ {s + \Delta}) - \ell_ {\mathrm {O E}} (f ; \mathcal {D} _ {\text {o u t}} ^ {s}) \right]} _ {\text {I n f o r m a t i v e E x t r a p o l a t i o n}}, \tag {4}
$$
where  $\beta$  indicates a balancing factor for controlling the extrapolation ratio and  $\mathcal{D}_{\mathrm{out}}^{s + \Delta}$  represents the synthesized distribution with a manipulation  $\Delta$ . Intuitively, the overall objective defined in Eq. (4) not only learns from the original surrogate OOD distribution but also generalizes to the different OOD distributions via the maximization part. The underlying insight is to expand the surrogate OOD distribution towards a more diversified one. The informative extrapolation is realized by the maximization part that maximizes the differences between the original surrogate OOD distribution and the generated one. Note that, Eq. (4) corresponds to an expectation formulation based on the whole population for diversifying outlier exposure, which is prohibitively expensive in realization. To achieve that more efficiently, we introduce an instance-level version for practical realization, and its optimization target can be formulated as the following hybrid loss,
$$
\ell_ {\mathrm {O E}} (f (\tilde {X})) = \frac {1}{n - r n} \underbrace {\sum_ {n - r n} \ell_ {\mathrm {O E}} (f (x))} _ {\text {O r i g i n a l D i s t r i b u t i o n}} + \frac {1}{r n} \underbrace {\sum_ {r n} \max  _ {\delta} \ell_ {\mathrm {O E}} (f (x + \delta))} _ {\text {I n f o r m a t i v e E x t r a p o l a t i o n}}, \tag {5}
$$
where  $n$  indicates the sample number of auxiliary outliers and  $r$  indicates the extrapolation ratio that corresponds to  $\beta$  in Eq. (4). Except for the original loss on learning with the given outliers, the latter part of Eq. (5) defines a surrogate optimization part for realizing the informative extrapolation.
Here we adopt instance-level maximization for manipulating the expected OOD samples based on the original one, in which the specific  $\delta$  is obtained by the following optimization objective,
$$
\delta = \arg \max  _ {\delta} \ell_ {\mathrm {O E}} (f (x + \delta)), \tag {6}
$$
Intuitively, DivOE will generate new outliers closer to the decision boundary to expand the coverage area of auxiliary outliers, and simultaneously be more informative to shape the decision area between ID and OOD data. The specific optimization process of  $\delta$  is characterized as,
$$
\delta \leftarrow \delta + \alpha \operatorname {s i g n} \left(\nabla_ {\delta} \ell_ {\mathrm {O E}} (x + \delta)\right), \quad \operatorname {s i g n} \left(\nabla_ {\delta} \ell_ {\mathrm {O E}} (x + \delta)\right) \leftarrow \operatorname {s i g n} \left(\nabla_ {\delta} \ell_ {\mathrm {O E}} ^ {S (\cdot ; f)} (x + \delta)\right), \tag {7}
$$
where sign is the function that extracts the sign of the tensor elements and  $S(\cdot; f)$  indicates the general OOD score functions. The optimization process also indicates that our extrapolation framework is general and can adopt different score functions to generate targeted outliers. Here we also provide the theoretical implication of our proposed objective based on previous work [Ming et al., 2022].
Theorem 3.1. Given a simple Gaussian mixture model in binary classification with the hypothesis class  $\mathcal{H} = \mathrm{sign}(\theta^T x),\theta \in \mathbb{R}^d$ . There exists constant  $\alpha$ , and  $\sigma (\epsilon)$  that satisfy,
$$
\frac {\mu^ {T} \theta_ {n _ {1} , n _ {2}} ^ {*}}{\sigma \left| \left| \theta_ {n _ {1} , n _ {2}} ^ {*} \right| \right|} \geq \frac {\left| | \mu | \right| ^ {2} - \sigma^ {\frac {1}{2}} \left| | \mu | \right| ^ {\frac {3}{2}} - \frac {\sigma^ {2} (\alpha - \tau (\epsilon))}{2}}{2 \sqrt {\frac {\sigma^ {2}}{n} (d + \frac {1}{\sigma}) + \left| | \mu | \right| ^ {2}}}. \tag {8}
$$
From the perspective of sample complexity, we present the effects of our informative extrapolation. As  $\mathrm{FPR}(\theta_{n_1,n_2}^*) = erf\left(\frac{\mu^T\theta_{n_1,n_2}^*}{\sigma||\theta_{n_1,n_2}^*||}\right)$  is monotonically decreasing, the lower bound of  $\frac{\mu^T\theta_{n_1,n_2}^*}{\sigma||\theta_{n_1,n_2}^*||}$  will
Figure 3: Empirical exploration of informative extrapolation. Left panel: visualization of extrapolated outliers w.r.t different diversified strength  $\epsilon \in [0,0.15]$ ; Left-middle panel: the corresponding density of the energy score distributions on the different extrapolated outliers; Right-middle panel: comparison of ID/OOD distributions based on Energy score of the OE baseline; Right panel: comparison of ID/OOD distributions based on Energy score using the model fine-tuned by the proposed DivOE.
increase with the constraint of  $(\alpha - \tau(\epsilon))$  (which corresponds to our DivOE that extrapolates the outlier boundary towards ID data) decrease in our methods, the upper bound of  $\mathrm{FPR}(\theta_{n_1,n_2}^*)$  will decrease. The above indicates the benefit of DivOE with the informative extrapolation on shaping boundary decision areas. The completed definition and the analysis can be referred to in Appendix B.
3.3 Realization of DivOE
In this part, we introduce the realization of the whole learning framework of DivOE in detail. Here we formally present the learning objective of DivOE via informative extrapolation as follows,
$$
\mathcal {L} _ {\text {D i v O E}} = \frac {1}{m} \sum_ {m} \ell_ {\mathrm {C E}} (f (x), y) + \lambda \left(\frac {1}{n - r n} \sum_ {n - r n} \ell_ {\mathrm {O E}} (f (x)) + \frac {1}{r n} \sum_ {r n} \ell_ {\mathrm {O E}} (f (x + \delta))\right), \tag {9}
$$
where  $m$  and  $n$  indicate the sample numbers of ID data and auxiliary outliers respectively, other notations keep the same meaning as the previous equations. Concretely, the maximization part of DivOE adopts the multi-step optimization (e.g., projected gradient decent [Bottou, 2012, Madry et al., 2018]) to realize the targeted outlier synthetics. The specific process is defined as,