Contrastive Out-of-Distribution Detection for Pretrained Transformers
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
- 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
- 2014Adam: A Method for Stochastic Optimizationcited by 36,960
- 2019RoBERTa: A Robustly Optimized BERT Pretraining Approachcited by 13,266
- 2020A Simple Framework for Contrastive Learning of Visual Representationscited by 11,979
- 2018Representation Learning with Contrastive Predictive Codingcited by 7,662
- 2019Momentum Contrast for Unsupervised Visual Representation Learningcited by 7,482
- 2018GLUE: A Multi-Task Benchmark and Analysis Platform for Natural Language Understandingcited by 4,854
- 2016SQuAD: 100,000+ Questions for Machine Comprehension of Textcited by 4,115
- 2020Supervised Contrastive Learningcited by 2,803
- 2017A Broad-Coverage Challenge Corpus for Sentence Understanding through Inferencecited by 2,665
- 2016A Baseline for Detecting Misclassified and Out-of-Distribution Examples in Neural Networkscited by 2,362
- 2016Concrete Problems in AI Safetycited by 1,582
24 more
- 2018A Simple Unified Framework for Detecting Out-of-Distribution Samples and Adversarial Attackscited by 1,472
- 2020Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hyperspherecited by 1,393
- 2017Enhancing The Reliability of Out-of-distribution Image Detection in Neural Networkscited by 1,325
- 2020Energy-based Out-of-distribution Detectioncited by 1,296
- 2018Neural Network Acceptability Judgmentscited by 952
- 2018Deep Anomaly Detection with Outlier Exposurecited by 939
- 2019Self-Supervised Learning of Pretext-Invariant Representationscited by 806
- 2018Deep Visual Domain Adaptation: A Surveycited by 634
- 2015Towards Open Set Deep Networkscited by 533
- 2020CSI: Novelty Detection via Contrastive Learning on Distributionally Shifted Instancescited by 441
- 2020Generalized ODIN: Detecting Out-of-distribution Image without Learning from Out-of-distribution Datacited by 408
- 2017Training Confidence-calibrated Classifiers for Detecting Out-of-Distribution Samplescited by 389
- 2019An Evaluation Dataset for Intent Classification and Out-of-Scope Predictioncited by 378
- 2020Pretrained Transformers Improve Out-of-Distribution Robustnesscited by 293
- 2020Supervised Contrastive Learning for Pre-trained Language Model Fine-tuningcited by 275
- 2016Multi30K: Multilingual English-German Image Descriptionscited by 250
- 2020DeCLUTR: Deep Contrastive Learning for Unsupervised Textual Representationscited by 249
- 2020Classification-Based Anomaly Detection for General Datacited by 210
- 2020Contrastive Training for Improved Out-of-Distribution Detectioncited by 186
- 2018Reducing Network Agnostophobiacited by 165
- 2018Out-of-Distribution Detection Using an Ensemble of Self Supervised Leave-out Classifierscited by 126
- 2017DOC: Deep Open Classification of Text Documentscited by 109
- 2019Out-of-Domain Detection for Low-Resource Text Classification Taskscited by 36
- 2018Joint Learning of Domain Classification and Out-of-Domain Detection with Dynamic Class Weighting for Satisficing False Acceptance Ratescited by 17
Built on by
Citing papers per year: 2021: 1; 2022: 17; 2023: 28; 2024: 13; 2025: 7; 2026: 4.
70 papers.
Sort:
By area:
- 2023Trustworthy LLMs: a Survey and Guideline for Evaluating Large Language Models' Alignmentcited by 394
- 2022Delving into Out-of-Distribution Detection with Vision-Language Representationscited by 215
- 2022Out-of-Distribution Detection and Selective Generation for Conditional Language Modelscited by 193
- 2022POEM: Out-of-Distribution Detection with Posterior Samplingcited by 108
- 2023A Survey of Safety and Trustworthiness of Large Language Models through the Lens of Verification and Validationcited by 91
- 2021Types of Out-of-Distribution Texts and How to Detect Themcited by 80
- 2023Context-faithful Prompting for Large Language Modelscited by 76
- 2022GOOD-D: On Unsupervised Graph Out-Of-Distribution Detectioncited by 47
- 2022Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognitioncited by 44
- 2023Uncertainty in Natural Language Processing: Sources, Quantification, and Applicationscited by 44
- 2023A Survey on Out-of-Distribution Detection in NLPcited by 31
- 2023Is Fine-tuning Needed? Pre-trained Language Models Are Near Perfect for Out-of-Domain Detectioncited by 29
38 more
- 2022Rainproof: An Umbrella To Shield Text Generators From Out-Of-Distribution Datacited by 21
- 2022Does Your Model Classify Entities Reasonably? Diagnosing and Mitigating Spurious Correlations in Entity Typingcited by 16
- 2023EAT: Towards Long-Tailed Out-of-Distribution Detectioncited by 16
- 2023Unsupervised Layer-wise Score Aggregation for Textual OOD Detectioncited by 15
- 2023How Good Are LLMs at Out-of-Distribution Detection?cited by 15
- 2023Fine-Tuning Deteriorates General Textual Out-of-Distribution Detection by Distorting Task-Agnostic Featurescited by 12
- 2023Exploring Large Language Models for Multi-Modal Out-of-Distribution Detectioncited by 12
- 2022Towards Computationally Feasible Deep Active Learningcited by 11
- 2022Estimating Soft Labels for Out-of-Domain Intent Detectioncited by 11
- 2022Multi-Level Knowledge Distillation for Out-of-Distribution Detection in Textcited by 11
- 2024Does DetectGPT Fully Utilize Perturbation? Bridging Selective Perturbation to Fine-tuned Contrastive Learning Detector would be Bettercited by 11
- 2024Your Finetuned Large Language Model is Already a Powerful Out-of-distribution Detectorcited by 11
- 2022Enhancing Out-of-Distribution Detection in Natural Language Understanding via Implicit Layer Ensemblecited by 9
- 2024SeTAR: Out-of-Distribution Detection with Selective Low-Rank Approximationcited by 9
- 2022The future is different: Large pre-trained language models fail in prediction taskscited by 8
- 2023Bag of Tricks for In-Distribution Calibration of Pretrained Transformerscited by 7
- 2024Multitask Active Learning for Graph Anomaly Detectioncited by 7
- 2025Shh, don't say that! Domain Certification in LLMscited by 7
- 2023Out-of-Domain Intent Detection Considering Multi-Turn Dialogue Contextscited by 6
- 2025Training-Free Policy Violation Detection via Activation-Space Whitening in LLMscited by 6
- 2022Self-Supervised Losses for One-Class Textual Anomaly Detectioncited by 5
- 2023Classical Out-of-Distribution Detection Methods Benchmark in Text Classification Taskscited by 5
- 2023Pseudo Outlier Exposure for Out-of-Distribution Detection using Pretrained Transformerscited by 5
- 2024Learning Shortcuts: On the Misleading Promise of NLU in Language Modelscited by 4
- 2024Conformal Intent Classification and Clarification for Fast and Accurate Intent Recognitioncited by 4
- 2024Dual-Adapter: Training-free Dual Adaptation for Few-shot Out-of-Distribution Detectioncited by 4
- 2024A new approach for fine-tuning sentence transformers for intent classification and out-of-scope detection taskscited by 4
- 2025MGT-Prism: Enhancing Domain Generalization for Machine-Generated Text Detection via Spectral Alignmentcited by 4
- 2022Out-of-distribution Detection by Cross-class Vicinity Distribution of In-distribution Datacited by 3
- 2022Beyond Mahalanobis-Based Scores for Textual OOD Detectioncited by 3
- 2023VendorLink: An NLP approach for Identifying & Linking Vendor Migrants & Potential Aliases on Darknet Marketscited by 3
- 2023DEnsity: Open-domain Dialogue Evaluation Metric using Density Estimationcited by 3
- 2023SELFOOD: Self-Supervised Out-Of-Distribution Detection via Learning to Rankcited by 3
- 2023RoAST: Robustifying Language Models via Adversarial Perturbation with Selective Trainingcited by 3
- 2024Out-of-Distribution Detection through Soft Clustering with Non-Negative Kernel Regressioncited by 3
- 2025Structural Entropy Guided Unsupervised Graph Out-Of-Distribution Detectioncited by 3
- 2023Probing Out-of-Distribution Robustness of Language Models with Parameter-Efficient Transfer Learningcited by 2
- 2022Contrastive Novelty-Augmented Learning: Anticipating Outliers with Large Language Modelscited by 1
50 most cited of 70 All 70 (JSON)
- 2026On the Properties of Feature Attribution for Supervised Contrastive Learning24 Apr 2026
- 2026Disentangled Graph Prompting for Out-Of-Distribution Detection31 Mar 2026
- 2026Out-of-Distribution Radar Detection with Complex VAEs: Theory, Whitening, and ANMF Fusion26 Jan 2026
- 2026Vision Also You Need: Navigating Out-of-Distribution Detection with Multimodal Large Language Model20 Jan 2026
- 2025Training-Free Policy Violation Detection via Activation-Space Whitening in LLMs3 Dec 2025
- 2025MGT-Prism: Enhancing Domain Generalization for Machine-Generated Text Detection via Spectral Alignment19 Aug 2025
- 2025Benchmarking Post-Hoc Unknown-Category Detection in Food Recognition24 Mar 2025
- 2025Unified Enhancement of the Generalization and Robustness of Language Models via Bi-Stage Optimization19 Mar 2025
- 2025Structural Entropy Guided Unsupervised Graph Out-Of-Distribution Detection5 Mar 2025
- 2025Shh, don't say that! Domain Certification in LLMs26 Feb 2025
- 2025Harnessing Feature Resonance under Arbitrary Target Alignment for Out-of-Distribution Node Detection22 Feb 2025
- 2024A new approach for fine-tuning sentence transformers for intent classification and out-of-scope detection tasks17 Oct 2024
38 more
- 2024Diversity-grounded Channel Prototypical Learning for Out-of-Distribution Intent Detection17 Sep 2024
- 2024Out-of-Distribution Detection through Soft Clustering with Non-Negative Kernel Regression18 Jul 2024
- 2024One Stone, Four Birds: A Comprehensive Solution for QA System Using Supervised Contrastive Learning12 Jul 2024
- 2024SeTAR: Out-of-Distribution Detection with Selective Low-Rank Approximation18 Jun 2024
- 2024How Out-of-Distribution Detection Learning Theory Enhances Transformer: Learnability and Reliability13 Jun 2024
- 2024Dual-Adapter: Training-free Dual Adaptation for Few-shot Out-of-Distribution Detection25 May 2024
- 2024VI-OOD: A Unified Representation Learning Framework for Textual Out-of-distribution Detection9 Apr 2024
- 2024Your Finetuned Large Language Model is Already a Powerful Out-of-distribution Detector7 Apr 2024
- 2024Conformal Intent Classification and Clarification for Fast and Accurate Intent Recognition27 Mar 2024
- 2024Does DetectGPT Fully Utilize Perturbation? Bridging Selective Perturbation to Fine-tuned Contrastive Learning Detector would be Better1 Feb 2024
- 2024Multitask Active Learning for Graph Anomaly Detection24 Jan 2024
- 2024Learning Shortcuts: On the Misleading Promise of NLU in Language Models17 Jan 2024
- 2023EAT: Towards Long-Tailed Out-of-Distribution Detection14 Dec 2023
- 2023RoAST: Robustifying Language Models via Adversarial Perturbation with Selective Training7 Dec 2023
- 2023Exploring Large Language Models for Multi-Modal Out-of-Distribution Detection12 Oct 2023
- 2023Robust Novelty Detection through Style-Conscious Feature Ranking5 Oct 2023
- 2023Environment-biased Feature Ranking for Novelty Detection Robustness21 Sep 2023
- 2023How Good Are LLMs at Out-of-Distribution Detection?20 Aug 2023
- 2023Trustworthy LLMs: a Survey and Guideline for Evaluating Large Language Models' Alignment10 Aug 2023
- 2023How Does Diffusion Influence Pretrained Language Models on Out-of-Distribution Data?26 Jul 2023
- 2023General-Purpose Multi-Modal OOD Detection Framework24 Jul 2023
- 2023Pseudo Outlier Exposure for Out-of-Distribution Detection using Pretrained Transformers18 Jul 2023
- 2023Classical Out-of-Distribution Detection Methods Benchmark in Text Classification Tasks13 Jul 2023
- 2023Contrastive Bootstrapping for Label Refinement7 Jun 2023
- 2023Uncertainty in Natural Language Processing: Sources, Quantification, and Applications5 Jun 2023
- 2023Semantic Role Labeling Guided Out-of-distribution Detection29 May 2023
- 2023SELFOOD: Self-Supervised Out-Of-Distribution Detection via Learning to Rank24 May 2023
- 2023Out-of-Distribution Generalization in Text Classification: Past, Present, and Future23 May 2023
- 2023Is Fine-tuning Needed? Pre-trained Language Models Are Near Perfect for Out-of-Domain Detection22 May 2023
- 2023A Survey of Safety and Trustworthiness of Large Language Models through the Lens of Verification and Validation19 May 2023
- 2023A Unified Evaluation Framework for Novelty Detection and Accommodation in NLP with an Instantiation in Authorship Attribution8 May 2023
- 2023DEnsity: Open-domain Dialogue Evaluation Metric using Density Estimation8 May 2023
- 2023Out-of-Domain Intent Detection Considering Multi-Turn Dialogue Contexts5 May 2023
- 2023A Survey on Out-of-Distribution Detection in NLP5 May 2023
- 2023VendorLink: An NLP approach for Identifying & Linking Vendor Migrants & Potential Aliases on Darknet Markets4 May 2023
- 2023Context-faithful Prompting for Large Language Models20 Mar 2023
- 2023Unsupervised Layer-wise Score Aggregation for Textual OOD Detection20 Feb 2023
- 2023Bag of Tricks for In-Distribution Calibration of Pretrained Transformers13 Feb 2023
50 newest of 70 All 70 (JSON)
- 2023Trustworthy LLMs: a Survey and Guideline for Evaluating Large Language Models' Alignmentcited by 394
- 2022Delving into Out-of-Distribution Detection with Vision-Language Representationscited by 215
- 2022Out-of-Distribution Detection and Selective Generation for Conditional Language Modelscited by 193
- 2022POEM: Out-of-Distribution Detection with Posterior Samplingcited by 108
- 2023A Survey of Safety and Trustworthiness of Large Language Models through the Lens of Verification and Validationcited by 91
- 2021Types of Out-of-Distribution Texts and How to Detect Themcited by 80
- 2023Context-faithful Prompting for Large Language Modelscited by 76
- 2022GOOD-D: On Unsupervised Graph Out-Of-Distribution Detectioncited by 47
- 2022Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognitioncited by 44
- 2023Uncertainty in Natural Language Processing: Sources, Quantification, and Applicationscited by 44
- 2023A Survey on Out-of-Distribution Detection in NLPcited by 31
- 2023Is Fine-tuning Needed? Pre-trained Language Models Are Near Perfect for Out-of-Domain Detectioncited by 29
12 most cited of 68 All 68 (JSON)
- 2026On the Properties of Feature Attribution for Supervised Contrastive Learning24 Apr 2026
- 2026Disentangled Graph Prompting for Out-Of-Distribution Detection31 Mar 2026
- 2026Out-of-Distribution Radar Detection with Complex VAEs: Theory, Whitening, and ANMF Fusion26 Jan 2026
- 2025Training-Free Policy Violation Detection via Activation-Space Whitening in LLMs3 Dec 2025
- 2025MGT-Prism: Enhancing Domain Generalization for Machine-Generated Text Detection via Spectral Alignment19 Aug 2025
- 2025Benchmarking Post-Hoc Unknown-Category Detection in Food Recognition24 Mar 2025
- 2025Unified Enhancement of the Generalization and Robustness of Language Models via Bi-Stage Optimization19 Mar 2025
- 2025Structural Entropy Guided Unsupervised Graph Out-Of-Distribution Detection5 Mar 2025
- 2025Shh, don't say that! Domain Certification in LLMs26 Feb 2025
- 2025Harnessing Feature Resonance under Arbitrary Target Alignment for Out-of-Distribution Node Detection22 Feb 2025
- 2024A new approach for fine-tuning sentence transformers for intent classification and out-of-scope detection tasks17 Oct 2024
- 2024Diversity-grounded Channel Prototypical Learning for Out-of-Distribution Intent Detection17 Sep 2024
12 newest of 68 All 68 (JSON)