<p>The quadratic computational complexity of the self-attention mechanism in Transformer models severely constrains their applicability to long sequence inputs. We propose Contextual Priority Attention (CPA), a novel attention mechanism that reduces computational complexity from <InlineEquation ID="IEq1"> <EquationSource Format="TEX">\(\mathcal {O}(n^2)\)</EquationSource> </InlineEquation> to <InlineEquation ID="IEq2"> <EquationSource Format="TEX">\(\mathcal {O}(n \log n)\)</EquationSource> </InlineEquation> theoretically, with experimentally observed linear scaling, while preserving the essential contextual modeling capabilities of traditional attention. Unlike existing efficient attention variants that approximate the full attention matrix, CPA fundamentally reimagines attention as a global-context-driven priority system. Our approach first computes a Global Context Vector (GCV) to capture the overall sequence information, then uses this context to assign priority scores to individual tokens, enabling sparse attention allocation. In encoder-decoder architectures, we apply CPA to the encoder while maintaining standard attention in the decoder, achieving substantial efficiency improvements while preserving full model expressivity for sequence-to-sequence tasks. Through theoretical analysis and extensive experimentation across language understanding, translation, and long document tasks, we demonstrate that CPA achieves comparable performance to standard self-attention while offering significant efficiency gains. On long-sequence benchmarks (8K+ tokens), CPA outperforms traditional Transformers and state-of-the-art efficient attention variants while using substantially fewer computational resources. Our findings suggest that pairwise token interactions may be unnecessary for effective contextual modeling, opening new avenues for efficient large-scale language models.</p>

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Contextual priority attention enables linear time sequence modeling in transformers

  • Karim Ben Khaled,
  • Davy Monticolo

摘要

The quadratic computational complexity of the self-attention mechanism in Transformer models severely constrains their applicability to long sequence inputs. We propose Contextual Priority Attention (CPA), a novel attention mechanism that reduces computational complexity from \(\mathcal {O}(n^2)\) to \(\mathcal {O}(n \log n)\) theoretically, with experimentally observed linear scaling, while preserving the essential contextual modeling capabilities of traditional attention. Unlike existing efficient attention variants that approximate the full attention matrix, CPA fundamentally reimagines attention as a global-context-driven priority system. Our approach first computes a Global Context Vector (GCV) to capture the overall sequence information, then uses this context to assign priority scores to individual tokens, enabling sparse attention allocation. In encoder-decoder architectures, we apply CPA to the encoder while maintaining standard attention in the decoder, achieving substantial efficiency improvements while preserving full model expressivity for sequence-to-sequence tasks. Through theoretical analysis and extensive experimentation across language understanding, translation, and long document tasks, we demonstrate that CPA achieves comparable performance to standard self-attention while offering significant efficiency gains. On long-sequence benchmarks (8K+ tokens), CPA outperforms traditional Transformers and state-of-the-art efficient attention variants while using substantially fewer computational resources. Our findings suggest that pairwise token interactions may be unnecessary for effective contextual modeling, opening new avenues for efficient large-scale language models.