Detecting out-of-distribution (OOD) inputs is crucial for the safe deployment of natural language processing (NLP) models. Though existing methods, especially those based on the statistics in the feature space of fine-tuned pre-trained language models (PLMs), are claimed to be effective, their effectiveness on different types of distribution shifts remains underexplored. In this work, we take the first step to comprehensively evaluate the mainstream textual OOD detection methods for detecting semantic and non-semantic shifts. We find that: (1) no existing method behaves well in both settings; (2) fine-tuning PLMs on in-distribution data benefits detecting semantic shifts but severely deteriorates detecting non-semantic shifts, which can be attributed to the distortion of task-agnostic features. To alleviate the issue, we present a simple yet effective general OOD score named GNOME that integrates the confidence scores derived from the task-agnostic and task-specific representations. Experiments show that GNOME works well in both semantic and non-semantic shift scenarios, and further brings significant improvement on two cross-task benchmarks where both kinds of shifts simultaneously take place. Our code is available at https://github.com/lancopku/GNOME.
翻译:检测分布外输入对于自然语言处理模型的安全部署至关重要。尽管现有方法,尤其是那些基于微调预训练语言模型特征空间统计的方法,被宣称有效,但它们在不同类型分布偏移下的有效性仍未得到充分探索。本研究首次系统评估主流文本分布外检测方法在检测语义与非语义偏移时的表现。我们发现:(1) 现有方法均无法在两种场景下表现良好;(2) 在分布内数据上微调预训练语言模型有助于检测语义偏移,但会严重损害非语义偏移的检测能力,这归因于任务无关特征的扭曲。为解决该问题,我们提出一种简单有效的通用分布外评分方法GNOME,该方法整合了任务无关与任务特定表征的置信度分数。实验表明,GNOME在语义和非语义偏移场景下均表现优异,并进一步在两个存在两类偏移同时发生的跨任务基准测试中带来显著提升。我们的代码开源地址为https://github.com/lancopku/GNOME。