Out-of-distribution (OOD) detection plays a vital role in enhancing the reliability of machine learning (ML) models. The emergence of large language models (LLMs) has catalyzed a paradigm shift within the ML community, showcasing their exceptional capabilities across diverse natural language processing tasks. While existing research has probed OOD detection with relative small-scale Transformers like BERT, RoBERTa and GPT-2, the stark differences in scales, pre-training objectives, and inference paradigms call into question the applicability of these findings to LLMs. This paper embarks on a pioneering empirical investigation of OOD detection in the domain of LLMs, focusing on LLaMA series ranging from 7B to 65B in size. We thoroughly evaluate commonly-used OOD detectors, scrutinizing their performance in both zero-grad and fine-tuning scenarios. Notably, we alter previous discriminative in-distribution fine-tuning into generative fine-tuning, aligning the pre-training objective of LLMs with downstream tasks. Our findings unveil that a simple cosine distance OOD detector demonstrates superior efficacy, outperforming other OOD detectors. We provide an intriguing explanation for this phenomenon by highlighting the isotropic nature of the embedding spaces of LLMs, which distinctly contrasts with the anisotropic property observed in smaller BERT family models. The new insight enhances our understanding of how LLMs detect OOD data, thereby enhancing their adaptability and reliability in dynamic environments.
翻译:分布外(OOD)检测在提升机器学习(ML)模型可靠性方面发挥着关键作用。大型语言模型(LLMs)的出现推动了ML社区内的范式转变,展示了它们在多种自然语言处理任务中的卓越能力。尽管现有研究使用相对小规模的Transformer(如BERT、RoBERTa和GPT-2)探索了OOD检测,但规模、预训练目标和推理范式的显著差异使得这些发现能否适用于LLMs存疑。本文针对LLMs领域的OOD检测展开了开创性实证研究,重点关注规模从7B到65B的LLaMA系列模型。我们全面评估了常用的OOD检测器,仔细审视了它们在零梯度和微调场景下的性能。值得注意的是,我们将以往的判别式分布内微调改为生成式微调,使LLMs的预训练目标与下游任务保持一致。研究结果揭示,简单的余弦距离OOD检测器表现出卓越效能,优于其他OOD检测器。我们通过强调LLMs嵌入空间的各向同性特性(这与较小的BERT系列模型中观察到的各向异性形成鲜明对比)为这一现象提供了有趣的解释。这一新见解加深了我们对LLMs如何检测OOD数据的理解,从而增强了它们在动态环境中的适应性和可靠性。