揭示大模型上下文学习的推理机制,解释其如何通过三步完成少样本任务。
Revisiting In-context Learning Inference Circuit in Large Language Models
- 将上下文学习拆解为编码、语义融合与特征检索复制三阶段。
- 实验验证该机制能统一解释多种现象,且禁用任一环节性能显著下降。
- 适合关注大模型内部工作原理的研究者与开发者参考。
上下文学习(ICL)是语言模型中一种新兴的少样本学习范式,其内部机制尚未完全明晰。现有研究虽尝试描述ICL的内部过程,但难以涵盖大型语言模型中的全部推理现象。为此,本文提出一个全面的推理电路,以解释ICL过程中观察到的现象。具体而言,将ICL推理分为三个主要操作:(1) 输入文本编码:模型将演示和查询文本编码为隐藏状态中的线性表示,保留解决ICL任务所需信息;(2) 语义融合:将演示的编码表示与其对应标签词元合并,生成标签与演示的联合表示;(3) 特征检索与复制:在任务子空间中搜索与查询表示相似的演示联合表示,并将其复制到查询中;随后,语言模型头部部分捕获这些复制的标签表示并解码为预测标签。通过细致测量,所提推理电路成功捕捉并统一了多个零散的ICL现象,构成对ICL推理过程的综合性、实用化解释。此外,消融分析表明,禁用任一步骤均会严重损害ICL性能,说明该电路是主导机制。同时,我们确认并列出了若干与该电路并行的绕行机制,也可解决ICL任务。
原文摘要 · Abstract (English)
In-context Learning (ICL) is an emerging few-shot learning paradigm on Language Models (LMs) with inner mechanisms un-explored. There are already existing works describing the inner processing of ICL, while they struggle to capture all the inference phenomena in large language models. Therefore, this paper proposes a comprehensive circuit to model the inference dynamics and try to explain the observed phenomena of ICL. In detail, we divide ICL inference into 3 major operations: (1) Input Text Encode: LMs encode every input text (in the demonstrations and queries) into linear representation in the hidden states with sufficient information to solve ICL tasks. (2) Semantics Merge: LMs merge the encoded representations of demonstrations with their corresponding label tokens to produce joint representations of labels and demonstrations. (3) Feature Retrieval and Copy: LMs search the joint representations of demonstrations similar to the query representation on a task subspace, and copy the searched representations into the query. Then, language model heads capture these copied label representations to a certain extent and decode them into predicted labels. Through careful measurements, the proposed inference circuit successfully captures and unifies many fragmented phenomena observed during the ICL process, making it a comprehensive and practical explanation of the ICL inference process. Moreover, ablation analysis by disabling the proposed steps seriously damages the ICL performance, suggesting the proposed inference circuit is a dominating mechanism. Additionally, we confirm and list some bypass mechanisms that solve ICL tasks in parallel with the proposed circuit.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。