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工作机制,并为未来研究开辟了新方向。