In-context learning (ICL) emerges as a promising capability of large language models (LLMs) by providing them with demonstration examples to perform diverse tasks. However, the underlying mechanism of how LLMs learn from the provided context remains under-explored. In this paper, we investigate the working mechanism of ICL through an information flow lens. Our findings reveal that label words in the demonstration examples function as anchors: (1) semantic information aggregates into label word representations during the shallow computation layers' processing; (2) the consolidated information in label words serves as a reference for LLMs' final predictions. Based on these insights, we introduce an anchor re-weighting method to improve ICL performance, a demonstration compression technique to expedite inference, and an analysis framework for diagnosing ICL errors in GPT2-XL. The promising applications of our findings again validate the uncovered ICL working mechanism and pave the way for future studies.
翻译:上下文学习(In-context Learning, ICL)作为大语言模型(LLMs)的一种重要能力,通过向模型提供示例来完成多样化任务。然而,LLMs如何从提供的上下文中学习的内在机制仍待深入探究。本文从信息流视角研究ICL的工作机制,发现示例中的标签词具有锚点功能:(1)在浅层计算层的处理过程中,语义信息汇聚到标签词表征中;(2)标签词中的整合信息为LLMs的最终预测提供参照依据。基于这些发现,我们提出了三项应用:用于提升ICL性能的锚点权重重标定方法、用于加速推理的示例压缩技术,以及用于诊断GPT2-XL中ICL错误的分析框架。这些成果不仅验证了所揭示的ICL工作机制,更为未来研究奠定了基础。