Rethinking Attention: Exploring Shallow Feed-Forward Neural Networks as an Alternative to Attention Layers in Transformers

Vukasin Bozic,Danilo Dordevic,Daniele Coppola,Joseph Thommes,Sidak Pal Singh
2024-02-05
Abstract:This work presents an analysis of the effectiveness of using standard shallow feed-forward networks to mimic the behavior of the attention mechanism in the original Transformer model, a state-of-the-art architecture for sequence-to-sequence tasks. We substitute key elements of the attention mechanism in the Transformer with simple feed-forward networks, trained using the original components via knowledge distillation. Our experiments, conducted on the IWSLT2017 dataset, reveal the capacity of these "attentionless Transformers" to rival the performance of the original architecture. Through rigorous ablation studies, and experimenting with various replacement network types and sizes, we offer insights that support the viability of our approach. This not only sheds light on the adaptability of shallow feed-forward networks in emulating attention mechanisms but also underscores their potential to streamline complex architectures for sequence-to-sequence tasks.
Computation and Language,Machine Learning
What problem does this paper attempt to address?
The problem that this paper attempts to solve is: **To explore whether shallow feed - forward neural networks can replace the attention mechanism in the Transformer model, thereby achieving performance comparable to the original Transformer architecture in sequence - to - sequence tasks**. Specifically, the goals of the paper include: 1. **Evaluate whether the shallow feed - forward network can mimic the behavior of the attention mechanism in the Transformer**: By replacing the key components of the Transformer with simple feed - forward networks and training with knowledge distillation, study whether these "attention - free Transformers" can achieve performance similar to the original Transformer. 2. **Explore the adaptability of the shallow feed - forward network in sequence - to - sequence tasks**: Through rigorous ablation studies on different types of replacement networks and sizes, provide insights into the feasibility of this method. 3. **Verify the potential of the shallow feed - forward network in simplifying complex architectures**: If the shallow feed - forward network can replace the complex attention mechanism while maintaining performance, this will help simplify the Transformer architecture, making it easier to understand and optimize. ### Main Methods - **Replacement Strategies**: The paper proposes four different replacement methods to replace the self - attention mechanism in the encoder: - **Attention Layer Replacement (ALR)**: Only replace the multi - head attention (MHA) module. - **Attention Layer with Residual Connection Replacement (ALRR)**: Replace the MHA module and its residual connection simultaneously. - **Attention Separate Heads Layer Replacement (ASLR)**: Replace each attention head with a feed - forward network separately. - **Encoder Layer Replacement (ELR)**: Completely replace the entire encoder layer. - **Experimental Setup**: The experiments were carried out on the IWSLT2017 dataset, using the BLEU score as the evaluation metric. The training of all feed - forward networks was based on knowledge distillation, that is, extracting intermediate activations from a pre - trained Transformer model as training data. ### Results - **Encoder Self - Attention Replacement**: All the proposed replacement methods can match the performance of the original Transformer to a certain extent, especially the ALR method performs the best. - **Complete Transformer Replacement**: When attempting to replace the self - attention and cross - attention in the decoder, it was found that the feed - forward network performs well in modeling self - attention, but poorly in cross - attention. This indicates that the cross - attention mechanism is more complex and it is difficult to capture its behavior with a simple feed - forward network. ### Conclusions - **Feasibility**: Experimental evidence shows that the shallow feed - forward network can successfully replace the attention mechanism in the Transformer in some cases, especially in the self - attention part. - **Limitations**: However, the feed - forward network performs poorly in handling more complex cross - attention and requires more parameters, resulting in a decrease in model flexibility. - **Future Directions**: Further optimizing the hyper - parameters of the feed - forward network or designing more complex feed - forward networks may help improve its performance in cross - attention modeling. Through this research, the authors not only provide an in - depth analysis of the existing technology, but also point out potential directions for future research, especially how to use simpler architectures to complete complex tasks.