Fine-Tuning Deteriorates General Textual Out-of-Distribution Detection by Distorting Task-Agnostic Features

Sishuo Chen, Wenkai Yang, Xiaohan Bi, Xu Sun

TL;DR

Fine-tuning large language models (LLMs) for specific tasks surprisingly harms their ability to detect out-of-distribution (OOD) text, especially for non-semantic shifts. This paper introduces GNOME, a simple yet effective OOD detection score that combines features from both pre-trained and fine-tuned models to achieve robust performance across various OOD scenarios.

What Problem Does This Paper Address?

Deploying natural language processing (NLP) models in real-world applications requires them to reliably identify inputs that differ from their training data (out-of-distribution or OOD data). This is crucial for safety and preventing unexpected behavior. While many OOD detection methods exist, they often rely on features extracted from fine-tuned pre-trained language models (PLMs). However, the effectiveness of these methods across different types of distribution shifts (semantic vs. non-semantic) has not been thoroughly investigated. This paper highlights a critical issue: fine-tuning PLMs, while beneficial for in-distribution task performance, can actually degrade their ability to detect certain types of OOD data, creating a trade-off that existing methods struggle to overcome.

Methods

The authors propose GNOME (GeNeral textual OOD Measurement scorE), a novel OOD detection score. GNOME is designed to leverage both the strengths of pre-trained and fine-tuned models. It works by:

  1. Extracting features: Obtaining features from both the original, pre-trained PLM (task-agnostic features) and the fine-tuned PLM (task-specific features).
  2. Calculating Mahalanobis distances: Using Mahalanobis distance detectors (MDpre for pre-trained features and MDft for fine-tuned features) to quantify the "out-of-distribution-ness" of an input.
  3. Normalizing scores: Standardizing the MDpre and MDft scores to make them comparable across different feature spaces.
  4. Aggregating scores: Combining the normalized scores, typically by taking the mean, to produce the final GNOME score.

This approach aims to capture both general linguistic properties (preserved in pre-trained models) and task-specific knowledge (learned during fine-tuning).

Datasets

The paper uses a comprehensive suite of datasets for evaluation, categorized into:

  • Non-Semantic Shift (NSS) Benchmarks:
    • Sentiment Analysis: SST-2, IMDB
    • Toxicity Detection: Twitter, Jigsaw
  • Semantic Shift (SS) Benchmarks:
    • News Categorization: AGNews, News Category (NC)
    • Dialogue Intent Classification: ROSTD, CLINC
  • Cross-Task Benchmarks:
    • ID data: SST-2, 20 Newsgroups (20 NG)
    • OOD data: TREC-10, WMT-16, Multi30k, RTE, SNLI

The authors construct these benchmarks to specifically isolate NSS and SS scenarios, and also include cross-task settings where both shifts occur simultaneously.

Key Insights and Ideas

  • Fine-tuning is a double-edged sword for OOD detection: While fine-tuning improves performance on in-distribution data and helps detect semantic shifts, it significantly degrades the ability to detect non-semantic shifts.
  • Task-agnostic features are crucial for NSS detection: The paper hypothesizes and empirically shows that fine-tuning discards general linguistic knowledge (like sentence length) that is vital for identifying non-semantic shifts.
  • No single existing method excels everywhere: The evaluation reveals a clear trade-off, with methods performing well on NSS often failing on SS, and vice-versa.
  • Combining pre-trained and fine-tuned features is key: GNOME's success demonstrates that leveraging both types of features is essential for robust OOD detection across diverse shift types.

Key Results

  • GNOME outperforms baselines: On average across various benchmarks, GNOME achieves the best OOD detection performance, significantly reducing the FAR95 (False Acceptance Rate at 95% True Positive Rate) compared to previous state-of-the-art methods. For instance, it achieved an average FAR95 of 36.50% on the NSS/SS benchmarks, an 8.13% improvement over the prior SOTA.
  • Robustness in cross-task settings: GNOME also showed superior performance in cross-task scenarios, reducing the average FAR95 by 4.88%, highlighting its effectiveness when both semantic and non-semantic shifts are present.
  • Empirical evidence for feature distortion: Probing experiments using sentence length and bigram shift tasks showed that as fine-tuning progresses, OOD detection performance (AUROC) degrades in parallel with the preservation of task-agnostic features.

Limitations and Future Work

  • Slight underperformance in specific settings: GNOME, while generally strong, slightly underperforms MDpre and KNNpre in the NSS setting and MDft and KNNft in the SS setting. The authors acknowledge that achieving perfect performance across all arbitrary OOD shifts with a single method is challenging.
  • Future work: The paper suggests exploring solutions that decouple task-agnostic and task-specific features within a single model. They also mention that if prior knowledge about OOD data types is available, weighted aggregation of scores could further improve performance.

Summary updated

BibTeX
@inproceedings{chen2023fine,
  author = {Sishuo Chen and Wenkai Yang and Xiaohan Bi and Xu Sun},
  title = {{Fine-Tuning Deteriorates General Textual Out-of-Distribution Detection by Distorting Task-Agnostic Features}},
  booktitle = {EACL (Findings)},
  year = {2023},
  url = {https://openreview.net/forum?id=mYYo4-C1Vh5},
}
Figure