SELFOOD : Self-Supervised Out-Of-Distribution Detection via Learning to Rank (2023)

Abstract: Deep neural classifiers trained with cross-entropy loss (CE loss) often suffer from poor calibration, necessitating the task of out-of-distribution (OOD) detection. Traditional supervised OOD detection methods require expensive manual annotation of in-distribution and OOD samples. To address the annotation bottleneck, we introduce SELFOOD, a self-supervised OOD detection method that requires only in-distribution samples as supervision. We cast OOD detection as an inter-document intra-label (IDIL) ranking problem and train the classifier with our pairwise ranking loss, referred to as IDIL loss. Specifically, given a set of in-distribution documents and their labels, for each label, we train the classifier to rank the softmax scores of documents belonging to that label to be higher than the scores of documents that belong to other labels. Unlike CE loss, our IDIL loss function reaches zero when the desired confidence ranking is achieved and gradients are backpropagated to decrease probabilities associated with incorrect labels rather than continuously increasing the probability of the correct label. Extensive experiments with several classifiers on multiple classification datasets demonstrate the effectiveness of our method in both coarse- and fine-grained settings.

## introduction deep neural networks (dnns) are ubiquitously used for text classification @xcite @xcite . however, they are generally poorly calibrated, resulting in erroneously high-confidence scores for both in-distribution and out-of-distribution (ood) samples @xcite @xcite . such poor calibration makes dnns unreliable, and ood detection task vital for the safe deployment of deep learning models in safety-critical applications @xcite . traditional supervised ood detection methods @xcite @xcite ) assume access to high-quality manually annotated in-distribution and ood samples. however, this requires extensive annotation of ood samples belonging to diverse distributions, which is expensive to obtain. moreover, text classifiers are ideally desired to be more confident on in-distribution samples than ood samples. however, the poor calibration of dnn precludes this phenomenon. to address these problems, we propose selfood, a self-supervised ood detection framework that requires only in-distribution samples as supervision. to adhere to the aforementioned ranking constraint, we formulate ood detection as an inter-document intra-label (idil) ranking problem and train the classifier using our pairwise ranking loss, referred to as idil loss. as shown in figure 1(a ), text classifiers are generally trained using cross-entropy (ce) loss @xcite in an intra-document fashion where for each document, the classifier is trained to distinguish between different labels by maximizing the score corresponding to the correct label. instead, in our method, as shown in figure 1(b) , we propose to train in an inter-document, intra-label fashion where for each label, we train the model to rank the considered label probability score in documents belonging to the label higher compared to those not belonging to it. as ood documents generally do not belong to any in-distribution label, we hypothesize such explicit learning to rank translates to accurately distinguishing ood from in-distribution. moreover, minimizing ce loss involves continuous optimization to increase the probability of the correct label over the other labels, making the classifier overconfident @xcite . instead, in our method, our idil loss function becomes zero once the desired ranking is achieved, and during training, we backpropagate gradients to decrease probabilities associated with incorrect labels rather than increasing the probability of the correct label. theoretically, the perfect model trained using the ce loss with 0 training loss is a solution to our ranking problem, however, in section 5.1, we empirically show that our ranking objective leads to a different solution, demonstrating the importance of the optimization procedure. finally, it is important to note that our ranking formulation, loss function, and the self-supervised training strategy are specifically designed to improve the performance of ood detection rather than classification accuracy. we present our framework in figure 2 . given a set of in-distribution documents and corresponding labels as input, we bucket documents belonging to each label and train the classifier to rank the probabilities using our idil loss function. specifically, for each document in a label bucket, we pair up with all documents in every other bucket and compute idil loss. our contributions are summarized as follows: • we propose selfood, a novel self-supervised method to train an ood detection model without any ood samples as supervision. ## related work traditional supervised methods cast the ood detection as classification with binary labels @xcite , with one additional label for unseen classes @xcite . since manually annotating documents is expensive @xcite , recent works have deviated from requiring such extensive annotations and leveraging various distance metrics to detect ood samples. leys et al. (2018); xu et al. (2020) use mahalanobis distance as a post-processing technique to identify ood samples. these methods use distance-based scoring functions along with the intermediate model layer features to determine an ood score. lee et al. (2018); hsu et al. (2020) use a similar distance metric called odin to detect ood images. an alternate approach to compensate for the lack of ood training data involves generating pseudo-ood data for training. ouyang et al. (2021) propose a framework to generate highquality ood utterances and importance weights by selectively replacing phrases in in-domain samples. zhan et al. (2021) generate pseudo-ood samples for the task of intent detection using self-supervision. zhou et al. (2021); zeng et al. (2021a) introduce self-supervised approaches to ood detection using a contrastive learning framework. they suggest fine-tuning transformers using a margin-based contrastive loss to learn text representations (mekala et al., 2021) for ood classification. vyas et al. (2018); li et al. (2021) treat a part of in-domain data as ood samples as an alternate self-supervised approach. further, wu et al. (2022a) use a reassigned contrastive loss (rcl) along with an adaptive class-dependent threshold mechanism to separate in-domain and ood intents. ren et al. (2019); gangal et al. (2020) leverage likelihood ratios crafted by generative models to classify ood samples. wei et al. (2022) observe that the norm of the logits keeps increasing during training, leading to overconfident outputs, and propose logitnorm as a solution to decoupling the output norm during training optimization. moon et al. (2020) introduce a novel correctness ranking loss function in order to regularize output probabilities to produce well-ranked confidence estimates. other calibration techniques include "top-label" calibration which is used to regularize the reported probability for the predicted class @xcite . ## selfood: self-supervised ood detection we present the problem statement, the motivation for our ranking formulation, and our method including the loss function and its optimization strategy. ## experiments we evaluate our ood detection method against state-of-the-art baselines with two classifiers on multiple datasets belonging to different domains. ## analysis & case studies in this section, we present a comprehensive analysis of our proposed method from different perspectives to understand its effectiveness. ## conclusion in this paper, we present selfood, a novel framework for ood detection that leverages only indistribution samples as supervision. building upon the insight that ood samples typically do not belong to any in-distribution labels, we formulate the ood detection problem as an inter-document intra-label ranking task. to address this challenge, we propose idil loss which guides the training process. through extensive experiments on multiple datasets, we demonstrate the effectiveness of selfood on ood detection task. however, we