When Do Transformers Outperform Feedforward and Recurrent Networks? A Statistical Perspective

Alireza Mousavi-Hosseini, Clayton Sanford, Denny Wu, Murat A Erdogdu

Introduction

The dominance of Transformers in modern AI is often attributed to their expressivity—their ability to represent complex functions. However, expressivity alone does not explain why they are so much easier to train on long sequences than other architectures. This paper shifts the focus to statistical separation (sample complexity), investigating why Transformers are more data-efficient than Recurrent Neural Networks (RNNs) and Feedforward Networks (FFNs) for specific tasks.

The Challenge of Dynamic Sparsity

To compare these architectures, the authors introduce the $q$-Sparse Token Regression ($q$STR) task. In this model, the output depends on only $q$ "relevant" tokens within a sequence of length $N$. The critical feature is dynamic sparsity: the indices of these relevant tokens are not fixed but are determined by the input itself (the "prompt"). This mimics real-world scenarios like coreference resolution or long-context retrieval, where the model must identify specific information based on changing context.

A simpler variant, Simple-$q$STR, involves static sparsity, where the relevant token indices remain constant across all inputs. While static sparsity is easier to learn, dynamic sparsity represents the true challenge of modern sequence modeling.

Theoretical Framework and Hierarchy

The researchers employ a rigorous mathematical framework using Rademacher complexity and covering numbers to derive generalization bounds. Their approach involves proving upper bounds for Transformers—demonstrating they can learn efficiently—and lower bounds for RNNs and FFNs—demonstrating they cannot learn efficiently as sequence length increases.

Summary of theoretical results for sample efficiency across different statistical models and architectures.

The paper establishes a clear hierarchy of statistical efficiency:

  1. Transformers: The attention mechanism acts as a "retrieval" tool. By using the prompt to create a "hard-max" filter, a single-layer Transformer can ignore irrelevant tokens. The authors prove that Transformers can learn $q$STR with a sample complexity $\tilde{O}(1)$ relative to the sequence length $N$, provided the number of attention heads $H \ge q$.
  2. RNNs: While RNNs can handle static sparsity (Simple-$q$STR) efficiently, they struggle with dynamic sparsity. To learn $q$STR, an RNN's weight norm or hidden state width must grow with $N$, leading to a sample complexity that scales polynomially with $N$ ($\Omega(N^c)$). This is known as the "RNN Bottleneck."
  3. FFNs: Feedforward networks are the least efficient. Lacking mechanisms to exploit sequential structure or prompt-based indexing, they must learn relationships across the entire flattened input, requiring samples proportional to the total input dimension ($N \times d$).

Experimental Validation

The theoretical findings are supported by experiments training models with the AdamW optimizer on synthetic $q$STR data. The authors observed how the number of training samples $n$ required to reach a target error scales as the input length $N$ increases.

Experimental results showing sample complexity scaling for dynamic (1STR) and static (Simple-1STR) tasks across architectures.

As shown in the experimental plots, the Transformer's sample requirement remains nearly constant as $N$ grows, whereas the requirements for RNNs and FFNs increase significantly. This visual evidence confirms the "statistical advantage" of the attention mechanism in handling long-context retrieval tasks. Interestingly, RNNs match Transformers on static tasks (Simple-1STR) but fall behind as soon as the task requires dynamic context-based retrieval.

Conclusion

This work provides a rigorous statistical foundation for the Transformer's success. By proving that attention is uniquely suited for dynamic sparsity, the authors show that Transformers are not just more expressive, but fundamentally more data-efficient for the types of retrieval-heavy tasks that define modern natural language processing. While this study focuses on single-layer models and synthetic link functions, it opens the door for future research into how multi-layer interactions and optimization dynamics further enhance this statistical advantage in large-scale models.

Summary updated

BibTeX
@inproceedings{mousavihosseini2025when,
  author = {Alireza Mousavi-Hosseini and Clayton Sanford and Denny Wu and Murat A Erdogdu},
  title = {{When Do Transformers Outperform Feedforward and Recurrent Networks? A Statistical Perspective}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=MnWWHumqMc},
}
Figure