Introduction
Detecting out-of-domain (OOD) text—instances where a user input falls outside a model's intended scope—is critical for robust AI systems. Traditionally, this task relies on labeled in-domain (ID) data. However, in many practical scenarios, such as early-stage prototyping, only raw, unlabeled ID text is available. This paper proposes a novel unsupervised approach that combines clustering with contrastive learning to establish clear boundaries for ID data, significantly outperforming traditional likelihood-based methods.
Problem Statement: The Challenge of Unlabeled OOD Detection
In real-world applications, a model must identify what it does not know. For example, a flight-booking assistant should flag a query about the weather as OOD rather than attempting to process it. Most existing OOD detection frameworks require ID category labels (e.g., "BookFlight" vs. "CheckStatus"). Without these labels, standard classifiers cannot be trained. This research investigates how to effectively detect OOD samples using only a collection of unlabeled in-domain text.
Methodology
The authors explore two primary technical directions:
1. Language Model (LM) Likelihood
These methods assume ID samples will have higher likelihoods than OOD samples when evaluated by a model trained on ID text. The study evaluates Likelihood Ratio (LR)—comparing an in-domain LM against a background LM—and introduces Normalized Likelihood Ratio (NLR) to mitigate biases related to sentence length.
2. Adaptive Representation Learning
The core contribution is a two-step pipeline. First, a sentence encoder (e.g., DistilBERT) is fine-tuned using a joint objective of unsupervised clustering and contrastive learning. Clustering identifies latent sub-groups within the ID data, while contrastive learning ensures these groups are distinct and compact. Second, a Gaussian Mixture Model (GMM) is fitted to the resulting vectors to estimate density and flag OOD samples.
Key Insights and Results
The proposed representation learning method ("Ours") demonstrated substantial improvements over likelihood-based baselines and approached the performance of supervised models.
Synergy of Clustering and Contrastive Learning
Clustering helps the model discover hidden classes, while contrastive learning tightens these clusters. This creates "sharp boundaries" that prevent OOD samples from being misclassified as ID. As shown in the t-SNE visualizations, the ID data forms distinct clusters that are well-separated from the OOD samples.
Performance Comparison
On the Searchsnippets dataset, the proposed method achieved an AUROC of 94.70%, far exceeding the 82.68% of the best likelihood method. On SNIPS, it reached a False Positive Rate (at 95% TPR) of 8.53%, nearly matching the supervised DistilBERT-Maha baseline of 8.65%.
Conclusion and Future Work
While highly effective, the method faced challenges on the Stackoverflow dataset due to the high similarity between ID and OOD programming topics. Future research could focus on automated selection of the optimal cluster count ($K$) or extending these techniques to multi-modal data. Additionally, scaling the base encoder may further enhance performance.
Summary updated