Understanding Emergent In-Context Learning from a Kernel Regression Perspective
Chi Han Ziqi Wang Han Zhao Heng Ji Siebel School of Computing and Data Science University of Illinois Urbana-Champaign
Abstract
Large language models (LLMs) have initiated a paradigm shift in transfer learning. In contrast to the classic pretraining-then-finetuning procedure, in order to use LLMs for downstream prediction tasks, one only needs to provide a few demonstrations, known as in-context examples, without adding more or updating existing model parameters. This in-context learning (ICL) capability of LLMs is intriguing, and it is not yet fully understood how pretrained LLMs acquire such capabilities. In this paper, we investigate the reason why a transformer-based language model can accomplish in-context learning after pre-training on a general language corpus by proposing a kernel-regression perspective of understanding LLMs’ ICL bahaviors when faced with in-context examples. More concretely, we first prove that Bayesian inference on in-context prompts can be asymptotically understood as kernel regression $\hat{y}=\sum_{i}y_{i}K(x,x_{i})/\sum_{i}K(x,x_{i})$ as the number of in-context demonstrations grows. Then, we empirically investigate the in-context behaviors of language models. We find that during ICL, the attention and hidden features in LLMs match the behaviors of a kernel regression. Finally
中文速览
大型语言模型(LLM)具备一种神奇的"上下文学习"(in-context learning,ICL)能力——只需在输入里给几个示例,无需更新任何参数就能完成新任务,但背后的数学原理一直不清晰。这篇论文提出用核回归(kernel regression)来解释这一现象:理论上证明了,当示例数量增多时,LLM对ICL提示的贝叶斯推断在数学上渐近等价于一个加权核回归公式,即用输入之间的相似度作为权重,对所有示例的输出做加权平均。在实验层面,作者对真实LLM进行了验证,发现模型最后一个token的注意力分配方式与核回归的预测高度吻合,仅凭注意力权重就能以超过80%的准确率重建模型输出。这一框架不仅让ICL的运作机制变得可解释,还顺带解释了三个长期困惑研究者的经验现象:为什么选与测试样本相似的示例效果更好、为什么ICL对输出格式敏感、以及为什么使用分布内且有代表性的样本能提升准确率。
原文 arXiv:2305.12766;中英对照 + 大白话阅读 https://aha.fim.ai/paper/2305.12766v3