arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2503.08067cs.CL
收藏

用于长度外推的上下文感知偏置

Context-aware Biases for Length Extrapolation

Ali Veisi, Hamidreza Amirzadeh, Amir Mansourian

AI总结:

本文提出上下文感知相对位置编码方法 CABLE,通过为每个注意力头动态学习 token 特定偏置,提升 Transformer 在长序列外推和长上下文检索任务上的性能。

摘要:

Transformer 在泛化到比训练时更长的序列时常常遇到困难,这一局限性被称为长度外推。现有的大多数相对位置编码(Relative Positional Encoding,RPE)方法试图通过引入固定的线性偏置或全局学习的偏置来解决这一问题,但这些偏置缺乏适应不同输入上下文的能力。在本工作中,我们提出了一种加性 RPE,即用于长度外推的上下文感知偏置(Context-Aware Biases for Length Extrapolation,CABLE),该方法为 Transformer 中的每个注意力头学习特定于 token 的、上下文感知的偏置。通过根据输入序列动态调整位置偏置,CABLE 克服了固定 RPE 的刚性。在比原始训练序列更长的序列上进行评估时,采用 CABLE 的 GPT-2 Medium(334M 参数)取得了比其他广泛采用的位置编码方法更低的困惑度。此外,通过将 CABLE 应用于 BERT base 模型,我们提升了长上下文检索任务的性能。我们的方法显著增强了在 FineWeb-Edu-10B 和 WikiText-103 数据集上测试的现有 RPE 方法的外推性能。我们的代码可在以下地址获取:https://github.com/AlgonetLabs/Cable。

英文摘要:

Transformers often struggle to generalize to longer sequences than those seen during training, a limitation known as length extrapolation. Most existing Relative Positional Encoding (RPE) methods attempt to address this by introducing either fixed linear biases or globally learned biases, which lack the capacity to adapt to different input contexts. In this work, we propose an additive RPE, Context-Aware Biases for Length Extrapolation (CABLE), a method that learns token-specific, context-aware biases for each attention head in transformers. By dynamically adjusting positional biases based on the input sequence, CABLE overcomes the rigidity of fixed RPEs. When evaluated on sequences longer than originally trained with, GPT-2 Medium (334M parameters) with CABLE achieves lower perplexity than counterparts using other widely adopted positional encoding methods. Additionally, by applying CABLE to the BERT base model we improved performance in long-context retrieval tasks. Our method significantly enhances the extrapolation performance of existing RPE methods tested on the FineWeb-Edu-10B and WikiText-103 datasets. Our code is available at: https://github.com/AlgonetLabs/Cable.

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

↑