Skip to main content
QUICK REVIEW

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

Vukasin Bozic, Danilo Dordevic|arXiv (Cornell University)|Nov 17, 2023
Advanced Neural Network ApplicationsComputer Science4 citations
TL;DR

This paper proposes replacing the attention mechanism in Transformers with shallow feed-forward neural networks trained via knowledge distillation, demonstrating that such 'attentionless Transformers' can match the original model's performance on IWSLT2017 translation tasks. The key finding is that self-attention can be effectively emulated, but cross-attention remains a significant challenge due to its complex sequence interactions.

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.

Motivation & Objective

  • To investigate whether shallow feed-forward networks can effectively emulate the behavior of self- and cross-attention mechanisms in Transformers.
  • To assess the feasibility of replacing attention modules with simpler, parameter-efficient feed-forward networks without sacrificing performance.
  • To identify architectural and training constraints that prevent end-to-end training of attentionless Transformers.
  • To evaluate the impact of network size and replacement strategy on translation quality using BLEU scores.

Proposed method

  • Knowledge distillation is used to train shallow feed-forward networks to mimic intermediate activations from the original Transformer's attention layers.
  • Four distinct replacement strategies are evaluated: Attention Layer Replacement (ALR), Attention Layer with Residual Connection Replacement (ALRR), Attention Separate Heads Layer Replacement (ASLR), and Encoder Layer Replacement (ELR).
  • The same replacement approach is extended to decoder self-attention and cross-attention, with adapted architectures to match the different attention types.
  • Experiments are conducted across five network sizes (XS to L) on the IWSLT2017 dataset, with BLEU scores used as the primary evaluation metric.
  • The original Transformer serves as the teacher model, providing soft labels and intermediate features for distillation.
  • Ablation studies are performed across multiple language translation tasks (E2G, G2E, E2F, F2E) to assess robustness and generalization.

Experimental results

Research questions

  • RQ1Can shallow feed-forward networks effectively learn and replicate the behavior of self-attention mechanisms in Transformers?
  • RQ2Does replacing attention with feed-forward networks degrade translation performance, and if so, under what conditions?
  • RQ3Why does cross-attention prove more difficult to replace than self-attention in the decoder?
  • RQ4Can knowledge distillation enable training of attentionless Transformers that match the performance of the original model?
  • RQ5What is the impact of network size and replacement strategy on model efficiency and accuracy?

Key findings

  • The ALR method achieved the best balance of performance and parameter efficiency, with the largest model (L) reaching 0.252 BLEU on E2G, very close to the original Transformer's 0.257.
  • Self-attention replacement via ALR achieved competitive results across all datasets, with the L-sized model outperforming the baseline on G2E (0.327 vs. 0.324) and E2F (0.276 vs. 0.276).
  • Cross-attention replacement consistently led to significant performance drops, with the largest model (L) achieving only 0.134 BLEU on G2E, far below the baseline.
  • The ASLR method for encoder self-attention achieved near-baseline performance (0.252 BLEU on E2G), indicating that head-wise replacement is viable.
  • Full replacement of all attention mechanisms (including cross-attention) resulted in the worst performance, with BLEU scores dropping to 0.105 on E2G for the L-sized model.
  • The ALRR and ELR methods performed poorly, especially on larger models, indicating that residual connections and full layer replacement disrupt training dynamics.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.