Transformers Provably Solve Parity Efficiently with Chain of Thought

Juno Kim, Taiji Suzuki

TL;DR

This paper provides the first theoretical proof that Chain-of-Thought (CoT) reasoning allows Transformers to efficiently solve the $k$-parity problem—a task notoriously "impossible" for standard gradient-based learning to solve in polynomial time. By breaking the problem into intermediate steps, a simple one-layer Transformer can learn to decompose complex tasks and achieve near-perfect accuracy where traditional end-to-end training fails.

What Problem Does This Paper Address?

Large Language Models (LLMs) are remarkably capable, yet they often stumble on tasks requiring multi-step logical reasoning (the "zero-shot" failure). Empirically, we know that asking a model to "show its work" via Chain-of-Thought (CoT) significantly boosts performance. However, we lack a rigorous theoretical understanding of why and how this capability emerges during training.

To bridge this gap, the authors focus on the $k$-parity problem: given a $d$-bit string, determine the parity of an unknown subset of $k$ bits. This is a classic "hard" problem in computational learning theory. For a standard neural network using gradient descent, solving this end-to-end requires an exponential number of samples or iterations because the gradient signal is essentially "drowned out" by noise. The paper asks: Can training a Transformer to generate intermediate reasoning steps (CoT) turn this "impossible" problem into an efficient one?

Methods

The authors analyze a one-layer Transformer (utilizing softmax attention and a feedforward layer) applied recursively to its own output. This setup mimics the step-by-step autoregressive generation of an LLM.

Recursive generation of intermediate states in the Transformer

Key technical approaches include:

  • Task Decomposition: They represent the $k$-parity problem as a hierarchical binary tree of 2-parity operations. Instead of solving for $k$ bits at once, the model learns to solve for 2 bits, then uses that result to solve for the next 2, and so on.
Hierarchical binary tree representing the decomposition of the k-parity problem
  • Teacher Forcing: A training regime where the model is given the ground-truth intermediate "reasoning" steps during training. The authors prove this allows the model to learn the task in a single gradient update.
  • End-to-End CoT with Self-Consistency: A more realistic setting where the model generates its own chain without intermediate ground-truth labels. To prevent "error explosion" (where one wrong step ruins the rest of the chain), they introduce a data augmentation technique. By appending random bit strings, the model can internally verify if its intermediate outputs are "meaningful" or just noise, effectively filtering out faulty reasoning.
  • Theoretical Extension: They extend existing "hardness" proofs for parity from infinite-population settings to more realistic finite-sample settings.

Datasets

The study uses synthetic datasets to maintain mathematical rigor:

  • $k$-parity data: $d$-bit inputs $x \in \{\pm 1\}^d$ sampled from a uniform distribution.
  • Augmented Data: Random $d$-bit strings used specifically for the self-consistency filter in the non-teacher-forcing experiments.
  • Experimental Scale: Numerical simulations were conducted with sequence lengths of $d=64$ and target subset sizes of $k \in \{8, 16, 32\}$.

Key Insights and Ideas

  • The Gradient Sparsity Problem: In standard end-to-end training, the variance of the gradient for parity is exponentially small. The model essentially "sees" nothing but noise until it happens to stumble upon the correct subset of bits.
  • CoT as a Gradient Amplifier: By supervising intermediate steps (2-parities), the "search space" for each step is reduced from $d^k$ to $d^2$. This creates a clear, strong gradient signal that the model can easily follow.
  • Phased Learning: Without teacher forcing, the model learns in "stages." It first masters the first level of the reasoning tree. Once those outputs are stable, the internal filter allows the gradient to flow to the next level. This mimics the sudden "aha!" moments often observed in LLM training.
  • Self-Consistency is Key: The paper provides a theoretical basis for why techniques like "Self-Consistency" (sampling multiple paths) work in practice. It acts as an internal validator that prevents the model from learning from its own hallucinations during the fine-tuning process.

Key Results

  • Hardness Result: The authors prove that any finite-precision gradient algorithm requires a massive (exponential) number of iterations to solve parity without intermediate steps.
  • Efficiency Proof: With CoT and teacher forcing, a one-layer Transformer learns any $k$-parity in $O(1)$ gradient steps.
  • Logarithmic Convergence: Even without teacher forcing, the model can still solve the problem in $O(\log k)$ steps (corresponding to the height of the reasoning tree) using the proposed filtering mechanism.
  • Empirical Validation: In experiments ($d=64, k=32$), the "Direct" model (no CoT) stayed at 50% error (random guessing). The CoT models (both with teacher forcing and self-consistency) successfully drove the loss to near zero, with the self-consistency model showing clear "step-wise" improvements in the loss curve.

Limitations and Future Work

  • Simplified Architecture: The study uses a one-layer Transformer. While recursive application simulates depth, real-world LLMs are multi-layered and far more complex.
  • Synthetic Task: While $k$-parity is a fundamental building block of logic, it doesn't capture the nuances of natural language semantics or "common sense" reasoning.
  • Fixed Link Function: The authors assume a specific quadratic-like activation function in the feedforward layer to facilitate the parity math.
  • Future Directions: The authors suggest exploring how these mechanisms apply to more complex "reasoning circuits" and investigating the "reversal curse" (the inability of models to reverse logical implications) through this theoretical lens.

Summary updated

BibTeX
@inproceedings{kim2025transformers,
  author = {Juno Kim and Taiji Suzuki},
  title = {{Transformers Provably Solve Parity Efficiently with Chain of Thought}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=n2NidsYDop},
}
Figure