调高注意力温度可提升大模型在分布偏移下的少样本学习鲁棒性
Optimal Attention Temperature Improves the Robustness of In-Context Learning under Distribution Shift in High Dimensions
- 通过分析高维线性回归中的近似Softmax注意力,推导出最优温度公式
- 实验显示温度调整后,模型在噪声演示下仍能接近贝叶斯最优性能
- 该方法轻量高效,适用于GPT-2和Llama2-7B等预训练模型
预训练的Transformer可通过少量示例实现上下文学习(ICL),但在测试分布与预训练不一致时,其性能会急剧下降,这在实际部署中很常见。本文研究了注意力温度作为推理时的简单控制手段,以提升ICL在分布偏移下的鲁棒性。在高维线性回归框架下,分析了一个采用‘近似Softmax’注意力的Transformer,该注意力保持Softmax的归一化和温度依赖的选择性,同时具备可解析性。我们推导出在分布偏移下ICL泛化误差的闭式表达式,并证明其在特定最优注意力温度下最小化。该结果将最佳温度与预Softmax注意力分数的矩相关联,提供了可解释的指导,并预测了温度调节可恢复接近贝叶斯最优的性能。通过大量模拟验证了理论,进一步在带有噪声上下文演示的问答基准上,展示了对GPT-2和Llama2-7B的性能提升。总体而言,注意力温度成为提升预训练Transformer中ICL鲁棒性的原理性、轻量级调控参数。
原文摘要 · Abstract (English)
Pretrained Transformers can perform in-context learning (ICL) from a few demonstrations, but this ability can fail sharply when the test distribution differs from pretraining, a common deployment setting. We study attention temperature as a simple inference-time control for improving ICL robustness under such shifts. In a high-dimensional linear-regression framework, we analyze a Transformer with "approximate softmax" attention, which preserves softmax's normalization and temperature-dependent selectivity while remaining tractable. We derive a closed-form expression for the ICL generalization error under distribution shift, and show that it is minimized by an explicit optimal attention temperature. This characterization yields interpretable guidance by linking the best temperature to moments of the pre-softmax attention scores, and predicts when temperature adjustment can recover near Bayes-optimal performance. We validate the theory with extensive simulations, and further demonstrate gains on pretrained LLMs (GPT-2 and Llama2-7B) on question-answering benchmarks under distribution shift induced by noisy in-context demonstrations. Overall, attention temperature emerges as a principled, lightweight knob for improving the robustness of ICL in pretrained Transformers.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。