[论文解读] A Theoretical Understanding of Self-Correction through In-context Alignment
本文提供了首个理论分析,表明大型语言模型(LLMs)可通过自我校正实现上下文对齐,利用如 softmax 注意力、多头注意力和 MLP 块等真实 Transformer 组件,通过自生成奖励来优化输出。研究证明,Transformer 可通过上下文梯度下降优化基于排序的对齐目标(例如 Bradley-Terry、Plackett-Luce),并通过合成数据和真实世界实验验证了该机制,包括逃逸防御和偏见缓解。
Going beyond mimicking limited human experiences, recent studies show initial evidence that, like humans, large language models (LLMs) are capable of improving their abilities purely by self-correction, i.e., correcting previous responses through self-examination, in certain circumstances. Nevertheless, little is known about how such capabilities arise. In this work, based on a simplified setup akin to an alignment task, we theoretically analyze self-correction from an in-context learning perspective, showing that when LLMs give relatively accurate self-examinations as rewards, they are capable of refining responses in an in-context way. Notably, going beyond previous theories on over-simplified linear transformers, our theoretical construction underpins the roles of several key designs of realistic transformers for self-correction: softmax attention, multi-head attention, and the MLP block. We validate these findings extensively on synthetic datasets. Inspired by these findings, we also illustrate novel applications of self-correction, such as defending against LLM jailbreaks, where a simple self-correction step does make a large difference. We believe that these findings will inspire further research on understanding, exploiting, and enhancing self-correction for building better foundation models.
研究动机与目标
- 建立对大型语言模型(LLMs)在无微调情况下自我校正机制的原理性理论理解。
- 将自我校正形式化为上下文对齐(ICA),即 LLM 利用(查询,响应,奖励)三元组来优化输出。
- 分析真实 Transformer 组件(如 softmax 注意力、多头注意力、MLP 块)在实现上下文对齐中的作用。
- 通过合成数据和真实世界实验验证理论,包括逃逸防御和偏见减少。
- 证明高质量自我批评者对有效自我校正至关重要,与实证发现一致。
提出的方法
- 使用三元组示例(查询,响应,奖励)将自我校正形式化为上下文对齐(ICA),类比强化学习人类反馈(RLHF)和偏好蒸馏(DPO)。
- 构建一个理论框架,其中多层 Transformer 通过上下文梯度下降学习优化基于排序的对齐目标(如 Bradley-Terry、Plackett-Luce)的机制。
- 设计一种改进的注意力机制,通过掩码位置编码和残差更新跟踪先前标记中的最大奖励。
- 提出一种键-查询-值矩阵构建方式,使模型能够关注迄今为止奖励最高的响应,利用大规模注意力缩放和掩码机制。
- 使用残差连接将最高奖励标记的位置编码传播至输出,从而实现对最佳响应的选择。
- 在包含噪声响应和准确批评者的合成数据集上验证该机制,并在真实 LLM(如 Vicuna-7b、Llama2-7b)上测试其在偏见和逃逸防御方面的表现。

实验结果
研究问题
- RQ1LLMs 能否通过自生成的自我检查奖励实现有效的上下文对齐?
- RQ2真实 Transformer 组件(如 softmax 注意力、多头注意力、MLP)通过何种理论机制实现自我校正?
- RQ3自我批评者的质量如何影响 LLM 中自我校正的性能?
- RQ4通过上下文对齐实现的自我校正是否能在无外部反馈的情况下减少社会偏见并防御逃逸攻击?
- RQ5与简化线性模型相比,真实 Transformer 组件在上下文对齐中的重要性有多大?
主要发现
- 理论分析证明,标准多层 Transformer 可通过使用自生成奖励的上下文梯度下降,优化基于排序的对齐目标(如 Bradley-Terry、Plackett-Luce)。
- 该机制依赖于一种改进的注意力机制,通过掩码位置编码和残差更新追踪最高奖励响应。
- 合成实验表明,当提供相对准确的自我批评者时,Transformer 可利用噪声输出优化响应。
- 真实世界实验显示,自我校正将 Llama2-7b-chat 的逃逸成功率从 95% 降低至 2%,展现出强大的防御能力。
- 观察到自我检查准确率与最终模型性能之间存在强相关性,验证了高质量自我批评者的关键作用。
- 理论洞察表明,多头注意力、softmax 注意力和 MLP 块对于有效上下文对齐至关重要,突破了简化线性模型的局限。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。