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.
翻译:上下文学习(ICL)通过向大型语言模型(LLMs)提供示范样例,使其展现出执行多样化任务的卓越能力。然而,LLMs如何从给定上下文中学习的底层机制尚未被充分探索。本文从信息流视角探究ICL的工作机理,揭示示范样例中的标签词发挥着锚点作用:(1)在浅层计算处理阶段,语义信息汇聚至标签词表征中;(2)标签词中的整合信息作为LLMs最终预测的参考基准。基于这些发现,我们提出了锚点权重重加权方法以提升ICL性能、示范压缩技术以加速推理,以及面向GPT2-XL的ICL错误诊断分析框架。这些研究结果的有前景应用再次验证了所揭示的ICL工作机制,并为未来研究奠定了基础。