English

Transformers on Markov Data: Constant Depth Suffices

Machine Learning 2024-07-26 v1 Computation and Language Information Theory math.IT Machine Learning

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 \kth Markov processes, where the conditional distribution of the next symbol in a sequence depends on the previous kk symbols observed. We observe a surprising phenomenon empirically which contradicts previous findings: when trained for sufficiently long, a transformer with a fixed depth and 11 head per layer is able to achieve low test loss on sequences drawn from \kth Markov sources, even as kk 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 \kth Markov sources, concurring with our empirical observations. Along the way, we prove that \textit{attention-only} transformers with O(log2(k))O(\log_2(k)) layers can represent the in-context conditional empirical distribution by composing induction heads to track the previous kk 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.

Keywords

Cite

@article{arxiv.2407.17686,
  title  = {Transformers on Markov Data: Constant Depth Suffices},
  author = {Nived Rajaraman and Marco Bondaschi and Kannan Ramchandran and Michael Gastpar and Ashok Vardhan Makkuva},
  journal= {arXiv preprint arXiv:2407.17686},
  year   = {2024}
}

Comments

29 pages, 10 figures

R2 v1 2026-06-28T17:52:57.412Z