Modeling Discriminative Representations for Out-of-Domain Detection with Supervised Contrastive Learning

Zhiyuan Zeng, Keqing He, Yuanmeng Yan, Zijun Liu, Yanan Wu, Hong Xu, Huixing Jiang, Weiran Xu

Introduction

In modern task-oriented dialog systems, such as virtual assistants, accurately identifying user intents is paramount. These systems are typically trained on a closed set of In-Domain (IND) intents. However, real-world usage frequently involves Out-of-Domain (OOD) queries—requests that fall outside the system's predefined capabilities. Detecting these OOD samples is critical for maintaining system reliability and user trust, as it prevents the model from providing confident but incorrect responses.

Standard training paradigms, primarily relying on Cross-Entropy (CE) loss, focus on establishing decision boundaries that separate classes. While effective for classification, CE does not explicitly optimize for the geometric distribution of samples within the latent space. This often results in loose clusters with high intra-class variance, creating "fuzzy" boundaries where OOD samples can easily be misclassified as IND intents.

Methodology

To address these limitations, this work proposes a novel framework that leverages Supervised Contrastive Learning (SCL) to learn highly discriminative representations. The core idea is to reshape the embedding space such that IND intents form tight, well-separated clusters, leaving more "empty space" for OOD detection.

The proposed architecture and the conceptual shift in latent space geometry from standard CE to SCL+CE.

Two-Stage Training Pipeline

The approach follows a two-stage process:

  1. SCL Pre-training: The model is first trained to minimize the distance between embeddings of the same intent while maximizing the distance between different intents. This explicitly encourages the formation of compact clusters.
  2. Fine-tuning: Following pre-training, the model is fine-tuned using standard Cross-Entropy or Large Margin Cosine Loss (LMCL) to refine the classification boundaries.

Adversarial Data Augmentation

Contrastive learning typically requires multiple "views" of the same data point. Since text is discrete, generating meaningful augmentations is challenging. The authors employ adversarial attacks in the latent space to create "hard positive" samples. By calculating a worst-case perturbation that increases the model's loss, the system generates a challenging variant of the input, forcing the model to learn more robust and invariant features.

OOD Detection

Once the discriminative representations are learned, standard algorithms such as Gaussian Discriminant Analysis (GDA) or Local Outlier Factor (LOF) are applied. These methods measure the distance of a test query from the known IND clusters; queries exceeding a specific distance threshold are flagged as OOD.

Experimental Results

The framework was evaluated on the CLINC benchmark dataset, using both the "Full" version (150 intents, 100 samples/intent) and the "Small" version (50 samples/intent) to test performance under data scarcity.

The SCL-based approach demonstrated consistent improvements over standard baselines across various architectures, including BiLSTM and BERT. On the CLINC-Full dataset with an LSTM backbone, the SCL+CE method improved OOD Recall by 3.08% and the F1-score by 2.45% compared to standard CE training.

PCA visualization of intent clusters, demonstrating the compact and well-separated representations achieved through SCL.

Discussion and Insights

The primary advantage of SCL lies in its impact on the geometry of the embedding space. By shrinking intra-class variance, the model creates a clearer distinction between known and unknown regions. This "Few-Shot" advantage is particularly pronounced when training data is limited, as the contrastive objective helps the model capture the underlying structure of the intent categories more efficiently than label-matching alone.

Furthermore, the use of gradient-based adversarial perturbations provides a mathematically principled alternative to traditional NLP augmentation techniques like synonym replacement, which often fail to provide the necessary difficulty for effective contrastive learning.

Conclusion

This research highlights that effective OOD detection is as much about the quality of the learned representations as it is about the classification algorithm. By integrating Supervised Contrastive Learning and adversarial augmentation, dialog systems can achieve more robust performance, ensuring that "unknown" queries are identified with higher precision and recall. Future work may explore joint training objectives to streamline the pipeline and investigate the impact of limited labeled OOD data.

Summary updated

BibTeX
@inproceedings{zeng2021modeling,
  author = {Zhiyuan Zeng and Keqing He and Yuanmeng Yan and Zijun Liu and Yanan Wu and Hong Xu and Huixing Jiang and Weiran Xu},
  title = {{Modeling Discriminative Representations for Out-of-Domain Detection with Supervised Contrastive Learning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.acl-short.110},
}
Figure