k F olden: k -Fold Ensemble for Out-Of-Distribution Detection (2021)

Abstract: Out-of-Distribution (OOD) detection is an important problem in natural language processing (NLP). In this work, we propose a simple yet effective framework k Folden, which mimics the behaviors of OOD detection during training without the use of any external data. For a task with k training labels, k Folden induces k sub-models, each of which is trained on a subset with k-1 categories with the left category masked unknown to the sub-model. Exposing an unknown label to the sub-model during training, the model is encouraged to learn to equally attribute the probability to the seen k-1 labels for the unknown label, enabling this framework to simultaneously resolve in- and out-distribution examples in a natural way via OOD simulations. Taking text classification as an archetype, we develop benchmarks for OOD detection using existing text classification datasets. By conducting comprehensive comparisons and analyses on the developed benchmarks, we demonstrate the superiority of k Folden against current methods in terms of improving OOD detection performances while maintaining improved in-domain classification accuracy.

## introduction recent progress in deep neural networks has drastically improved accuracy in numerous nlp tasks @xcite @xcite , but detecting out-ofdistribution (ood) examples from the in-domain (id) examples is still a challenge for existing stateof-the-art deep nlp models. the ability of identifying ood examples is critical for building reliable and trustworthy nlp systems for, say, text classifi-1 corresponding author: jun zhang. in this work, we propose a novel, simple yet effective framework, kfolden, short for a k-fold ensemble, to address ood detection for nlp without the use of any external data. we accomplish this goal by simulating the process of detecting ood examples during training. concretely, for a standard nlp task with k labels for both training and test, we first obtain k separate sub-models, each of which is trained on a set of different k -1 labels with the left one being masked unknown to the model. we train each sub-model by jointly optimizing the cross entropy loss for the visible k -1 labels and the kl divergence loss between the predicted distribution and the uniform distribution for the left-one-out label. during test, we simply average the probability distributions produced by these k sub-modules and treat the result as the final probability estimate for a given input. intuitively, if the input is an id example, the final probability distribution will lay much of the weight on one of the k seen labels, but if the input is an ood example, we expect the final probability distribution to get close to the uniform distribution, since each sub-model has tried to even its probability distribution when encountering unseen labels during training. this training paradigm does not rely on any external data, and by mimicking the behaviors of distinguishing unseen labels from the seen, i.e., simulating the process of ood detection during training, which is completed via the kl divergence loss, the framework naturally detects ood examples and is able to perform reasonably better than other widely used strong ood detection methods. moreover, kfolden is complementary to existing post-hoc ood detection methods, and combining both leads to the most performance boosts. to facilitate ood detection researches in nlp, we also construct benchmarks on top of four widely used text classification datasets: 20newsgroups, reuters, ag news and yahoo!answers. this created benchmark consists of 7 datasets with different levels of difficulty directed to two types of ood examples: semantic shift and non-semantic shift, which differ in whether a shift is related to the inclusion of new semantic categories. the proposes benchmarks help comprehensively examine ood detection methods, and we hope it can serve as a convenient and general tool for developing more robust and effective ood detection models. to summarize, the contributions of this work are: ## benchmark construction out-of-distribution data can be conceptually divided into two categories: non-semantic shift (nss) and semantic shift (ss) and datasets @xcite . they are different in terms of whether a shift is related to the inclusion of new semantic categories: the training and ood test examples in the nss dataset come from different sub-categories of the same broader category. for example, the training and ood test sets in an nss dataset are both from the "car" category, but examples in the training set are able "real car", e.g. "that's when they took out the fuel tank and poured it into a jug", and all ood test are about "toy car", e.g. "raleigh 2year-old fills up toy car with 'gas' amidst shortage". for ss, the training and ood test examples in the ss dataset come from completely different cate-gories. for example, the training set contains labels "car" and "bicycle", and the test set has labels "train" and "plane", which have no intersections with training labels. in this paper, we construct both ss and nss text classification benchmarks for ood detection. we construct benchmarks on multi-class topic classification datasets. the topic classification task has less vocabulary overlap between id and ood data. we use data from 20newsgroups @xcite , reuters-21578 foot_0 , ag news (del @xcite and yahoo!answers @xcite . more details of the original datasets can be found at appendix a. the statistics of the benchmark are present in we construct nss benchmarks as follows: agnews-ext this dataset is adapted from ag news and additional articles come from the ag corpus. the original ag news dataset has 4 classes ("world", "sports", "business", "sci/tech"). the training and id test data in agnews-ext come from the 4 class labels in ag news, and the ood test data are from the ag corpus but have the same class labels as in ag news. the ood test data are selected from the 5 classes ("health", "sci/tech", "sports", "entertainment", "business") in ag corpus. ## conclusion in this paper, we propose a simple yet effective framework kfolden for ood detection. it works by mimicking the behaviors of detecting out-ofdistribution examples during training without the use of any external data. we also develop a bencha dataset details