NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

When Can Self-Attention Be Replaced by Feed Forward Layers?

Shucong Zhang, Erfan Loweimi, Peter Bell, Steve RenalsarXiv 2020

Abstract

Recently, self-attention models such as Transformers have given competitive results compared to recurrent neural network systems in speech recognition. The key factor for the outstanding performance of self-attention models is their ability to capture temporal relationships without being limited by the distance between two related events. However, we note that the range of the learned context progressively increases from the lower to upper self-attention layers, whilst acoustic events often happen within short time spans in a left-to-right order. This leads to a question: for speech recognition, is a global view of the entire sequence still important for the upper self-attention layers in the encoder of Transformers? To investigate this, we replace these self-attention layers with feed forward layers. In our speech recognition experiments (Wall Street Journal and Switchboard), we indeed observe an interesting result: replacing the upper self-attention layers in the encoder with feed forward layers leads to no performance drop, and even minor gains. Our experiments offer insights to how self-attention layers process the speech signal, leading to the conclusion that the lower self-attention layers of the encoder encode a sufficiently wide range of inputs, hence learning further contextual information in the upper layers is unnecessary.

Introduction

Transformers have revolutionized Automatic Speech Recognition (ASR) by leveraging self-attention to capture long-range temporal dependencies. Unlike traditional Recurrent Neural Networks (RNNs), which process sequences step-by-step, self-attention allows for a global view of the entire audio sequence. However, acoustic events in speech are fundamentally sequential and local. This research investigates whether the expensive global context provided by self-attention remains necessary in the upper layers of a Transformer encoder or if it becomes redundant overhead.

Architecture and Methodology

The researchers analyzed a standard 12-layer Transformer encoder. In a typical Transformer block, Multi-Head Attention (MHA) is followed by a Feed-Forward (FF) network. The core experiment involved systematically replacing the top $k$ self-attention layers with pure Feed-Forward layers.

Comparison of Self-Attention (SA) and Feed-Forward (FF) layer architectures.

By removing the attention mechanism in these upper layers, the computational complexity for those specific blocks is reduced from $O(n^2)$ to $O(n)$, where $n$ is the sequence length. This modification effectively imposes a "hard" diagonal constraint, forcing the model to process information point-wise once sufficient temporal context has been integrated by the lower layers.

The Diagonalization of Attention

A key observation driving this work is how attention patterns evolve through the depth of the network. In the initial layers, attention is broad, allowing the model to aggregate information from a wide temporal window. As the signal progresses to the upper layers, the attention maps become increasingly "diagonal."

Visualization of a diagonalized attention map in the upper layers of the encoder.

This diagonalization suggests that once the lower layers have successfully encoded the surrounding context into a rich feature vector for a specific time step, the upper layers no longer need to "look" at neighboring frames. They primarily perform point-wise transformations to refine the features for final prediction. Unconstrained global attention in these upper layers may even introduce noise by attending to irrelevant parts of the distant past or future.

Experimental Results

The hypothesis was tested on two major benchmarks: the Wall Street Journal (WSJ) and Switchboard (SWBD) datasets.

  • Wall Street Journal: Replacing the top layer with an FF layer (11 SA + 1 FF) improved the Character Error Rate (CER) from 3.5% to 3.4% on the eval92 set.
  • Switchboard: The 10 SA + 2 FF configuration achieved a Word Error Rate (WER) of 8.9%, outperforming the all-attention baseline (9.0%). On the more difficult "Callhome" subset, the improvement was even clearer: 17.6% vs 18.1%.

The results indicate a "sweet spot" for layer replacement. While replacing the top 1-2 layers yields gains, replacing too many (e.g., leaving only 6 SA layers) leads to performance degradation, as the model fails to capture enough initial temporal context before switching to point-wise processing.

Conclusion

This study demonstrates that the global view of self-attention becomes redundant in the upper layers of speech recognition encoders. By replacing these layers with simpler feed-forward structures, models can achieve better accuracy with lower computational complexity and fewer parameters. This suggests that the primary role of self-attention in ASR is to establish a sufficiently wide contextual window in the early stages of processing, after which point-wise refinement is sufficient.

Summary updated

BibTeX
@misc{zhang2020when,
  author = {Shucong Zhang and Erfan Loweimi and Peter Bell and Steve Renals},
  title = {{When Can Self-Attention Be Replaced by Feed Forward Layers?}},
  year = {2020},
  eprint = {2005.13895},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2005.13895},
}

Loading related content...

Figure