arXiv:2502.17206cs.LGcs.NE2025-02

用神经网络替代注意力计算中的点积,提升Transformer表达能力。

Neural Attention: A Novel Mechanism for Enhanced Expressive Power in Transformer Models

  • 用前馈网络代替点积计算注意力矩阵,增强关系建模能力。
  • 在WikiText-103上困惑度降低超2%,图像分类准确率提升超4%。
  • 保留原有结构适配性,适合需更强表达力的NLP与视觉任务。

Transformer模型通常使用点积计算注意力矩阵,难以捕捉嵌入向量间的非线性关系。本文提出神经注意力(Neural Attention),用前馈网络替代点积,以更丰富地表示标记间的关系。该方法仅修改注意力矩阵计算过程,保持矩阵维度不变,可无缝集成至现有Transformer架构。我们提供了数学证明,说明神经注意力能提升表示容量,并通过受控实验验证该结论。在WikiText-103上的自然语言处理实验显示,困惑度下降超过2%;在CIFAR-10和CIFAR-100上的图像分类任务中,准确率提升超过4个百分点。尽管神经注意力带来更高计算开销,我们提出了缓解策略,确保实际可用性的同时不牺牲其表达优势。本工作证实神经注意力是提升多种应用场景下Transformer预测性能的有效手段。所有实验代码已公开于https://github.com/awayfromzel/neural-attention-research。

原文摘要 · Abstract (English)

Transformer models typically calculate attention matrices using dot products, which have limitations when capturing nonlinear relationships between embedding vectors. We propose Neural Attention, a technique that replaces dot products with feed-forward networks, enabling a more expressive representation of relationships between tokens. This approach modifies only the attention matrix calculation while preserving the matrix dimensions, making it easily adaptable to existing transformer-based architectures. We provide a detailed mathematical justification for why Neural Attention increases representational capacity and conduct controlled experiments to validate this claim. When comparing Neural Attention and Dot-Product Attention, NLP experiments on WikiText-103 show a reduction in perplexity of over 2 percent. Similarly, experiments on CIFAR-10 and CIFAR-100 show improvements in accuracy of more than 4 percentage points for image classification tasks. While Neural Attention introduces higher computational demands, we develop techniques to mitigate these challenges, ensuring practical usability without sacrificing the increased expressivity it provides. This work establishes Neural Attention as an effective means of enhancing the predictive capabilities of transformer models across a variety of applications. The code for all experiments is available at https://github.com/awayfromzel/neural-attention-research.

注意力机制Transformer神经网络模型优化

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