揭示大模型用评分优化输出的内在机制,类比强化学习策略梯度。
In-Context Learning as Implicit Policy Gradient

- 通过自注意力实现奖励加权聚合,类比REINFORCE算法。
- 证明注意力更新可限制输出分布偏移,类似信任区域优化。
- 实验显示注意力权重与示例得分强相关,验证理论有效性。
近期研究发现,大语言模型可通过将生成样本及其评分作为上下文示例,迭代改进输出。尽管有这些实证结果,其理论基础仍不清晰。本文表明,基于评分的上下文学习(ICL)在结构上与策略梯度优化存在对应关系。我们首先通过构造性证明,在特定权重配置下,自注意力机制可实现类似于REINFORCE算法的奖励加权聚合,并讨论该构造与预训练Transformer行为的关系。这种对应关系在隐藏状态空间中具有方向性,仅在简化条件下精确成立;我们通过实证量化其强度。在简化的隐藏状态模型中,我们进一步推导出受限注意力更新所引发的分布偏移的精确上界,呈现出类似KL约束策略优化的信任区域类比。通过多个LLM的广泛实验验证了该理论,结果表明模型能有效利用评分信息将输出分布向高分示例迁移,且注意力权重与示例得分高度相关。
原文摘要 · Abstract (English)
Recent work has shown that large language models (LLMs) can iteratively improve their outputs by incorporating generated samples and their corresponding evaluation scores as in-context examples. Despite these empirical findings, the theoretical foundations underlying this phenomenon remain poorly understood. In this paper, we show that score-conditioned In-Context Learning (ICL) admits a structural correspondence to policy gradient optimization. We first provide a constructive proof that self-attention mechanisms can implement reward-weighted aggregation analogous to the REINFORCE algorithm under specific weight matrix configurations, and discuss the relationship between this construction and the behavior of pretrained transformers. The correspondence is directional in hidden-state space and holds exactly only under the stated simplifying conditions; we quantify its strength empirically. Within our simplified hidden-state model, we furthermore derive an exact upper bound on the distribution shift induced by a bounded attention update, yielding a trust-region-like analogy to KL-constrained policy optimization. We validate our theory through extensive experiments across multiple LLMs, demonstrating that LLMs effectively utilize score information to shift output distributions toward high-scoring exemplars, and that attention weights exhibit a strong correlation with example scores.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。