arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2611.05344cs.CLcs.LG
收藏

一种用于上下文学习的电路

A Circuit for In-Context Learning

Stanford University(斯坦福大学)

Andrew Gao, William Gao

AI总结:

本研究揭示了预训练Transformer中上下文学习的电路机制,通过键值记忆、门控关联查找等可识别组件实现少样本分类,该机制在不同规模模型中保守存在且可迁移。

摘要:

上下文学习(ICL)允许预训练语言模型通过提示中的演示来执行指定任务,无需更新任何参数。当标签任意时,模型必须获取无法记忆的映射,因此学习在单次前向传播中完成。先前工作发现了候选部分,但未阐明它们如何组合。我们针对三个3-4B参数的Transformer模型,给出了带有任意标签的少样本句子分类的组合方式:模型在标签标记位置实现键值记忆,每个标签标记的残差流编码标签身份,中间层注意力头将前一个演示的类别作为键写入该记忆;在查询阶段,上层注意力头将查询类别与存储的键匹配并复制匹配的标签;一层编码是否有标签重复的早期信号会门控该读取过程,若缺少该信号,读取头会关注提示开头且不偏向任何标签;另有一组注意力头抑制最近看到的标签。每个步骤通过激活修补、针对随机头基线的头消融实验以及利用模型自身信号的引导来因果确立。对读取过程的Softmax模型(每个头含两个常数)在一个提示分布上拟合后可预测另一个分布。该计算在三个模型间保守存在,仅命名的注意力头即可复现该行为,且从头训练的Transformer也会形成相同组件。该电路可迁移至语义概念和有意义的标签,在某一系列模型中,从0.6B到8B参数的模型中均出现相同组件及因果门,且在指令调优后仍保留。此场景下的ICL是由少数可识别组件类型构成的门控关联查找,可从演示到预测进行因果追踪。

英文摘要:

In-context learning (ICL) lets a pretrained language model perform a task specified by demonstrations in its prompt, with no parameter updates. With arbitrary labels the model must acquire a mapping it cannot have memorized, so the learning happens within a single forward pass. Prior work found candidate parts but not how they compose. We give the composition for few-shot sentence classification with arbitrary labels in three 3-4B-parameter transformers. The model implements a key-value memory over label-token positions: each label token's residual stream encodes the label's identity, and middle-layer attention heads write into it the class of the preceding demonstration as its key. At the query, upper-layer heads match the query's class against the stored keys and copy out the matching labels. An early-layer signal encoding whether any label has repeated gates this readout; in its absence the readers attend to the start of the prompt and no label is favored. A separate set of heads suppresses the most recently seen label. Each step is established causally by activation patching, head ablations against random-head baselines, and steering with the model's own signals. A softmax model of the readout with two constants per head, fit on one prompt distribution, predicts another. The computation is conserved across the three models, the named heads alone reproduce the behaviour, and a transformer trained from scratch grows the same parts. The circuit transfers to semantic concepts and to labels with meaning, and the same parts, with a causal gate, appear from 0.6B to 8B in one family and survive instruction tuning. ICL in this setting is a gated associative lookup built from a few identifiable component types, traced causally from demonstrations to prediction.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑