Efficient Out-of-Domain Detection for Sequence to Sequence Models (2023)

Abstract: Sequence-to-sequence (seq2seq) models based on the Transformer architecture have become a ubiquitous tool applicable not only to classical text generation tasks such as machine translation and summarization but also to any other task where an answer can be represented in a form of a finite text fragment (e.g., question answering). However, when deploying a model in practice, we need not only high performance but also an ability to determine cases where the model is not applicable. Uncertainty estimation (UE) techniques provide a tool for identifying out-of-domain (OOD) input where the model is susceptible to errors. State-of-the-art UE methods for seq2seq models rely on computationally heavyweight and impractical deep ensembles. In this work, we perform an empirical investigation of various novel UE methods for large pre-trained seq2seq models T5 and BART on three tasks: machine translation, text summarization, and question answering. We apply computationally lightweight density-based UE methods to seq2seq models and show that they often outperform heavyweight deep ensembles on the task of OOD detection.

## introduction sequence-to-sequence (seq2seq) models achieve state-of-the-art performance in various nlp tasks, such as neural machine translation (nmt; @xcite ; @xcite ; @xcite ; @xcite , abstractive text summarization (ats; @xcite ; @xcite ), question answering (qa; @xcite ), and others. such models may encounter various user inputs when exposed to the general public. in many cases, it is preferable to detect and handle in a special way what is known as out-of-domain (ood) inputs. ood instances are significantly different 1 the code for reproducing experiments is available online at https://github.com/stat-ml/seq2seq_ood_ detection ♢ equal contribution from the data used during training, and as a result, model predictions on such inputs might be unreliable. ood can be performed in supervised and unsupervised ways. in a supervised approach, one trains a discriminator between in-domain (id) and ood instances on a labeled dataset of such instances, which is manually annotated @xcite or synthetically generated @xcite . the drawback of such an approach is that the discriminator is also limited in what instances it can correctly process. therefore, in many practical cases, it might be better to use an unsupervised approach, where ood instances are detected using uncertainty estimation (ue) methods. ## out-of-domain detection methods ood detection using uncertainty estimation is a binary classification task, where an uncertainty score u (x) of a given input x is a predictor of x coming from an unknown domain. in practice, a threshold δ is specified so that all x : u (x) > δ are considered to be ood. the task of text generation involves complex autoregressive probabilistic models and usually requires making not one but multiple predictions (one per output token). these two factors make ue of predictions in text generation tasks much more complicated than in standard text classification tasks. below, we provide a short overview of the approaches for uncertainty estimation of autoregressive model predictions investigated in our work. more comprehensive details can be found in appendix a. all methods described below can be applied to the majority of modern transformerbased pre-trained seq2seq models. ## experiments following @xcite , we use two approaches to generating ood data for a given "in-domain" (id) dataset. in the first approach, we simply take texts from another dataset, which is distinct from the training set of the model in terms of domain and/or structure. in the second approach, we corrupt the dataset by randomly permuting the source tokens (prm). the details of ood data creation are provided in appendix b. following the previous works on ood detection (hendrycks and gimpel, 2017; malinin and gales, 2020), we report the au-roc scores of detecting ood instances mixed into the test set. to ensure stability, we run each experiment with 5 different random seeds and report the standard deviation. for brevity, in the main part, we report the results of only the two best-performing methods from each method group. hardware configuration for experiments is provided in appendix b. 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 nsp entropy md-enc. rde-enc. pe-s-tu pe-t-mi rubq2-mintaka rubq2-prm rubq2-rubq2ru figure 3: average roc curves for qa task on datasets with links to wikidata kg. the first dataset in the title is the id dataset, the second represents the ood dataset. also, the language is english except for the case with "ru", which identifies the russian language. ## conclusion we adopted the density-based ue methods for seq2seq models and demonstrated that they provide the best results in ood detection across three sequence generation tasks: nmt, ats, and qa. they appear to be superior to the ensemble-based methods in terms of both performance and compute time, which makes them a good choice for applying in practice. in future work, we are going to extend the application of density-based methods to seq2seq models in other ue tasks such as selective classification.