NeurIPS2024
Transformers on Markov data: Constant depth suffices
Nived Rajaraman, Marco Bondaschi, Ashok Vardhan Makkuva, Kannan Ramchandran, Michael Gastpar
Abstract
Attention-based transformers have been remarkably successful at modeling generative processes across various domains and modalities. In this paper, we study the behavior of transformers on data drawn from Markov processes, where the conditional distribution of the next symbol in a sequence depends on the previous symbols observed. We observe a surprising phenomenon empirically which contradicts previous findings: when trained for sufficiently long, a transformer with a fixed depth and head per layer is able to achieve low test loss on sequences drawn from Markov sources, even as grows. Furthermore, this low test loss is achieved by the transformer's ability to represent and learn the in-context conditional empirical distribution. On the theoretical side, our main result is that a transformer with a single head and three layers can represent the in-context conditional empirical distribution for Markov sources, concurring with our empirical observations. Along the way, we prove that attention-only transformers with layers can represent the in-context conditional empirical distribution by composing induction heads to track the previous symbols in the sequence. These results provide more insight into our current understanding of the mechanisms by which transformers learn to capture context, by understanding their behavior on Markov sources.