On Prefix-tuning for Lightweight Out-of-distribution Detection

Yawen Ouyang, Yongchang Cao, Yuan Gao, Zhen Wu, Jianbing Zhang, Xinyu Dai

Abstract

Detecting out-of-distribution (OOD) inputs is critical for the reliability of NLP systems. While full fine-tuning of pretrained language models (PLMs) achieves high performance, it is computationally expensive and storage-intensive. This paper proposes PTO (Prefix-Tuning based OOD detection), a parameter-efficient framework that maintains a frozen PLM and tunes only a small set of prefix vectors. PTO achieves state-of-the-art results in background shift detection and remains competitive on semantic shifts, requiring significantly fewer parameters than traditional fine-tuning methods.

Introduction

In real-world deployment, NLP models frequently encounter inputs that deviate from their training distribution. Identifying these "unknowns" is essential to prevent erroneous model behavior. Traditional OOD detection methods often rely on fine-tuning large PLMs, which scales poorly when models must be adapted for numerous specific tasks. Storing a fully fine-tuned model (e.g., 110M+ parameters for BERT) for every domain is often impractical.

This work investigates whether effective OOD detection can be achieved while keeping the underlying PLM parameters frozen. The authors introduce PTO, leveraging prefix-tuning to "steer" a frozen model toward in-distribution (ID) patterns, using the resulting likelihood improvement as a robust OOD signal.

Methodology

The PTO framework utilizes prefix-tuning, where a small set of trainable continuous vectors (prefixes) is prepended to every layer of a frozen PLM, such as GPT-2.

Overview of the PTO framework. Trainable prefixes are prepended to a frozen PLM to calculate likelihood ratios for OOD detection.

The authors propose three variants of the method:

  1. Unsupervised PTO: An ID prefix ($\theta_{in}$) is optimized to maximize the likelihood of the training data. The OOD score $S_{PTO}$ is calculated as the ratio of the likelihood with the prefix versus the likelihood from the vanilla (un-prefixed) model.
  2. PTO + Label: When training labels are available, class-specific prefixes are trained to capture the nuances of individual categories.
  3. PTO + OOD: If a small sample of representative OOD data is available, an "OOD prefix" ($\theta_{out}$) is trained. The detection score then becomes the likelihood ratio between the ID prefix and the OOD prefix.

Theoretically, these likelihood ratios are shown to be proportional to the posterior probability $p(ID|x)$, providing a Bayesian justification for the approach.

Experimental Setup

The researchers evaluated PTO across two primary OOD challenges:

  • Semantic Shift (CLINC150): This dataset contains voice assistant utterances across 150 intents. OOD samples consist of "unknown" intents not seen during training.
  • Background Shift (IMDB vs. Yelp): This task uses IMDB movie reviews as ID data and Yelp restaurant reviews as OOD data. While the sentiment labels (positive/negative) are shared, the domain or "background" shifts significantly.

Results and Discussion

PTO demonstrates remarkable efficiency and performance. While full fine-tuning requires updating over 110M parameters, PTO achieves comparable or superior results by tuning only 10M to 20M parameters.

Likelihood Change as a Signal

A key finding is that the improvement in likelihood induced by an ID-specific prefix is a much stronger OOD indicator than raw perplexity (PPL) or standard model confidence. As shown in the distribution plots, the PTO score provides much clearer separation between ID and OOD samples than standard PPL.

Distribution of OOD scores. The proposed $S_{PTO}$ (right) provides significantly better separation between ID and OOD samples compared to standard perplexity (left).

Performance Benchmarks

  • Background Shifts: On the IMDB-Yelp task, unsupervised PTO achieved an AUROC of 99.3%, surpassing the best unsupervised baseline (97.4%). With labels (PTO + Label), performance reached 99.6% AUROC, outperforming supervised baselines like the Mahalanobis distance method.
  • Semantic Shifts: On CLINC150, PTO achieved 92.8% AUROC, outperforming other unsupervised methods like PPL (90.7%) and Likelihood Ratio (LLR, 90.2%).

Conclusion and Future Work

PTO offers a lightweight and effective alternative to full fine-tuning for OOD detection. It is particularly adept at identifying background shifts, suggesting that parameter-efficient tuning may be less prone to domain-specific overfitting.

However, limitations remain. The reliance on left-to-right models like GPT-2 makes the system sensitive to initial tokens, which may be common across both ID and OOD samples. Additionally, training unique prefixes for every label in high-cardinality tasks can lead to redundancy. Future research could explore bi-directional architectures and more advanced parameter-efficient methods like LoRA or Adapters to further enhance OOD detection capabilities.

Summary updated

BibTeX
@inproceedings{ouyang2023prefix,
  author = {Yawen Ouyang and Yongchang Cao and Yuan Gao and Zhen Wu and Jianbing Zhang and Xinyu Dai},
  title = {{On Prefix-tuning for Lightweight Out-of-distribution Detection}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.85},
}
Figure