Enhancing Out-of-Distribution Detection in Natural Language Understanding via Implicit Layer Ensemble (2022)

Abstract: Out-of-distribution (OOD) detection aims to discern outliers from the intended data distribution, which is crucial to maintaining high reliability and a good user experience.Most recent studies in OOD detection utilize the information from a single representation that resides in the penultimate layer to determine whether the input is anomalous or not.Although such a method is straightforward, the potential of diverse information in the intermediate layers is overlooked.In this paper, we propose a novel framework based on contrastive learning that encourages intermediate features to learn layer-specialized representations and assembles them implicitly into a single representation to absorb rich information in the pre-trained language model. Extensive experiments in various intent classification and OOD datasets demonstrate that our approach is significantly more effective than other works.

## introduction natural language understanding (nlu) in dialog systems, which often formalizes as a classification task to identify intentions behind user input, is a vital component as their decision propagates to the downstream pipelines. numerous works have achieved immense success on sundry tasks (e.g., intention classification, nli, qa) reaching parity with human performance @xcite . despite their success in many different benchmarks, neural models are known to be vulnerable to test inputs from an unknown distribution @xcite , commonly referred to as outliers, since they depend strongly on the closed-world assumption (i.e., i.i.d assumption). thus, out-of-distribution (ood) detection @xcite , which aims to discern outliers from the train distribution, is a essential research problem for ensuring a high-quality user experience and maintaining strong reliability as the systems in the wild encounter myriad unseen data ceaselessly. the most prevailing paradigm in ood detection is to extract and score. namely, it extracts the representation of the input from a neural model and passes it to a pre-defined scoring function. then, the scoring function gauges the appropriateness of the input based on the extracted feature and decides whether the input is from the normal distribution. the most common rule of thumb for extracting representation from neural models is employing the the last layer, a simple and intuitive way to obtain a holistic representation, which is universally utilized in broad machine learning areas. meanwhile, previous studies @xcite revealed that the middle layers of the language model also conceal copious information. for instance, prior studies on language model probing suggest that syntactic linguistic knowledge is most prominent in the middle layers @xcite @xcite , and semantic knowledge in bert is spread in all layers widely @xcite . in this regard, leveraging intermediate lay-ers can lead to a better ood detection performance, as they retain some complementary information to the last layer feature, which might be beneficial in discriminating outliers. several studies @xcite @xcite have shown empirical evidence that intermediate representations are indeed beneficial in detecting outliers. precisely, they attempted to utilize middle layers via naïvely aggregating the individual result of every single intermediate feature explicitly. although previous studies have shown the potential of intermediate layer representations in ood detection, we confirmed that the aforementioned naïve ensemble scheme spawns several problems: (fig. 1 illustrates ood performance of the layerwise and their explicit ensemble in two different datasets.) the first problem we observed is that the ensemble result (red bar) nor the last layer can not guarantee the best performance among the entire layer depending on the setting. such a phenomenon raises the necessity for a more elaborate approach of deriving a more meaningful ensemble representation from various representations rather than a current simple summation or selecting a single layer. secondly, even when this explicit ensemble gives a sound performance, it requires multiple computations of the scoring function by birth. thus, explicit ensemble inevitably delays the detecting time, which is a critical shortcoming in ood detection, as swift and precise decisionmaking is the cornerstone in this area. to remedy the limitations of the explicit ensemble schemes, we propose a novel framework dubbed layer-agnostic contrastive learning (lacl). our framework is inspired by the foundation of an ensemble, which seeks a more calibrated output by combining heterogeneous decisions from multiple models @xcite . specifically, lacl regards intermediate layers as independent decision-makers and assembles them into a single vector to yield a more accurate prediction: lacl makes middlelayer representations richer and more diverse by injecting the advantage of contrastive learning (cl) into intermediate layers while suppressing interlayer representations from being similar through additional regularization loss. then, lacl assembles them into a single ensemble representation implicitly to circumvent multiple computations of the scoring function. we demonstrate the effectiveness of our ap-proach in 9 different ood scenarios where lacl consistently surpasses other competitive works and their explicit ensemble performance by a significant margin. moreover, we conducted an in-depth analysis of lacl to elucidate its behavior in conjunction with our intuition. contrastive learning & ood detection. among the numerous approaches mentioned, contrastive learning (cl) based methods @xcite @xcite are recently spurring predominant interest in ood detection research. the superiority of cl in ood detection comes from the fact that it can guide a neural model to learn semantic similarity within data instances. such property is also precious for unsupervised ood detection, as there is no accessible clue regarding outliers or abnormal distribution. despite its potential, cl has been utilized in the computer vision field @xcite @xcite in the early works due to its high reliance on data augmentation. however, now it is also widely used in various nlp applications with the help of recent progress @xcite @xcite @xcite . specifically, @xcite verified that cl is also helpful in the nlp field, and @xcite ; @xcite redesigned the contrastive-learning objective into a more appropriate form for ood detection. ## analysis in this section, we conduct supplementary experiments on lacl to analyze our framework in-depth to elucidate its behavior. ## conclusion in this study, we propose a novel framework called lacl to improve ood detection by leveraging intermediate representations. our framework seeks a more calibrated output by combining layerspecialized representations from each layer via a layer-agnostic training scheme and novel regularization loss. through extensive experiments and ablations, we have demonstrated the potential of intermediate representations in ood detection and the effectiveness of our framework, which significantly outperforms other existing works.