去掉MLP和冗余矩阵,让Transformer瘦身90%仍保持性能
Reducing the Transformer Architecture to a Minimum
- 移除MLP并合并查询/键、值/投影矩阵,压缩模型结构
- 在MNIST和CIFAR-10上参数减少90%后分类准确率不变
- 适合追求轻量化部署的模型优化研究者
Transformer架构在自然语言处理和计算机视觉中广泛应用,其核心是注意力机制,用于从长序列中提取相关上下文信息。传统设计中,多层感知机(MLP)常被用来建模非线性关系,但注意力机制本身通过相似度计算已具备非线性能力。研究提出假设:仅靠注意力机制即可胜任典型任务。进一步地,可将查询与键矩阵合并为单一矩阵,值与投影矩阵亦可省略,且对注意力机制本质无损。此外,对称的相似度定义只需原参数量的一半。在广泛使用的图像基准数据集MNIST和CIFAR-10上验证表明,简化后的Transformer架构(不含MLP、矩阵合并、对称相似度)在参数量减少高达90%的情况下,分类性能与原始模型相当。
原文摘要 · Abstract (English)
Transformers are a widespread and successful model architecture, particularly in Natural Language Processing (NLP) and Computer Vision (CV). The essential innovation of this architecture is the Attention Mechanism, which solves the problem of extracting relevant context information from long sequences in NLP and realistic scenes in CV. A classical neural network component, a Multi-Layer Perceptron (MLP), complements the attention mechanism. Its necessity is frequently justified by its capability of modeling nonlinear relationships. However, the attention mechanism itself is nonlinear through its internal use of similarity measures. A possible hypothesis is that this nonlinearity is sufficient for modeling typical application problems. As the MLPs usually contain the most trainable parameters of the whole model, their omission would substantially reduce the parameter set size. Further components can also be reorganized to reduce the number of parameters. Under some conditions, query and key matrices can be collapsed into a single matrix of the same size. The same is true about value and projection matrices, which can also be omitted without eliminating the substance of the attention mechanism. Initially, the similarity measure was defined asymmetrically, with peculiar properties such as that a token is possibly dissimilar to itself. A possible symmetric definition requires only half of the parameters. We have laid the groundwork by testing widespread CV benchmarks: MNIST and CIFAR-10. The tests have shown that simplified transformer architectures (a) without MLP, (b) with collapsed matrices, and (c) symmetric similarity matrices exhibit similar performance as the original architecture, saving up to 90% of parameters without hurting the classification performance.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。