On Prefix-tuning for Lightweight Out-of-distribution Detection (2023)

Abstract: Out-of-distribution (OOD) detection, a fundamental task vexing real-world applications, has attracted growing attention in the NLP community. Recently fine-tuning based methods have made promising progress. However, it could be costly to store fine-tuned models for each scenario. In this paper, we depart from the classic fine-tuning based OOD detection toward a parameter-efficient alternative, and propose an unsupervised prefix-tuning based OOD detection framework termed PTO. Additionally, to take advantage of optional training data labels and targeted OOD data, two practical extensions of PTO are further proposed. Overall, PTO and its extensions offer several key advantages of being lightweight, easy-to-reproduce, and theoretically justified. Experimental results show that our methods perform comparably to, even better than, existing fine-tuning based OOD detection approaches under a wide range of metrics, detection settings, and OOD types.

## introduction detecting out-of-distribution (ood) inputs is crucial for real-world machine learning systems deployed in the wild @xcite . for example, for a task-oriented dialogue system designed for particular domains, it can be challenging to ensure that the system is only exposed to utterances from the same distribution as the training utterances, i.e., in-distribution (id) utterances. therefore, it would be desirable for the system to detect ood utterances and return safe responses. pretrained language models (plms) have been a de facto choice for ood detection in the nlp community, and many fine-tuning based methods have achieved promising results @xcite @xcite . despite being effective, these methods require storing finetuned models for each scenario, which could be prohibitively expensive. this begs the following question: can we achieve effective ood detection in a parameter-efficient way, i.e., keep plm parameters frozen? to achieve this goal, an unsupervised prefix-tuning based ood detection framework (pto) is proposed in this paper. the key idea of pto is intuitive: an in-distribution specific prefix, optimized with the training data via maximum likelihood, could steer plms to assign higher likelihoods to id samples than plms without the prefix, while ood samples should be assigned lower likelihood. thus we propose to use the likelihood change triggered by the prefix to detect oodsamples whose improvement is not obvious (e.g., less than a predefined threshold). note that the training process of pto does not involve the sample labels, expanding its application to situations where obtaining labeled data is cost-prohibitive. going beyond the unsupervised setting, we extend our framework to fully leverage optional supervised data. specifically, we design two extensions to take advantage of training data labels and incorporate the accessible targeted ood data encountered in the system deployment environment. these practical and comprehensive extensions could further improve the pto performance. in a nutshell, pto and its extensions offer compelling advantages of being: (1) lightweight (i.e., without tuning the plm parameters), (2) easy-toreproduce (i.e., no additional hyper-parameters other than prefix-tuning itself), and (3) theoretically justified (proofed in section 3). experimental results reveal the effectiveness of our methods in detecting both semantic shift and background shift ood sentences @xcite . especially for the background shift, pto surpasses the previous best baseline by only tuning 10m parameters. our code and data will be available at https://github.com/ 1250658183/pto . no. text label dist. ## problem setup given a collection of training sentences x train and corresponding labels y train , we assume they are sampled from in-distribution p in (x, y ). the objective of ood detection is to decide whether a test sentence is from p in (x, y ) (id) or not (ood) @xcite . we follow @xcite to classify the types of ood data as either semantic or background shift based on whether the label space remains the same. semantic shift happens when we encounter sentences with unknown labels, e.g., a sentiment classifier trained with positive and negative movie reviews receiving a neutral text (example 3 in the goal of all ood detection methods is to design a score function s(x) that maps each input x to a single scalar that is distinguishable between id and ood. mathematically, the ood detector g can be described as: ## approach in this section, we start by presenting our proposed lightweight framework pto (section 3.1), then introducing two extensions of pto to leverage optional training data (sections 3.2 to 3.4). finally, we make a summary in section 3.5. ## main results ## conclusion in this paper, we shed light on lightweight ood detection, which was largely overlooked in the literature. our work bridges the gap by proposing pto, an unsupervised prefix-tuning based framework. moreover, we extend pto to fully leverage the optional training labels and targeted ood sentences. our methods have the key advantages of being lightweight, easy-to-reproduce, and theoretically justified. we reveal the effectiveness of pto and its extensions on both semantic and background shift ood detection. we hope our work could serve as a valuable starting point for future work and inspire them to explore more possibilities of lightweight ood detection.