Abstract
Detecting out-of-distribution (OOD) inputs is crucial for the safe deployment of natural language processing (NLP) models. Though existing methods, especially those based on the statistics in the feature space of fine-tuned pre-trained language models (PLMs), are claimed to be effective, their effectiveness on different types of distribution shifts remains underexplored. In this work, we take the first step to comprehensively evaluate the mainstream textual OOD detection methods for detecting semantic and non-semantic shifts. We find that: (1) no existing method behaves well in both settings; (2) fine-tuning PLMs on in-distribution data benefits detecting semantic shifts but severely deteriorates detecting non-semantic shifts, which can be attributed to the distortion of task-agnostic features. To alleviate the issue, we present a simple yet effective general OOD score named GNOME that integrates the confidence scores derived from the task-agnostic and task-specific representations. Experiments show that GNOME works well in both semantic and non-semantic shift scenarios, and further brings significant improvement on two cross-task benchmarks where both kinds of shifts simultaneously take place.
Introduction
As NLP models move from research to real-world deployment, the ability to identify Out-of-Distribution (OOD) data—inputs that differ significantly from the training distribution—becomes a safety requirement. Ideally, a model should flag such inputs rather than providing overconfident, erroneous predictions.
Distribution shifts are generally categorized into two types: Semantic Shifts (SS), where the input belongs to an unseen category (e.g., a news classifier encountering a recipe), and Non-Semantic Shifts (NSS), where the topic remains the same but the domain or style changes (e.g., movie reviews vs. informal tweets). This paper identifies a critical trade-off: current fine-tuning practices optimize models for semantic detection at the expense of non-semantic robustness.
The Impact of Fine-Tuning on Feature Representation
The authors perform a probing analysis to investigate why fine-tuned models struggle with domain changes. They demonstrate that fine-tuning is a "destructive" process for general OOD detection. As a model specializes in a specific task, it collapses its feature space to focus exclusively on task-specific discriminators, discarding "task-agnostic" linguistic cues such as syntax, sentence length, or bigram patterns.
As shown in the training dynamics, while test accuracy on the target task improves, the model's ability to detect various distribution shifts (measured by AUROC) often declines. This distortion of task-agnostic features creates a "blind spot" for non-semantic shifts.
GNOME: A Hybrid Scoring Approach
To address this trade-off, the authors propose GNOME (GeNeral textual OOD Measurement scorE). The method is designed to capture both task-agnostic and task-specific features without requiring complex retraining or auxiliary outlier datasets.
GNOME utilizes a Dual-Feature Scoring mechanism:
- Task-Agnostic Score ($MD_{pre}$): Calculates the Mahalanobis distance in the feature space of the original pre-trained model.
- Task-Specific Score ($MD_{ft}$): Calculates the Mahalanobis distance in the feature space of the fine-tuned model.
These scores are standardized using z-score normalization based on a small in-distribution validation set and then averaged. This allows GNOME to leverage the "generalist" knowledge of the pre-trained model to catch domain shifts and the "specialist" knowledge of the fine-tuned model to catch topic shifts.
Experimental Evaluation and Results
The effectiveness of GNOME was tested across a comprehensive suite of benchmarks, including NSS scenarios (e.g., SST-2 vs. IMDB), SS scenarios (e.g., held-out classes in AGNews), and complex cross-task benchmarks where both shifts occur simultaneously.
As illustrated in the performance scatter plot, traditional methods typically fail in at least one scenario. Methods relying on pre-trained features (like $MD_{pre}$) excel at NSS but fail at SS, while fine-tuned methods (like $MD_{ft}$) show the opposite trend. GNOME (represented by the green star) is the only method that achieves low FAR95 (False Alarm Rate at 95% True Positive Rate) in both scenarios. On average, GNOME outperformed the previous state-of-the-art by 8.13 points in FAR95 across eight benchmarks.
Conclusion
This work highlights a fundamental limitation in current NLP fine-tuning: the distortion of task-agnostic features leads to poor OOD detection in non-semantic shift scenarios. GNOME provides a simple, effective remedy by aggregating features from both pre-trained and fine-tuned states. While GNOME requires two forward passes, it sets a new benchmark for robust OOD detection. Future research may focus on decoupling these features within a single model to improve inference efficiency.
Summary updated