Learn what you can't learn: Regularized Ensembles for Transductive out-of-distribution detection

1 INTRODUCTION . Modern machine learning ( ML ) systems can achieve good test set performance and are gaining popularity in many real-world applications - from aiding medical diagnosis ( Beede et al. , 2020 ) to making recommendations for the justice system ( Angwin et al. , 2016 ) . In reality however , some of the data points in a test set could come from a different distribution than the training ( in-distribution ) data . For example , sampling biases can lead to spurious correlations in the training set ( Sagawa et al. , 2020 ) , a faulty sensor can produce novel data corruptions ( Lu et al. , 2019 ) , or new unseen classes can emerge over time , like undiscovered bacteria ( Ren et al. , 2019 ) . Many of these samples are so different compared to the training distribution that the model does not have enough information to predict their labels but still outputs predictions with high confidence . It is important to identify these out-of-distribution ( OOD ) samples in the test set and flag them , for example to at least temporarily abstain from prediction ( Geifman & El-Yaniv , 2017 ) and involve a human in the loop . To achieve this , Bayesian methods ( Gal & Ghahramani , 2016 ; Malinin & Gales , 2018 ) or alternatives such as Deep Ensembles ( Lakshminarayanan et al. , 2017 ) try to identify samples on which a given model can not predict reliably and include . Their aim is to obtain predictive models that simultaneously have low error on in-distribution ( ID ) data and perform well on OOD detection . Other approaches try to identify samples with low probability under the training distribution , independent of any prediction model , and use , for instance , density estimation ( Nalisnick et al. , 2019 ) or statistics of the intermediate layers of a neural network ( Lee et al. , 2018 ) . Most prior work have reported good OOD detection performance , reaching an almost perfect area under the ROC curve ( AUROC ) value of nearly 1 . However these settings generally consider differentiating two vastly different data sets such as SVHN vs CIFAR10 . We show that the picture is very different in a lot of other relevant settings . Specifically , for unseen classes within CIFAR10 or for data with strong distribution shifts ( e.g . ( resized ) ImageNet vs ObjectNet ( Barbu et al. , 2019 ) ) , the AUROC of state-of-the-art methods often drops below 0.8 . Almost all of these methods assume a setting where at test time , no training is possible and the OOD detection method can only be trained beforehand . This inductive setting allows real-time decision-making and is hence more broadly used . However , in many cases we can indeed do batch predictions , for example when sensor readings come in every second and it is sufficient to make a prediction and decision every few minutes ( e.g . automatic irrigation system ) . In this case we have a batch of unlabeled test data available that we want to predict ( and be warned about ) that we can use together with the labeled training set to detect the OOD points in the set . We call this the transductive OOD setting ( related to but quite different from transductive classification ( Vapnik , 1998 ) ) . Even in an online setting , transductive OOD could be very useful ( see Section 2.1 ) . ( How ) Can we achieve significantly better OOD detection performance in the transductive setting ? Even though the transductive setting improves test accuracy in small data settings for tasks such as classification or zero-shot learning , it is unclear how to successfully leverage simultaneous availability of training and test set in the transductive OOD setting which is quite distinct from the former problems . A concurrent recent work Yu & Aizawa ( 2019 ) tackles this challenge by encouraging two classifiers to maximally disagree on the test set ( i.e . to produce different predictions on test samples ) . However this leads to models that disagree to a similar degree on both ID and OOD data and hence one can not distinguish between the two , as indicated by the low AUROC in Figure 1 . We introduce a new method called Regularized Ensembles for Transductive OOD detection ( RETO ) for overparameterized models , which heavily uses regularization to make sure that the ensemble disagrees only on the OOD samples in the test set , but not on the ID samples . In summary , our main contributions in this paper are as follows : • We experimentally identify many realistic OOD scenarios where SOTA methods achieve a subpar AUROC below 0.84 . We hence argue that the field of OOD detection is far from satisfactorily solved and more methods will be proposed that include these ( or other ) hard OOD cases as benchmarks . • For the transductive OOD detection setting , we propose a new procedure , RETO , that manages to diversify the output of an ensemble only on the OOD portion of the test set and hence achieves significant improvements compared to SOTA methods ( see Figure 1 ) with a relative gain of at least 32 % . 2 REGULARIZED ENSEMBLES FOR TRANSDUCTIVE OOD DETECTION . Our main goal is to detect samples that are outside of the training distribution and focus on classification tasks . We are only interested in situations where we can obtain a model that generalizes well given the training data . If the models do not generalize well in-distribution ( ID ) , then the primary task should be to find a better classifier instead . Given a classifier with good generalization , the next challenge becomes to ensure that samples on which the model can not make confident predictions ( e.g . samples that are too far from the training data ) are correctly identified . This constitutes the main focus of our work . Recall that in our use case , we have a batch of unlabeled test samples at our disposal . This test set includes a mixture of samples drawn from the training distribution and samples we call OOD per our definition in the previous section . The goal is to distinguish between the ID and the OOD samples in the test set . In this section we propose our method that uses the more numerous training data as a counterweight that does not allow a sufficiently smooth model to fit an arbitrary label on ID test samples , but only on OOD test samples . 2.1 TRANSDUCTIVE OOD DETECTION . In an inductive OOD detection setting , one can only tune a method at training time , and then use it with unchanged parameters on any test set . In contrast , in a transductive setting , the training data is available during test time and it is possible to tune a method using both the training set and the unlabeled test set . We stress that no labels are available for the test data , so it is unknown which test samples are indeed anomalous . Moreover , we do not assume access to any known OOD samples , unlike some of the inductive methods , which sometimes use OOD data for training or calibration ( Lee et al. , 2018 ; Liang et al. , 2018 ; Malinin & Gales , 2018 ; Cao et al. , 2020 ) . When deployed in the context of classification , transductive and semi-supervised learning methods leverage the unlabeled data to obtain low-dimensional representations that are more effective for the prediction task . A key assumption for the setting to be useful is that the data is related in some way , e.g . the unlabeled data comes from the same distribution as the labeled data . On the other hand , transductive OOD detection differs from the usual transductive classification setting , in that the training distribution does not carry information about the OOD data . As a consequence , it is not obvious how to adapt existing semi-supervised methods to work in this different regime . Some of the downsides that prevent transductive classification methods from being used more broadly are that for each test set that we want to predict , we would need to have access to the training data and computational resources . Furthermore , they do not allow predictions on the fly in the online setting . For transductive OOD however , we know that the inductive model predicts reliably in-distribution . Hence we can still predict test points on the fly , and only flag OOD samples with a slight delay after receiving a batch of test points . An example for which all these downsides are not limiting should be quite relatable to the reader . For example , Covid-19 test results have a crucial role for controlling the spread of the virus . Imagine a machine learning model were to be developed and deployed for reliable fast testing that works well under usual circumstances . If a test pipeline becomes defect , informing the patient of the potentially wrong test result is still crucial , in particular if it is to inform a negatively tested patient to repeat the test or to quarantine . In this case we would also be willing to allow access to labeled training data and computational resources for fine-tuning as precision is of utmost importance . 2.2 THE COMPLETE RETO PROCEDURE . We now provide details on our approach , RETO , outlined in Algorithm 1 . Recall that we have access to both a labeled training set , and the unlabeled test set . We begin by assigning an arbitrary label ( selected from the set of labels of the training data ) to all the test samples . We train a classifier on the union of the correctly-labeled training set , and the arbitrarily-labeled test set . To find the optimal classifier , we search among functions that are known to generalize well on the ID ( training ) distribution . If the classifiers are smooth enough , they will not be able to fit both the correct labels of the training set and the arbitrary label on the ID test samples , as illustrated in Figure 2 for linear classifiers . However , they will still fit the arbitrary label on the OOD test samples . Using regularization , we ensure that the models we obtain are not too complex . We search inside a function class of regularized functions , Freg , as discussed in more detail in Section 3 . We ensemble several such classifiers , where each model fits a different label to the test set . We then use a disagreement statistic and flag as OOD all the points in the test set with high disagreement . To avoid training the ensemble from scratch for each new test batch , it is possible to instead start from pre-trained weights and perform a few iterations of fine-tuning , as detailed in Section 4 . We stress that we do not calibrate or train our method on any known OOD data . Algorithm 1 : Pseudocode for RETO Input : Train set S , Test set T , Ensemble size K , Test statistic threshold t0 , Regularized function class Freg , Disagreement metric Result : O , i.e . the elements of T which are OOD for c← { y1 , ... , yK } do // train K models T c ← { ( x , c ) : x ∈ T } f̂c ← Train ( S ∪ T c ; Freg ) O = ∅ for x ∈ T do // run two-sample test if disagreement ( f̂y1 ( x ) , . . . , f̂yK ( x ) ) > t0 then O ← O ∪ { x } return O Determining OOD samples with RETO . We distinguish between ID and OOD samples using a two-sample statistical test , with the null hypothesis : H0 : x ∈ suppP , for a test sample x and where P denotes the training distribution1 . Previous baselines have proposed their own choices of the test statistic , which is discussed in detail in Appendix A . For RETO , we use : Tavg-TV ( x ) : = 1 K ( K − 1 ) ∑ i 6=j dTV ( fi ( x ) , fj ( x ) ) , the average pairwise total variation distance between the softmax outputs fi ( x ) , fj ( x ) ∈ R|Y| of models i , j ∈ { 1 , ... , K } in the ensemble , where dTV is the total variation distance . The null hypothesis is rejected for high values of Tavg-TV . Appendix L contains more details about the choice of the test statistic . It follows from the way in which the hypothesis test is stated that true positives are OOD samples that are indeed flagged as OOD , while the false positives are ID samples that are incorrectly predicted as OOD .

Summary: The problem of good predictive uncertainty-based out of distribution (OOD) detection is essential for classification systems to be deployed in safety-critical environments. The authors present a method RETO that achieves state-of-the-art performance in a transductive OOD detection setting. Like other predictive uncertainty-based approaches RETO can ultimately be used downstream on problems like active learning or abstaining on OOD samples in combination with selective classification.