TL;DR
This paper introduces "Avg-Avg," a simple yet highly effective method for improving out-of-distribution (OOD) detection in NLP models. By averaging token representations across all intermediate layers of a pre-trained language model (PLM), Avg-Avg creates more holistic sentence embeddings that significantly outperform existing methods, offering a "free gain" in OOD detection capabilities.
What Problem Does This Paper Address?
Deploying NLP models in real-world applications means they will inevitably encounter data that differs from their training distribution – these are known as out-of-distribution (OOD) samples. When models encounter OOD data, they can produce unreliable or even nonsensical outputs, posing a significant risk. Detecting these OOD instances is crucial for safe and robust NLP systems. Current state-of-the-art methods for textual OOD detection often rely on distance-based approaches using embeddings from the final layer of pre-trained language models (PLMs). However, these methods typically only use the special [CLS] token's embedding, which is optimized for the in-distribution classification task and may not fully capture the rich linguistic information embedded within the PLM's intermediate layers. This paper aims to bridge this gap by proposing a method to derive more informative sentence embeddings that are better suited for OOD detection.
Methods
The core of this paper's contribution lies in a novel sentence embedding strategy called Avg-Avg. This method builds upon two observations:
- Intra-Layer Token Averaging: Instead of solely relying on the
[CLS]token's representation at each layer, Avg-Avg averages the embeddings of all tokens within that layer. This captures a broader representation of the sentence's meaning at that specific layer. - Inter-Layer Combination: Avg-Avg then combines the averaged representations from all intermediate layers of the PLM. This holistic approach leverages the hierarchical linguistic information learned by the PLM across its depth.
The authors propose this as a simple, plug-and-play post-processing technique. For OOD detection, they then apply a distance-based method (Mahalanobis distance) to these newly derived Avg-Avg embeddings.
Datasets
The paper evaluates its method on several standard NLP datasets for in-distribution (ID) tasks and uses various datasets for out-of-distribution (OOD) evaluation.
In-Distribution (ID) Datasets: * SST-2 (Sentiment Analysis) * IMDB (Sentiment Analysis) * TREC-10 (Question Classification) * 20 Newsgroups (Topic Classification)
Out-of-Distribution (OOD) Datasets: * Multi30k (Machine Translation) * WMT-16 (Machine Translation) * RTE (Recognising Textual Entailment) * SNLI (Natural Language Inference)
The paper also uses specific datasets for analyzing different types of distribution shifts:
- Background Shift: Customer Reviews (OOD) relative to SST-2 (ID), and News Rest (OOD) relative to News Top-5 (ID).
- Semantic Shift: CLINC (ID) and CLINCOOD (OOD) for intent classification.
Key Insights and Ideas
- The
[CLS]token is not king for OOD detection: The paper strongly suggests that relying solely on the[CLS]token's final layer embedding is suboptimal for OOD detection, as it overlooks valuable information in intermediate layers. - Holistic embeddings are key: Averaging token representations within layers and combining information across layers creates richer, more robust sentence embeddings that better distinguish between in-distribution and out-of-distribution data.
- Avg-Avg is a "free lunch": The proposed Avg-Avg method is simple to implement and adds negligible computational cost during inference, yet provides significant performance gains.
- Background shifts are the main benefactor: The analysis shows that Avg-Avg is particularly effective at detecting background shifts (changes in data style, domain, etc.) while still improving semantic shift detection. This highlights its ability to capture general linguistic knowledge.
Key Results
- State-of-the-art performance: The Avg-Avg method significantly outperforms existing OOD detection methods, achieving a remarkable 9.33% FAR95 margin averaged across multiple benchmarks.
- Superiority over baselines: On the SST-2 vs. 20NG benchmark, Avg-Avg achieved an AUROC of 99.99%, compared to the default last-layer CLS pooling at 90.48%.
- Consistent improvement across PLMs: The benefits of Avg-Avg were demonstrated across different PLM backbones, including BERT and RoBERTa.
- Improved linguistic representation: Probing tasks show that Avg-Avg embeddings lead to higher accuracies in surface, syntactic, and semantic level understanding, indicating a more comprehensive capture of linguistic information.
- Visualization confirms separation: t-SNE visualizations show a much clearer separation between in-distribution and OOD samples when using Avg-Avg embeddings compared to the default CLS embeddings.
Limitations and Future Work
- Theoretical justification: The authors acknowledge that while Avg-Avg's effectiveness is empirically proven, a strict theoretical justification is still lacking.
- Small performance gap to ideal: There remains a small performance gap between Avg-Avg and an "ideal upper bound" (as shown in Figure 1), suggesting room for further improvement.
- Future work: The authors plan to explore theory-guaranteed embedding approaches to further enhance OOD detection capabilities. They also express interest in extending these ideas to training-time methods.
Summary updated