mlsanityData to 7 Oct 2026

Contrastive Out-of-Distribution Detection for Pretrained Transformers

arXiv 2104.08812 ↗First posted 18 Apr 2021cs.CLcited by 70

Not on the map. Why?

Abstract (arXiv)

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.

Key facts. Cited by 70 papers in the map (data through 7 Oct 2026). Builds on 36 of its 54 references that are in the map. First posted on arXiv 18 Apr 2021.

Builds on

36 of 54 references.

References · 36

  1. 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
  2. 2014Adam: A Method for Stochastic Optimizationcited by 36,960
  3. 2019RoBERTa: A Robustly Optimized BERT Pretraining Approachcited by 13,266
  4. 2020A Simple Framework for Contrastive Learning of Visual Representationscited by 11,979
  5. 2018Representation Learning with Contrastive Predictive Codingcited by 7,662
  6. 2019Momentum Contrast for Unsupervised Visual Representation Learningcited by 7,482
  7. 2018GLUE: A Multi-Task Benchmark and Analysis Platform for Natural Language Understandingcited by 4,854
  8. 2016SQuAD: 100,000+ Questions for Machine Comprehension of Textcited by 4,115
  9. 2020Supervised Contrastive Learningcited by 2,803
  10. 2017A Broad-Coverage Challenge Corpus for Sentence Understanding through Inferencecited by 2,665
  11. 2016A Baseline for Detecting Misclassified and Out-of-Distribution Examples in Neural Networkscited by 2,362
  12. 2016Concrete Problems in AI Safetycited by 1,582
24 more
  1. 2018A Simple Unified Framework for Detecting Out-of-Distribution Samples and Adversarial Attackscited by 1,472
  2. 2020Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hyperspherecited by 1,393
  3. 2017Enhancing The Reliability of Out-of-distribution Image Detection in Neural Networkscited by 1,325
  4. 2020Energy-based Out-of-distribution Detectioncited by 1,296
  5. 2018Neural Network Acceptability Judgmentscited by 952
  6. 2018Deep Anomaly Detection with Outlier Exposurecited by 939
  7. 2019Self-Supervised Learning of Pretext-Invariant Representationscited by 806
  8. 2018Deep Visual Domain Adaptation: A Surveycited by 634
  9. 2015Towards Open Set Deep Networkscited by 533
  10. 2020CSI: Novelty Detection via Contrastive Learning on Distributionally Shifted Instancescited by 441
  11. 2020Generalized ODIN: Detecting Out-of-distribution Image without Learning from Out-of-distribution Datacited by 408
  12. 2017Training Confidence-calibrated Classifiers for Detecting Out-of-Distribution Samplescited by 389
  13. 2019An Evaluation Dataset for Intent Classification and Out-of-Scope Predictioncited by 378
  14. 2020Pretrained Transformers Improve Out-of-Distribution Robustnesscited by 293
  15. 2020Supervised Contrastive Learning for Pre-trained Language Model Fine-tuningcited by 275
  16. 2016Multi30K: Multilingual English-German Image Descriptionscited by 250
  17. 2020DeCLUTR: Deep Contrastive Learning for Unsupervised Textual Representationscited by 249
  18. 2020Classification-Based Anomaly Detection for General Datacited by 210
  19. 2020Contrastive Training for Improved Out-of-Distribution Detectioncited by 186
  20. 2018Reducing Network Agnostophobiacited by 165
  21. 2018Out-of-Distribution Detection Using an Ensemble of Self Supervised Leave-out Classifierscited by 126
  22. 2017DOC: Deep Open Classification of Text Documentscited by 109
  23. 2019Out-of-Domain Detection for Low-Resource Text Classification Taskscited by 36
  24. 2018Joint Learning of Domain Classification and Out-of-Domain Detection with Dynamic Class Weighting for Satisficing False Acceptance Ratescited by 17

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2021: 1; 2022: 17; 2023: 28; 2024: 13; 2025: 7; 2026: 4.

70 papers.

Sort:

By area:

  1. 2023Trustworthy LLMs: a Survey and Guideline for Evaluating Large Language Models' Alignmentcited by 394
  2. 2022Delving into Out-of-Distribution Detection with Vision-Language Representationscited by 215
  3. 2022Out-of-Distribution Detection and Selective Generation for Conditional Language Modelscited by 193
  4. 2022POEM: Out-of-Distribution Detection with Posterior Samplingcited by 108
  5. 2023A Survey of Safety and Trustworthiness of Large Language Models through the Lens of Verification and Validationcited by 91
  6. 2021Types of Out-of-Distribution Texts and How to Detect Themcited by 80
  7. 2023Context-faithful Prompting for Large Language Modelscited by 76
  8. 2022GOOD-D: On Unsupervised Graph Out-Of-Distribution Detectioncited by 47
  9. 2022Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognitioncited by 44
  10. 2023Uncertainty in Natural Language Processing: Sources, Quantification, and Applicationscited by 44
  11. 2023A Survey on Out-of-Distribution Detection in NLPcited by 31
  12. 2023Is Fine-tuning Needed? Pre-trained Language Models Are Near Perfect for Out-of-Domain Detectioncited by 29
38 more
  1. 2022Rainproof: An Umbrella To Shield Text Generators From Out-Of-Distribution Datacited by 21
  2. 2022Does Your Model Classify Entities Reasonably? Diagnosing and Mitigating Spurious Correlations in Entity Typingcited by 16
  3. 2023EAT: Towards Long-Tailed Out-of-Distribution Detectioncited by 16
  4. 2023Unsupervised Layer-wise Score Aggregation for Textual OOD Detectioncited by 15
  5. 2023How Good Are LLMs at Out-of-Distribution Detection?cited by 15
  6. 2023Fine-Tuning Deteriorates General Textual Out-of-Distribution Detection by Distorting Task-Agnostic Featurescited by 12
  7. 2023Exploring Large Language Models for Multi-Modal Out-of-Distribution Detectioncited by 12
  8. 2022Towards Computationally Feasible Deep Active Learningcited by 11
  9. 2022Estimating Soft Labels for Out-of-Domain Intent Detectioncited by 11
  10. 2022Multi-Level Knowledge Distillation for Out-of-Distribution Detection in Textcited by 11
  11. 2024Does DetectGPT Fully Utilize Perturbation? Bridging Selective Perturbation to Fine-tuned Contrastive Learning Detector would be Bettercited by 11
  12. 2024Your Finetuned Large Language Model is Already a Powerful Out-of-distribution Detectorcited by 11
  13. 2022Enhancing Out-of-Distribution Detection in Natural Language Understanding via Implicit Layer Ensemblecited by 9
  14. 2024SeTAR: Out-of-Distribution Detection with Selective Low-Rank Approximationcited by 9
  15. 2022The future is different: Large pre-trained language models fail in prediction taskscited by 8
  16. 2023Bag of Tricks for In-Distribution Calibration of Pretrained Transformerscited by 7
  17. 2024Multitask Active Learning for Graph Anomaly Detectioncited by 7
  18. 2025Shh, don't say that! Domain Certification in LLMscited by 7
  19. 2023Out-of-Domain Intent Detection Considering Multi-Turn Dialogue Contextscited by 6
  20. 2025Training-Free Policy Violation Detection via Activation-Space Whitening in LLMscited by 6
  21. 2022Self-Supervised Losses for One-Class Textual Anomaly Detectioncited by 5
  22. 2023Classical Out-of-Distribution Detection Methods Benchmark in Text Classification Taskscited by 5
  23. 2023Pseudo Outlier Exposure for Out-of-Distribution Detection using Pretrained Transformerscited by 5
  24. 2024Learning Shortcuts: On the Misleading Promise of NLU in Language Modelscited by 4
  25. 2024Conformal Intent Classification and Clarification for Fast and Accurate Intent Recognitioncited by 4
  26. 2024Dual-Adapter: Training-free Dual Adaptation for Few-shot Out-of-Distribution Detectioncited by 4
  27. 2024A new approach for fine-tuning sentence transformers for intent classification and out-of-scope detection taskscited by 4
  28. 2025MGT-Prism: Enhancing Domain Generalization for Machine-Generated Text Detection via Spectral Alignmentcited by 4
  29. 2022Out-of-distribution Detection by Cross-class Vicinity Distribution of In-distribution Datacited by 3
  30. 2022Beyond Mahalanobis-Based Scores for Textual OOD Detectioncited by 3
  31. 2023VendorLink: An NLP approach for Identifying & Linking Vendor Migrants & Potential Aliases on Darknet Marketscited by 3
  32. 2023DEnsity: Open-domain Dialogue Evaluation Metric using Density Estimationcited by 3
  33. 2023SELFOOD: Self-Supervised Out-Of-Distribution Detection via Learning to Rankcited by 3
  34. 2023RoAST: Robustifying Language Models via Adversarial Perturbation with Selective Trainingcited by 3
  35. 2024Out-of-Distribution Detection through Soft Clustering with Non-Negative Kernel Regressioncited by 3
  36. 2025Structural Entropy Guided Unsupervised Graph Out-Of-Distribution Detectioncited by 3
  37. 2023Probing Out-of-Distribution Robustness of Language Models with Parameter-Efficient Transfer Learningcited by 2
  38. 2022Contrastive Novelty-Augmented Learning: Anticipating Outliers with Large Language Modelscited by 1

50 most cited of 70 All 70 (JSON)