Abstract
Identifying Out-of-Domain (OOD) user intents is a critical challenge for task-oriented dialogue systems. Traditional methods often rely on forcing In-Domain (IND) features into tight global clusters, which can inadvertently "smother" OOD samples and lead to misclassification. This paper introduces KNN-Contrastive Learning, a novel framework that shifts the focus from global class compactness to local neighborhood consistency. By minimizing variance within a sample's K-Nearest Neighbors rather than the entire class, the model creates a more flexible feature space that naturally accommodates unknown intents. Experimental results across multiple benchmarks show that this approach significantly outperforms state-of-the-art methods without requiring labeled OOD training data.
Introduction
Task-oriented chatbots are designed to handle specific domains, such as banking or travel. While they excel at processing In-Domain (IND) intents, they often struggle when users provide queries outside their trained scope—known as Out-of-Domain (OOD) intents. For instance, a flight-booking bot should recognize a question about pandemic statistics as OOD rather than attempting to map it to a known flight-related intent.
Existing solutions typically attempt to model IND features using Gaussian distributions or by enforcing high global compactness. However, the authors identify two major flaws in these approaches:
- Distribution Mismatch: Empirical analysis shows that only about 57% of intent classes in standard datasets actually follow a Gaussian distribution.
- The Compactness Risk: Forcing all samples of an intent into a single tight cluster can trap OOD samples within the "convex hull" of IND data, leading to "intra-OOD" errors where the system is overconfident in a wrong prediction.
Methodology
The proposed framework utilizes a two-stage approach to learn robust semantic features for OOD detection.
KNN-Contrastive Loss ($L_{knn-cl}$)
Unlike standard contrastive learning that pulls all samples of the same class toward a single center, KNN-Contrastive Learning only pulls a sample toward its K-Nearest Neighbors of the same class. Simultaneously, it pushes the sample away from instances of different classes. This local focus allows the model to learn the underlying manifold of the data more flexibly, preserving natural gaps in the feature space.
Momentum Contrast (MoCo)
To ensure training efficiency and a diverse set of negative samples, the model employs a MoCo-style queue. This maintains a large dictionary of "negative" samples (different intents) from previous batches, providing a consistent signal for the contrastive loss to "push away" from.
Inference with Local Outlier Factor (LOF)
At inference time, the system uses the Local Outlier Factor (LOF), a density-based algorithm, to detect OOD samples. Because the KNN-contrastive training avoids forcing rigid global shapes on clusters, LOF becomes highly effective at identifying OOD samples that reside in the low-density "gaps" between or within IND clusters.
Key Insights and Ideas
The core innovation lies in how the feature space is organized. By moving away from global compactness, the model addresses the "Intra-OOD" problem—where OOD samples fall inside the boundaries of an IND class.
As shown in Figure 2, standard methods (b) can "smother" OOD intents by forcing IND samples into tight clusters. The proposed KNN approach (c) leaves more "breathing room" or physical space in the high-dimensional map, acting as a buffer where OOD intents can reside and be detected as outliers.
Experimental Results
The model was evaluated on four benchmarks: CLINC-FULL, CLINC-SMALL, BANKING, and StackOverflow. For the latter two, OOD scenarios were simulated by withholding various percentages of classes during training.
- OOD Detection Performance: On the BANKING dataset (with 25% IND classes), the KNN-Contrastive method achieved an F1-OOD score of 90.19, significantly higher than the previous state-of-the-art (ADB) at 84.56.
- Overall Accuracy: In the CLINC-FULL dataset, the model reached an Accuracy of 89.45%, outperforming the SCL+LOF baseline (84.87%).
- Robustness: The method proved particularly effective in "open space" scenarios where the number of known IND classes is small, maintaining high performance even when 75% of classes were OOD.
Conclusion and Future Work
KNN-Contrastive Learning provides a powerful, unsupervised way to improve OOD detection by rethinking how feature spaces are structured. By prioritizing local consistency over global compactness, it creates a more realistic and flexible representation of intent data.
While highly effective, the method's performance is sensitive to the choice of $k$ (number of neighbors). Future research could explore adaptive ways to determine $k$ or apply this local-consistency principle to other domains like image recognition or anomaly detection in sensor data. Additionally, optimizing the inference speed of density-based detectors like LOF remains an area for practical improvement in large-scale systems.
Summary updated