Introduction
Modern Pre-trained Language Models (PLMs) such as BERT and RoBERTa frequently exhibit overconfidence, assigning high-probability class labels even to Out-of-Distribution (OOD) samples. This behavior poses significant safety risks in critical real-world applications like medical diagnosis or automated customer support. While Outlier Exposure (OE) techniques exist to mitigate this by training on auxiliary "garbage" datasets, they suffer from high data collection burdens and poor generalization if the auxiliary data differs significantly from test-time OOD samples.
This paper introduces Pseudo Outlier Exposure (POE), a novel framework that generates synthetic "near-OOD" surrogate samples directly from the In-Distribution (ID) training data. By sequentially masking informative tokens, POE enables models to learn sharper decision boundaries without requiring external outlier datasets.
Methodology
The POE process involves three main stages: identifying critical tokens, sequential masking to induce feature space drift, and training with a specialized contrastive loss.
1. Token Identification and Sequential Masking
Using the Transformer's attention mechanism, specifically the attention scores relative to the [CLS] token in the final layer, the method identifies tokens most influential to the model's prediction. These tokens are then replaced with a [MASK] token.
2. Feature Space Drift and the Mahalanobis Trigger
As informative tokens are removed, the sample's representation in the PLM's feature space drifts away from its original class cluster. To ensure these "pseudo-outliers" remain realistic and "near-OOD," the process uses the Mahalanobis distance as a trigger. Masking stops once the sample's distance exceeds the maximum distance observed in the original training set, placing the sample on the edge of the known data manifold.
3. Training with Margin-based Contrastive Loss (MCL)
The model is fine-tuned using a Margin-based Contrastive Loss (MCL). This objective encourages ID samples of the same class to cluster tightly while pushing the generated pseudo-OOD samples into a distinct $(K+1)$-th "unknown" class. This reshaping of the feature space facilitates more effective OOD detection for post-hoc methods.
Experimental Results
The authors evaluated POE across several benchmarks, including intent classification (CLINC), semantic shift (NEWS, IMDB), and domain shift (SST2 vs. Yelp).
Performance on Intent Classification
POE consistently outperformed state-of-the-art post-hoc methods. On the CLINC_FULL dataset, the combination of POE and Mahalanobis scoring achieved an AUROC of 97.66%, a notable improvement over the standard Mahalanobis baseline (97.55%) and the Max Softmax Probability (MSP) baseline (95.71%).
Key Insights
- Near-OOD Effectiveness: Training on "hard" outliers—those semantically close to ID data—is more effective than using random "easy" outliers. By masking only the most discriminative tokens, POE creates samples that lack class-specific meaning but retain the general "style" of the training data.
- Attention as Importance Proxy: Final-layer attention scores serve as an efficient and effective proxy for token importance compared to more computationally expensive methods like "Leave-One-Out" (LOO).
- Feature Space Regularization: Contrastive learning makes ID classes more compact, naturally improving the efficacy of post-hoc detection methods like Energy-based scoring or Mahalanobis distance.
Conclusion and Limitations
POE provides a "plug-and-play" solution for Transformer-based classifiers by generating outliers on-the-fly from existing data. However, its reliance on attention scores limits its direct application to non-Transformer architectures like LSTMs. Future work may explore alternative masking strategies, such as gradient-based importance, or more sophisticated token replacement methods to further enhance the naturalness of pseudo-outliers.
Summary updated