Lune

EMNLP2021Top-tier venue

Contrastive Out-of-Distribution Detection for Pretrained Transformers

Wenxuan Zhou, Fangyu Liu, Muhao Chen

Abstract

Pretrained Transformers achieve remarkable performance when training and test data are from the same distribution. However, in real-world scenarios, the model often faces out-of-distribution (OOD) instances that can cause severe semantic shift problems at inference time. Therefore, in practice, a reliable model should identify such instances, and then either reject them during inference or pass them over to models that handle another distribution. In this paper, we develop an unsupervised OOD detection method, in which only the in-distribution (ID) data are used in training. We propose to fine-tune the Transformers with a contrastive loss, which improves the compactness of representations, such that OOD instances can be better differentiated from ID ones. These OOD instances can then be accurately detected using the Mahalanobis distance in the model's penultimate layer. We experiment with comprehensive settings and achieve near-perfect OOD detection performance, outperforming baselines drastically. We further investigate the rationales behind the improvement, finding that more compact representations through margin-based contrastive learning bring the improvement. We release our code to the community for future research.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

30 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognition cites Energy-based Out-of-distribution Detection
  • Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognition cites Supervised Contrastive Learning
  • Delving into Out-of-Distribution Detection with Vision-Language Representations cites Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognition
  • Delving into Out-of-Distribution Detection with Vision-Language Representations cites Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere
  • Delving into Out-of-Distribution Detection with Vision-Language Representations cites POEM: Out-of-Distribution Detection with Posterior Sampling
  • Delving into Out-of-Distribution Detection with Vision-Language Representations cites Energy-based Out-of-distribution Detection
  • Delving into Out-of-Distribution Detection with Vision-Language Representations cites CSI: Novelty Detection via Contrastive Learning on Distributionally Shifted Instances
  • Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere cites A Simple Framework for Contrastive Learning of Visual Representations
  • POEM: Out-of-Distribution Detection with Posterior Sampling cites Energy-based Out-of-distribution Detection
  • POEM: Out-of-Distribution Detection with Posterior Sampling cites Supervised Contrastive Learning
  • Beyond Mahalanobis Distance for Textual OOD Detection cites Energy-based Out-of-distribution Detection
  • A Data-centric Framework to Endow Graph Neural Networks with Out-Of-Distribution Detection Ability cites Energy-based Out-of-distribution Detection
  • Supervised Contrastive Learning cites Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere
  • Supervised Contrastive Learning cites A Simple Framework for Contrastive Learning of Visual Representations
  • CSI: Novelty Detection via Contrastive Learning on Distributionally Shifted Instances cites A Simple Framework for Contrastive Learning of Visual Representations
  • CSI: Novelty Detection via Contrastive Learning on Distributionally Shifted Instances cites Supervised Contrastive Learning
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers30

  1. Delving into Out-of-Distribution Detection with Vision-Language RepresentationsYifei Ming, Ziyang Cai, Jiuxiang Gu, Yiyou Sun et al.NeurIPS 2022 · 308 citations
  2. POEM: Out-of-Distribution Detection with Posterior SamplingYifei Ming, Ying Fan, Yixuan LiICML 2022 · 151 citations
  3. Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed RecognitionHaotao Wang, Aston Zhang, Yi Zhu, Shuai Zheng et al.ICML 2022 · 61 citations
  4. A Data-centric Framework to Endow Graph Neural Networks with Out-Of-Distribution Detection AbilityYuxin Guo, Cheng Yang, Yuluo Chen, Jixi Liu et al.KDD 2023 · 26 citations
  5. Beyond Mahalanobis Distance for Textual OOD DetectionPierre Colombo, Eduardo Dadalto Câmara Gomes, Guillaume Staerman, Nathan Noiry et al.NeurIPS 2022 · 24 citations

Builds on10

  1. A Simple Framework for Contrastive Learning of Visual RepresentationsTing Chen, Simon Kornblith, Mohammad Norouzi, Geoffrey E. HintonICML 2020 · 24,064 citations
  2. Supervised Contrastive LearningPrannay Khosla, Piotr Teterwak, Chen Wang, Aaron Sarna et al.NeurIPS 2020 · 7,049 citations
  3. Understanding Contrastive Representation Learning through Alignment and Uniformity on the HypersphereTongzhou Wang, Phillip IsolaICML 2020 · 2,360 citations
  4. Energy-based Out-of-distribution DetectionWeitang Liu, Xiaoyun Wang, John D. Owens, Yixuan LiNeurIPS 2020 · 2,213 citations
  5. CSI: Novelty Detection via Contrastive Learning on Distributionally Shifted InstancesJihoon Tack, Sangwoo Mo, Jongheon Jeong, Jinwoo ShinNeurIPS 2020 · 755 citations

Related papers

  1. Is Fine-tuning Needed? Pre-trained Language Models Are Near Perfect for Out-of-Domain DetectionRheeya Uppaal, Junjie Hu, Yixuan LiACL 2023 · 9 citations
  2. On Prefix-tuning for Lightweight Out-of-distribution DetectionYawen Ouyang, Yongchang Cao, Yuan Gao, Zhen Wu et al.ACL 2023 · 1 citation
  3. X-Mahalanobis: Transformer Feature Mixing for Reliable OOD DetectionTong Wei, Bolin Wang, Jiang-Xin Shi, Yu-Feng Li et al.NeurIPS 2025 · 9 citations
  4. Gradient-Based Novelty Detection Boosted by Self-Supervised Binary ClassificationJingbo Sun, Li Yang, Jiaxin Zhang, Frank Liu et al.AAAI 2022 · 17 citations
  5. Out-of-Distribution Detection by Leveraging Between-Layer Transformation SmoothnessFran Jelenic, Josip Jukic, Martin Tutek, Mate Puljiz et al.ICLR 2024 · 12 citations
Dusk over the sea between two cliffs drawn in fine vertical lines