NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Types of Out-of-Distribution Texts and How to Detect Them

Udit Arora, William Huang, He HeEMNLP 2021

Presented at EMNLP 2021, this research provides a formal taxonomy for "Out-of-Distribution" (OOD) detection in Natural Language Processing. By distinguishing between shifts in what is being said versus how it is being said, the authors reveal why current detection methods often fail in unpredictable ways.

The Problem: Defining "Out-of-Distribution"

Machine learning models are notoriously overconfident. A sentiment classifier trained on movie reviews might produce a high-confidence prediction when presented with a medical paper, despite the input being completely out-of-distribution. The core challenge is that "OOD" is a fuzzy term—it could refer to a change in topic, writing style, or task. Without a formal definition, researchers often compare detection methods on "apples-to-oranges" datasets. This paper proposes a formal decomposition of text features to test how standard detection algorithms handle different types of distribution shifts.

A Taxonomy of Textual Shifts

The authors propose that any text representation can be split into two disjoint components:

  1. Semantic Features ($\phi_s$): Features discriminative for the task (e.g., the word "excellent" in sentiment analysis).
  2. Background Features ($\phi_b$): Features invariant across labels, such as genre, style, or formality (e.g., the word "cinematography").

Using these definitions, they evaluate two primary detection approaches:

  • Calibration (Maximum Softmax Probability - MSP): Uses the model’s own confidence score. If the model is "unsure," the input is flagged as OOD.
  • Density Estimation (Perplexity - PPL): Uses a language model (like GPT-2) to estimate how likely a sequence is. If the text is "unusual" compared to training data, it is flagged as OOD.
Figure 2: Comparison of density estimation $p(x)$ and calibration $p(y|x)$ scores. Calibration methods are blind to background shifts, leading to failure cases where OOD data is assigned high confidence.

Key Insights: The Blind Spot of Classifiers

The study reveals a fundamental trade-off between these methods:

  • Calibration's Semantic Focus: Calibration methods (MSP) are almost entirely driven by semantic features. Because a classifier learns to ignore "background" noise to perform its task, it becomes blind to background shifts. If the style changes but the sentiment words remain, the classifier stays confident—and fails to detect the OOD input.
  • Density Estimation's Sensitivity: Density estimation (PPL) is sensitive to both semantic and background features. While this makes it excellent at catching domain shifts, it can be too sensitive, sometimes performing worse than random when the shift is purely semantic.
  • The Repetition Trap: Language models often assign very high likelihoods to repetitive text (e.g., "and true is true is true..."). This allows "nonsense" OOD examples to bypass PPL-based detection.

Experimental Results

The authors validated their theory across 14 pairs of In-Distribution (ID) and OOD datasets, including semantic shifts (DBPedia) and background shifts (SST-2 to IMDB).

Figure 5: Performance of Calibration vs. Density Estimation across semantic and background shifts. Calibration excels at semantic shifts, while Density Estimation is superior for background shifts.
  • Semantic Shift: Calibration (MSP) consistently wins. On DBPedia, MSP achieved an 88.8 AUROC compared to PPL’s 75.4.
  • Background Shift: Density Estimation (PPL) is the clear winner. When moving from SST-2 to IMDB, PPL hit a near-perfect 97.9 AUROC, while MSP languished at 66.2.
  • Challenge Data: Both methods failed on adversarial datasets. On the HANS dataset, MSP was effectively useless (55.0 AUROC), while PPL was easily fooled by length mismatches, scoring a disastrous 19.6 AUROC.

Conclusion

In real-world scenarios, semantic and background shifts often occur simultaneously. The authors suggest that the future of OOD detection lies in hybrid models that balance the discriminative power of classifiers with the broad sensitivity of density estimators. Furthermore, the failure on challenge datasets highlights a critical need for detectors robust against simple data-augmentation artifacts like repetition.

Summary updated

BibTeX
@inproceedings{arora2021types,
  author = {Udit Arora and William Huang and He He},
  title = {{Types of Out-of-Distribution Texts and How to Detect Them}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.emnlp-main.835},
}
Figure