arXiv:2606.27748cs.LGcs.AI2026-06

Flexformer让线性Transformer自学习注意力核,高效处理长序列。

Flexformer: Flexible Linear Transformer with Learnable Attention Kernel

论文配图:Flexformer: Flexible Linear Transformer with Learnable Attention Kernel
图 1 · 摘自论文原文
  • 将频谱频率设为可训练参数,数据驱动学习注意力核
  • 在语言建模和分类任务上超越基线模型
  • 可从预训练模型蒸馏,跨领域迁移能力强

Transformer依赖注意力机制捕捉长距离依赖,但存在二次复杂度,限制其在长序列上的扩展。基于核的线性注意力虽降低复杂度,但通常使用固定或弱可学习的核,表达能力受限。本文提出Flexformer,一种可灵活学习注意力核的线性Transformer。它基于随机傅里叶特征线性注意力,将频谱频率设为可训练参数,使模型能学习广泛的注意力核族。我们设计了平稳与非平稳两种变体,后者表达能力更强。大量实验表明,Flexformer在语言建模和序列分类任务中持续优于基线模型。此外,该模型可从预训练Transformer中有效蒸馏,恢复softmax注意力,并在不同领域间展现强核迁移能力,在长序列任务上实现高效率与竞争力表现。

原文摘要 · Abstract (English)

Transformer models rely on attention mechanism to capture long-range dependencies but suffer from quadratic complexity, limiting their scalability to long sequences. Kernel-based linear attention reduces this complexity but typically relies on fixed or weakly learnable kernels, restricting expressiveness and performance. In this work, we propose Flexformer, a flexible linear Transformer that learns attention kernels in a fully data-driven manner. Flexformer builds on random Fourier feature-based linear attention and treats spectral frequencies as trainable parameters, enabling the model to learn a broad family of attention kernels. We develop both stationary and nonstationary variants, with the latter offering strictly greater expressiveness. Extensive experiments on language modeling and sequence classification demonstrate that Flexformer consistently outperforms baselines. Moreover, Flexformer can be effectively distilled from pretrained Transformers to recover softmax attention and exhibits strong kernel transferability across domains, achieving both high efficiency and competitive performance on long-sequence tasks.

Transformer线性注意力可学习核长序列

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。