Tight Sample Complexity of Transformers

Chenxiao Yang, Nathan Srebro, Zhiyuan LiarXiv 2026

TL;DR

This paper provides the first mathematically tight characterization of the sample complexity and Vapnik-Chervonenkis (VC) dimension of hard-attention Transformers. It reveals that the data required to train a Transformer scales linearly with its depth ($L$) and parameter count ($W$), but logarithmically with the input sequence length ($T$). Furthermore, the authors prove that standard "teacher forcing" is statistically optimal for Chain-of-Thought (CoT) learning, meaning no alternative learning rule can achieve better sample complexity in the worst case.

What Problem Does This Paper Address?

Transformers are uniquely powerful because their architecture and parameter counts remain fixed regardless of the input sequence length ($T$). This raises a fundamental question in statistical learning theory: Does the amount of data needed to train a Transformer depend on the length of the sequences it processes?

Prior work attempted to show sequence-length independence by placing strict restrictions on weight norms. However, these bounds often suffered from loose polynomial dependencies on the number of parameters or exponential dependencies on depth. This paper tackles the problem from a purely parametric perspective, calculating the exact VC dimension (and sample complexity) of Transformers as a function of depth ($L$), parameters ($W$), and sequence length ($T$), without restricting weight magnitudes. It also extends this analysis to the increasingly popular Chain-of-Thought (CoT) paradigm to see how intermediate reasoning steps impact data requirements.

Methods

The authors analyze a mathematically tractable yet representative variant of the Transformer: hard-attention Transformers with ReLU feed-forward networks (FFNs). Hard attention represents the low-temperature limit of standard softmax attention, where the model assigns attention weights strictly to the score-maximizing positions.

To derive the upper bounds, the authors extend the classic piecewise-polynomial framework used for feed-forward neural networks. Because hard attention and ReLUs act as discrete "switches," the parameter space can be partitioned into regions where all routing decisions are fixed. Within each region, the network's output behaves as a polynomial function of its weights. By applying Warren's theorem to count these regions, they bound the model's capacity.

To derive the lower bounds, the authors construct a novel Recursive Retrieval Machine gadget. This explicit construction demonstrates how a Transformer can use its attention layers to sequentially look up, shift, and retrieve bits from a "label repository" encoded within the input context.

The Recursive Retrieval Machine gadget used to prove the VC dimension lower bound.

For the CoT setting, the authors introduce two new complexity measures to handle the inherent train-test asymmetry (where models are trained step-by-step but evaluated only on the final answer):

  • Trace Shattering Dimension (TSdim): Measures the capacity to shatter entire reasoning paths (governs the upper bound).
  • Answer Shattering Dimension (ASdim): Measures the capacity to shatter only the final token given a fixed prefix (governs the lower bound).

Datasets

This is a purely theoretical paper rooted in statistical learning theory. No empirical datasets or benchmarks were used or introduced.

Key Insights and Ideas

  • The $\log T$ Interaction: Unlike standard feed-forward networks, a Transformer's capacity scales with the sequence length as $\log T$. This happens because the attention mechanism allows data-dependent routing, effectively letting the model use the sequence length as an addressable memory space.
  • Teacher Forcing is Statistically Optimal: In CoT learning, a model is trained on full intermediate steps but evaluated only on the final output. One might wonder if a smarter algorithm could exploit these intermediate traces better than standard teacher forcing (empirical risk minimization on next-token prediction). The paper proves the answer is no: teacher forcing matches the fundamental lower bound for any learning rule.
  • Traces as a Scratchpad: The CoT lower bound is proven by showing that intermediate tokens can act as a label-invariant "scratchpad." The model can write intermediate data that depends on the input but not the final label, and then use a final readout layer to decode the answer, maximizing the effective capacity of the network.

Key Results

  • Standard Classification: The VC dimension of a depth-$L$, $W$-parameter Transformer is tightly bounded by: $$\Omega\left(LW \log \frac{TW}{L}\right) \le \text{VCdim} \le O(LW \log(TW))$$
  • Chain-of-Thought Learning: For an input length $T$ and generation length $T'$, the sample complexity $m(\epsilon, \delta)$ for teacher forcing is tightly bounded by: $$O\left( \frac{LW \log((T+T')W)}{\epsilon} \right)$$ Any learning rule using CoT data requires at least $\Omega\left(LW \log \left(\frac{(T+T')W}{L}\right) / \epsilon\right)$ examples, establishing the optimality of teacher forcing.

Limitations and Future Work

  • Hard Attention vs. Softmax: The tight $\log T$ bounds rely on hard attention. Softmax attention includes transcendental exponential functions, which break the piecewise-polynomial analysis. Currently, the best upper bound for softmax Transformers remains looser at $\text{poly}(T)$.
  • No Layer Normalization: To keep the polynomial degrees manageable, the authors omitted layer normalization from their theoretical architecture.
  • Statistical vs. Computational Complexity: This work focuses entirely on sample complexity (how much data is needed). It completely bypasses the computational complexity of finding the optimal parameters, which remains an NP-hard problem in the worst case.
  • Open Questions: The authors highlight two major open problems: closing the minor gap between TSdim and ASdim for general hypothesis classes, and determining the exact sample complexity of learning end-to-end mappings without intermediate CoT traces.

Summary updated

BibTeX
@misc{yang2026tight,
  author = {Chenxiao Yang and Nathan Srebro and Zhiyuan Li},
  title = {{Tight Sample Complexity of Transformers}},
  year = {2026},
  eprint = {2606.09731},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.09731},
}
Figure