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工作机理,并为未来研究铺平了道路。