As one of the most exciting features of large language models (LLMs), in-context learning is a mixed blessing. While it allows users to fast-prototype a task solver with only a few training examples, the performance is generally sensitive to various configurations of the prompt such as the choice or order of the training examples. In this paper, we for the first time theoretically and empirically identify that such a paradox is mainly due to the label shift of the in-context model to the data distribution, in which LLMs shift the label marginal $p(y)$ while having a good label conditional $p(x|y)$. With this understanding, we can simply calibrate the in-context predictive distribution by adjusting the label marginal, which is estimated via Monte-Carlo sampling over the in-context model, i.e., generation of LLMs. We call our approach as generative calibration. We conduct exhaustive experiments with 12 text classification tasks and 12 LLMs scaling from 774M to 33B, generally find that the proposed method greatly and consistently outperforms the ICL as well as state-of-the-art calibration methods, by up to 27% absolute in macro-F1. Meanwhile, the proposed method is also stable under different prompt configurations.
翻译:作为大型语言模型(LLMs)最引人注目的特性之一,上下文学习(in-context learning)是一把双刃剑。虽然它允许用户仅凭少量训练示例就能快速构建任务求解原型,但其性能通常对提示词的各种配置(如训练示例的选择或排序)高度敏感。本文首次从理论与实验层面揭示,这种矛盾主要源于上下文模型的标签分布偏移——LLMs在保持良好标签条件分布$p(x|y)$的同时,改变了标签边缘分布$p(y)$。基于这一认知,我们通过调整标签边缘分布即可简单校准上下文预测分布,该边缘分布通过基于上下文模型的蒙特卡洛采样(即LLMs的生成过程)进行估计。我们将此方法称为生成式校准(generative calibration)。我们在12项文本分类任务与12个参数规模从7.74亿到330亿的LLMs上开展全面实验,结果表明:所提方法在宏F1指标上较原始ICL及当前最先进的校准方法实现最高27%的绝对性能提升,同时在不同提示配置下仍保持稳定表现。