Improving Unsupervised Out-of-domain detection through Pseudo Labeling and Learning (2023)

Abstract: Unsupervised out-of-domain (OOD) detection is a task aimed at discriminating whether given samples are from the in-domain or not, without the categorical labels of in-domain instances. Unlike supervised OOD, as there are no labels for training a classifier, previous works on unsupervised OOD detection adopted the one-class classification (OCC) approach, assuming that the training samples come from a single domain. However, in-domain instances in many real world applications can have a heterogeneous distribution (i.e., across multiple domains or multiple classes). In this case, OCC methods have difficulty in reflecting the categorical information of the domain properly. To tackle this issue, we propose a two-stage framework that leverages the latent categorical information to improve representation learning for textual OOD detection. In the first stage, we train a transformer-based sentence encoder for pseudo labeling by contrastive loss and cluster loss. The second stage is pseudo label learning in which the model is re-trained with pseudo-labels obtained in the first stage. The empirical results on the three datasets show that our two-stage framework significantly outperforms baseline models in more challenging scenarios.

## introduction deep neural networks show outstanding performance on benchmark datasets that have the same training and test domains. however, once the model is deployed to the real world, it can face outof-domain (ood) instances that make the model predict unreliable outcomes related to ai safety issues @xcite . for this reason, the ood detection task aims to discriminate whether given instances are from in-domain (ind) or not. one of the main ood detection approaches is to use a classifier that predicts the labels of ind samples, based on the * indicates corresponding author. as this approach targets only supervised tasks that require ind labels to train the classifier, it has a limitation on unsupervised tasks. to overcome this problem, recent studies have proposed unsupervised ood detection (or the without label scenario) that can be utilized in a more general use case @xcite . this setting can be regarded as one-class classification (occ) because it uses only ind instances without labels and aims to distinguish novel samples from ind instances. within this background, unsupervised ood detection methods introduce occ approaches such as oc-svm and svdd @xcite . meanwhile, self-supervision based models exploit a novel property named inlier priority @xcite by using pseudo labels that are generated for surrogate supervision (e.g., rotation transformation @xcite ). in the field of natural language processing (nlp), this approach is adopted in combination with selfsupervised methods of pretrained-language models @xcite . however, there are tasks where the categorical labels of training data are not available, while the ind has categorical distributions (e.g., summarization, topic modeling). occ methods can suffer in this scenario @xcite due to the absence of ind labels, because it is difficult for the model to explicitly reflect the latent categorical distribution. to tackle this problem, we propose a two-stage framework for textual out-of-domain detection that embeds similar inds close together by considering latent categorical information of heterogenous ind instances without labels, and then detects ood instances based on the learned embedding space. to achieve this, in the first stage, we conduct pseudo labeling of training samples by using an unsupervised clustering method combined with contrastive loss. next, the model from the first stage is refined by the given pseudo labels, which we call pseudo label learning (pll). we find that this second stage of pll greatly improves the representation learning for ind instances. after training is done, the inference step uses a confidence score function that measures the likelihood of whether an input is ind or ood. our experimental results on three real-world datasets with the pre-trained roberta @xcite as a base architecture show that the proposed framework substantially outperforms the baseline models in various settings. in addition, we conduct embedding space analysis to confirm the effectiveness of pll and show that it learns a more suitable representation for ood detection by increasing inter-cluster distance significantly, which makes ood samples more distinct from the clusters. in summary, our main contributions are as follows: ## related work out of domain detection. ood detection aims to distinguish ood instances from ind to prevent a model trained for ind from making wrong predictions in the real applications. one of the main approaches is to rely on a classifier for ind labels, supposing that the softmax probability value of the ind will be larger than ood @xcite . furthermore, @xcite @xcite improve this method by adding perturbation to the inputs, which further increases the softmax probability of ind. in the nlp field, hendrycks et al., 2020 find out that transformer-based models are more effective than convolutional neural networks @xcite or long short-term memory @xcite based models in detecting textual oods. to improve ood detection performance for the models, @xcite utilize supervised contrastive loss that creates a more compact representation. however, these approaches cannot be used without ind labels. unsupervised out of domain detection. selfsupervised methods can handle this issue by using augmentation techniques @xcite . @xcite adopt this approach by utilizing the training scheme introduced in electra @xcite . they use a generator to replace random masked tokens in the input and train a discriminator to predict whether each token is replaced by the generator or not. xu et al., 2021 focus on the findings that different layers of bert devlin et al., 2019 can capture different linguistic information. they compute the mahalonobis distance using the embeddings in each layer and construct a new vector consisting of the distance values across all the layers. this new feature vector is used as input to occ-based ood detection methods. however, these models are difficult to perform well when inds are in heterogeneous domains (or multiple classes), because they do not explicitly reflect the multimodal ind distribution. cluster-based approaches can help alleviate this problem since they assume that the ind has a latent class distribution in its feature space. @xcite introduce a clustering method for representation learning to reflect categorical distributions on the embedding space. our approach is motivated by @xcite , but our method generates pseudo labels and uses them explicitly to reinforce this categorical information, which greatly improves the performance. ## proposed framework in this section, we describe our two-stage framework for unsupervised ood detection. first, the purpose of stage 1 is to generate pseudo labels that include categorical information of ind samples. we train a sentence encoder based on a pre-trained is the pseudo label for x i generated in stage 1. ## experiments in this section, we present the experimental setting for the evaluation of the proposed framework. we describe the used datasets and how to construct ind and ood samples under unsupervised ood scenarios. ## conclusion in this work, we proposed a two-stage framework for unsupervised ood detection that effectively utilizes the categorical information of ind instances by pseudo labeling and pseudo label learning. in addition, for a more systematic analysis of ood performance, we introduced the near-ood setting, which is a more challenging yet realistic scenario. in most of our experimental settings, our framework outperforms the baseline models with significant margins. we further justify the improvement of the proposed model's ood detection performance by analyzing the embedding space with inter or intra-cluster distances and silhouette scores. in future work, we will further investigate how to reduce intra-cluster variations while maintaining inter-cluster distances.