36
0

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

Abstract

Theoretical efforts to prove advantages of Transformers in comparison with classical architectures such as feedforward and recurrent neural networks have mostly focused on representational power. In this work, we take an alternative perspective and prove that even with infinite compute, feedforward and recurrent networks may suffer from larger sample complexity compared to Transformers, as the latter can adapt to a form of dynamic sparsity. Specifically, we consider a sequence-to-sequence data generating model on sequences of length NN, in which the output at each position depends only on qq relevant tokens with qNq \ll N, and the positions of these tokens are described in the input prompt. We prove that a single-layer Transformer can learn this model if and only if its number of attention heads is at least qq, in which case it achieves a sample complexity almost independent of NN, while recurrent networks require NΩ(1)N^{\Omega(1)} samples on the same problem. If we simplify this model, recurrent networks may achieve a complexity almost independent of NN, while feedforward networks still require NN samples. Consequently, our proposed sparse retrieval model illustrates a natural hierarchy in sample complexity across these architectures.

View on arXiv
@article{mousavi-hosseini2025_2503.11272,
  title={ When Do Transformers Outperform Feedforward and Recurrent Networks? A Statistical Perspective },
  author={ Alireza Mousavi-Hosseini and Clayton Sanford and Denny Wu and Murat A. Erdogdu },
  journal={arXiv preprint arXiv:2503.11272},
  year={ 2025 }
}
Comments on this paper