Estimating Semantic Similarity between In-Domain and Out-of-Domain Samples
Year: 2023

Abstract:
Prior work typically describes out-of-domain (OOD) or out-of-distribution (OODist) samples as those that originate from dataset(s) or source(s) different from the training set but for the same task. When compared to in-domain (ID) samples, the models have been known to usually perform poorer on OOD samples, although this observation is not consistent. Another thread of research has focused on OOD detection, albeit mostly using supervised approaches. In this work, we first consolidate and present a systematic analysis of multiple definitions of OOD and OODist as discussed in prior literature. Then, we analyze the performance of a model under ID and OOD/OODist settings in a principled way. Finally, we seek to identify an unsupervised method for reliably identifying OOD/OODist samples without using a trained model. The results of our extensive evaluation using 12 datasets from 4 different tasks suggest the promising potential of unsupervised metrics in this task.

heading: 1 Introduction
text: What happens when you train a machine learning model on a dataset and use it to predict a sample whose source is unknown? Would you fully rely on the model’s prediction on the test sample? Basically, this situation is encountered in most realworld scenarios where the test sample may differ considerably from the training samples. Recent works show that models perform poorer on the samples that come from a different distribution (Gokhale et al., 2022). In many real-world scenarios, such as health and law, false predictions or misclassified results could have significant consequences, and as such identifying out-of-domain or out-of-distribution data beforehand is critical.
Previous works have defined OOD and OODist data in different ways or used them interchangeably. Early works define data that comes from a related but different domain as OOD (Dai et al., 2007),
whereas OODist data has been defined as the data that might have been collected at a different time (Ovadia et al., 2019). In recent studies, (Chrysostomou and Aletras, 2022) use the term OOD to describe different datasets for the same task (e.g., SST, IMDb, and Yelp for sentiment classification), whereas (Lin et al., 2022) use OODist to describe the datasets that are not in the training set, including those that are subsets of the same dataset (e.g., PDTB 2.0 (Carlson et al., 2002)). In this paper, we first present a focused analysis of all the various terminologies used in this context in recent works.
Another thread of research has focused on identifying OOD/OODist samples, mostly through supervised methods (Varshney et al., 2022; Chiang and Lee, 2022; Gokhale et al., 2022). However, considering that trained models may not always be available, we take a complementary approach in this work to identify metric(s) that may be able to support OOD detection in an unsupervised manner.
The first part of our methodology focuses on establishing to what extent performance (e.g., accuracy) can inform the detection of OOD samples1. Our results indicate that indeed performance can serve as a reliable metric for estimating OODness, however, this requires a supervised model. To address this limitation, in the second part of this work, we explore several unsupervised metrics for estimating semantic similarity between the training and test samples. We hypothesize that an unsupervised metric which sufficiently correlates with performance, may be considered as a feasible alternative for detecting OOD samples.
The major contributions of this paper are:
• an in-depth exploration of the usage of the terms OOD and OODist in recent works;
• a systematic assessment of the effectiveness 1As formally distinguishing between the two terms remains beyond the scope of this paper, in this work we use the terms OOD and OODist interchangeably.
409
of performance in estimating OODness, and an investigation of unsupervised approaches for identifying OODness;
• an extensive evaluation across four different tasks using a total of twelve datasets; we will also make our code available for facilitating reproducibility.

heading: 2 Related Work
text: Prior research has often used the terms OOD and OODist interchangeably. In some works, dataset X is described to be OODist to dataset Y if they are different datasets, but support the same task (Lin et al., 2022; Aghazadeh et al., 2022; Chiang and Lee, 2022; Mishra and Arunkumar, 2022; Omar et al., 2022; Adila and Kang, 2022), while in other works, the term OOD is used to describe the similar
setting (Chrysostomou and Aletras, 2022; Le Berre et al., 2022; Nejadgholi et al., 2022; Varshney et al., 2022). Beyond that, while some consider different subsets of the same dataset to be OODist (Mai et al., 2022; Garg et al., 2022; Jin et al., 2021), others refer to these as OOD to describe distributionally different datasets (Atwell et al., 2022; Gokhale et al., 2022).
When it comes to detecting OOD or OODist samples, using the model’s accuracy (Le Berre et al., 2022; Aghazadeh et al., 2022; Gokhale et al., 2022; Omar et al., 2022), input features, hidden features representations, and output probability distribution of the network layers (Chiang and Lee, 2022), or AUC and F1 score (Nejadgholi et al., 2022) have been well-studied. Table 1 presents a brief summary of some recent works.

heading: 3 Method

heading: 3.1 Problem Definition
text: Given two datasets, X = {x1, ..., xm} and Y = {y1, ..., ym}, the goal is to assess the correlation between the performance of the two datasets under ID/OOD settings and their (semantic) similarity. The performance is measured by training a model on one of the datasets, say, Xtrain and testing it on the test set Xtest which represents the ID setting, and Ytest representing the OOD setting. The ID similarity is computed by averaging the similarity between the instances of Xtrain and Xtest, while OOD similarity is measured between Xtrain and Ytest.

heading: 3.2 Datasets
text: We study four different tasks using a total of 12 datasets (3 datasets for per task). We include the most common tasks that have been used in prior work. (i) Sentiment Analysis: given a text, classify its sentiment as negative or positive. (ii) Multiple Choice Question Answering (MCQ): given a question and a context, select the correct
answer from a pool of possible answers. (iii) Extractive Question Answering (QA): given a question and a context, find the answer to the question from the context. (iv) Natural Language Inference (NLI): given a premise and a hypothesis, determine whether the hypothesis contradicts, entails, or is neutral with respect to the premise.
Table 2 presents the details of the datasets and the tasks. For sentiment classification, we use IMDb (Maas et al., 2011), SST2 (Socher et al., 2013), and Yelp (Zhang et al., 2015) datasets. We experiment with SCIQ (Welbl et al., 2017), CommonsenseQA (CS) (Talmor et al., 2019), and QASC (Khot et al., 2020) for the MCQ task. For the Extractive QA task, SQUAD, News, and Trivia (Fisch et al., 2019) datasets are selected from the MRQA dataset (note that since these datasets do not have a separate test set, we use the validation data as the test set). The NLI datasets include MNLI, QNLI, and WNLI from the GLUE benchmark (Wang et al., 2018). All the other datasets were accessed from the HuggingFace repository2.
Data preparation: Prior work has largely overlooked the effect of an important aspect – dataset size – in such studies. As such, we control the dataset size as a variable in our study by maintaining the size of all train, validation (when available), and test splits for all three datasets per task by downsampling them to match the size of the smallest dataset in each set. For instance, all the splits of all three sentiment analysis datasets are downsampled to be of equal size. Additionally, we balance the number of instances for each class when possible (e.g., in the sentiment datasets).

heading: 3.3 Metrics
text: We use three categories of metrics, one for measuring the performance of the model, another for estimating the similarity between the two datasets,
2https://huggingface.co/datasets/
and the third for computing the correlation between performance and similarity.
Performance Metrics. We report accuracy for the classification tasks, i.e., sentiment analysis, MCQ, and NLI tasks, and F1 score for extractive Question Answering task to measure the correctness of model predictions.
Similarity Metrics. To estimate the closeness among the ID and OOD datasets, we use metrics related to semantic similarity (higher value means the samples are from nearby distributions) and semantic distance (higher value indicates less similarity). These include: (i) Cosine Similarity: measures the distance between the samples from two sources3. (ii) Mauve Score: measures the similarity between two texts4 (Pillutla et al., 2021). (iii) Wasserstein Distance (Wstn): measures the distance between the two distributions and if the distributions overlap enough, then they are close to each other5 (Weng, 2019). (iv) Jensen Shannon Distance (JSD): quantifies the similarity between two probability distributions, where the smaller the value, the closer the distributions6 (Manning and Schutze, 1999).
Correlation Metrics. Lastly, we use two commonly used correlation metrics – Kendall Tau and Pearson7 (we also experimented with Spearman which gave similar results), with the goal of understanding the relationship between performance and similarity of datasets under ID/OOD settings.

heading: 3.4 Measuring Performance and Similarity
text: For measuring the performance, we fine-tune a BERT base uncased model for 2 epochs on each Xtrain and test it on Xtest (ID) and Ytest (OOD). For estimating the similarity between the ID and OOD datasets, we randomly sample two sets of 20 instances, Xtrain20 and Ytest20, and estimate pairwise similarity between all of these samples, obtaining a total of 400 similarity scores which are then averaged to compute the similarity.

heading: 4 Results and Discussion
text: Performance analysis: Table 3 presents the results of the performance experiments, where we observe
3We estimate this using word2vec embeddings. 4We use the default embeddings (GPT-2) https:// pypi.org/project/mauve-text/. 5We use the universal sentence encoder for estimating this. 6We used word2vec embeddings. 7https://pandas.pydata.org/docs/ reference/api/pandas.DataFrame.corr.html
that the model performance under ID settings is generally better than under OOD settings, except for three exceptions, suggesting that performance can indeed serve as a reasonably dependable met-
ric for detecting OOD. However, this requires a supervised model, which motivates us to explore unsupervised approaches for estimating OODness. It is worth noting that while Garg et al. (2022) found that OOD accuracy is less than the ID accuracy, this observation does not always hold true according to our analysis.
Correlation between performance and similarity: Figure 1 presents the heatmap visualizing the correlation (Kendall and Pearson) between performance and similarity metrics, across all 12 datasets for the four tasks (the full set of results is included in Appendix A). In looking at the results, we observe that according to Kendall Tau correlation analysis, Wasserstein distance (Wstn) shows the most consistent correlation (in 10 out of 12 cases), whereas according to Pearson correlation, both Wasserstein and Cosine are acceptable metrics (in 9 out of 12 cases). In all the scenarios, however, JSD is clearly the least correlated metric. This suggests the potential of unsupervised approaches in estimating OOD samples.

heading: 5 Conclusion
text: In this work, we aim to identify unsupervised approaches for identifying OOD samples. We conducted an in-depth analysis of different unsupervised similarity metrics and estimated their correlation with performance of a model under ID/OOD settings. Our findings indicate that Wasserstein distance presents a promising metric for determining OOD samples. The natural question of how to determine the appropriate threshold, however, remains to be explored in future work. Another direction worth exploring is to verify the robustness of these similarity metrics when estimated using different embeddings.
Limitations
While our analysis suggests some promising results, we acknowledge some limitations of this work such as:
• on some datasets, the ID performance was observed to be less than the OOD performance, and further investigation is needed to study this observation in detail and bring additional insights.
• all the analysis in this study focuses on datasets in English language, and it will be
interesting to investigate whether our findings will generalize to other languages.

heading: Acknowledgements
text: We are thankful to the anonymous reviewers for their valuable feedback.

heading: Future Work
text: The natural question of how to determine the appropriate threshold, however, remains to be explored in future work. Another direction worth exploring is to verify the robustness of these similarity metrics when estimated using different embeddings. Limitations
While our analysis suggests some promising results, we acknowledge some limitations of this work such as:
• on some datasets, the ID performance was observed to be less than the OOD performance, and further investigation is needed to study this observation in detail and bring additional insights. • all the analysis in this study focuses on datasets in English language, and it will be
interesting to investigate whether our findings will generalize to other languages