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 task-oriented dialog systems, identifying user intents is critical. However, a significant challenge arises when a user provides a query that falls outside the system's pre-defined capabilities. This is known as Out-of-Domain (OOD) detection. Traditional models trained with standard Cross-Entropy (CE) loss often struggle with this, as they prioritize finding decision boundaries rather than learning compact, well-separated representations.

This paper proposes a novel framework using Supervised Contrastive Learning (SCL) and adversarial data augmentation to create a more discriminative feature space. This approach facilitates more effective OOD detection without requiring any labeled OOD samples during training.

Methodology: Shaping the Latent Space

The core idea is to move beyond the "lazy" nature of Cross-Entropy loss. While CE ensures samples are on the correct side of a boundary, it does not necessarily enforce large margins between classes or tight clustering within them. This leaves "gray areas" where OOD samples can be misclassified with high confidence.

The authors introduce a two-stage training pipeline to create a more discriminative feature space:

  1. Supervised Contrastive Learning (SCL) with Adversarial Augmentation: The model is first trained to pull samples of the same intent closer together while pushing different intents further apart. To make this robust, the authors use an adversarial attack mechanism (Fast Gradient Value) to generate "hard" positive samples in the latent space.
  2. Fine-tuning: After the feature space is "shaped" by SCL, the encoder is fine-tuned using standard classification losses like Cross-Entropy or Large Margin Cosine Loss (LMCL).
Figure 2: The proposed architecture and conceptual shift in feature representation from standard CE to SCL+CE.

At inference time, traditional outlier detection algorithms such as Gaussian Discriminant Analysis (GDA) or Local Outlier Factor (LOF) are applied to these discriminative features to flag OOD queries.

Experimental Results

The method was evaluated on the CLINC-Full and CLINC-Small benchmarks, representing standard and low-resource scenarios respectively.

Improved OOD and IND Performance

The SCL+CE approach consistently outperformed baselines across different encoders (LSTM and BERT). On the CLINC-Full dataset using an LSTM encoder, the method improved OOD Recall by 3.08% and the F1-score by 2.45%. Notably, the tighter clustering also improved In-Domain (IND) accuracy by 0.67% to 1.49%, demonstrating that better feature organization benefits general classification.

Visualizing Discriminative Features

The impact of SCL is most apparent when visualizing the latent space. PCA plots demonstrate that SCL leads to significantly tighter intent clusters and larger distances between similar intents that typically confuse standard models. This visual evidence confirms that the model successfully creates a larger "no-man's land" where OOD samples naturally fall.

Figure 6: PCA visualization of intent clusters, showing the increased discriminative power and tighter grouping of the learned representations.

Key Insights

  • The "Empty Space" Strategy: By maximizing inter-class variance, the model creates a larger gap in the feature space. OOD samples fall into these gaps, making them much easier to isolate from known intents.
  • Pre-training vs. Multitask Learning: The authors found that a two-stage approach (SCL pre-training followed by CE fine-tuning) is superior to joint multitask training, which can actually hurt performance.
  • Data Efficiency: The performance gains were particularly significant on the CLINC-Small dataset, suggesting that contrastive learning is highly effective for learning intent structures from limited data.

Conclusion

By combining Supervised Contrastive Learning with adversarial augmentation, this work provides a robust framework for unsupervised OOD detection. The resulting discriminative representations not only improve the detection of unknown queries but also enhance the accuracy of known intent classification, particularly in data-scarce environments.

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