The Expressive Capacity of State Space Models: A Formal Language Perspective

Yash Sarrof, Yana Veitsman, Michael Hahn · DOI

TL;DR

This paper provides a rigorous theoretical analysis of the expressive capacity of linear State Space Models (SSMs) like Mamba through the lens of formal languages. It reveals that SSMs and Transformers have overlapping but distinct computational strengths: SSMs effortlessly handle long-range state tracking (such as the Flip Flop language) and bounded hierarchical structures, but are fundamentally bottlenecked by their nonnegative gating mechanisms from performing modular counting tasks like PARITY.

What Problem Does This Paper Address?

State Space Models (SSMs) have recently emerged as powerful alternatives to Transformers, offering linear-time scaling with sequence length while maintaining competitive performance on language modeling tasks. However, our theoretical understanding of what these models can and cannot compute in principle has lagged behind their empirical success.

To guide the design of future language model architectures, this paper investigates the foundational computational limits of SSMs. The authors compare SSMs directly to Transformers and traditional Recurrent Neural Networks (RNNs) by evaluating their ability to recognize and predict different classes of formal languages (sets of strings governed by specific grammatical rules).

Three key formal languages used to evaluate model capabilities: Flip Flop, Parity, and Bounded-depth Dyck.

Methods

The authors analyze SSMs under a realistic finite precision assumption (allowing an unbounded number of integer bits but only a fixed number of fractional bits). They employ algebraic automata theory—specifically the Krohn-Rhodes theorem and cascade products—to mathematically map formal language classes to multi-layer SSM architectures.

To validate their theoretical findings, they conduct empirical sequence-prediction experiments using Mamba, a prominent modern SSM, testing its ability to generalize to unseen, longer sequence lengths.

Datasets

The paper utilizes three main sets of synthetic formal language benchmarks:

  1. FlipFlop Dataset: A benchmark testing long-range state tracking via a sequence of write, read, and ignore instructions.
  2. Bhattamishra et al. [2020] Test Suite: A collection of 27 formal languages containing 18 regular languages (including Tomita grammars and PARITY) and 9 counter languages (such as $a^nb^n$, $a^nb^nc^n$, and Dyck-1).
  3. Bounded Hierarchical Dyck ($Dyck_{K,h}$): A well-bracketed language with $K=8$ types of parentheses and a maximum nesting depth of $h=10$, used to evaluate hierarchical processing.

Key Insights and Ideas

  • The Flip-Flop Advantage: SSMs naturally excel at "star-free" regular languages (like Flip Flop state tracking) where Transformers struggle to length-generalize. Because SSMs maintain state sequentially, they avoid the commutative aggregation pitfalls of self-attention, which struggles to pinpoint the exact position of the last "write" command in long sequences.
  • The Nonnegative Gate Bottleneck: Most modern SSMs utilize exponential or sigmoid parameterizations that restrict gate values to be nonnegative ($A(x_t) \ge 0$). The authors prove that this design choice makes it impossible for SSMs to perform modular counting (e.g., determining if the number of 1s in a string is even or odd, known as the PARITY problem).
  • Stack-Free Hierarchy: SSMs can track bounded hierarchical languages ($Dyck_{K,h}$) using an optimal memory footprint ($O(h \log K)$ hidden units) without explicitly simulating a stack data structure. They achieve this by combining counting layers with state-tracking layers.
The architectural constructions designed for Flip-Flop state tracking and bounded-depth Dyck processing.
  • Unbounded vs. Modular Counting: Paradoxically, while nonnegative SSMs can perform unbounded counting (like tracking the absolute depth of brackets), they cannot read out the modulo value of that count because typical neural network nonlinearities and normalization layers cannot reliably extract periodic information from arbitrarily large integers.

Key Results

  • FlipFlop Tracking: A 1-layer Mamba model converges to zero error on both in-distribution and out-of-distribution validation sets within ~1400 steps, bypassing the length-generalization failures typical of Transformers.
  • Star-Free vs. Non-Star-Free Languages: Mamba perfectly learns and length-generalizes on all 11 star-free regular languages in the test suite. Conversely, it fails completely on non-star-free languages requiring modular counting; its accuracy drops to near 0% on out-of-distribution lengths for tasks like PARITY.
Mamba performance across 27 formal languages compared against baseline Transformer results.
  • Hierarchical Structure: Confirming the paper's theoretical proofs, a 2-layer Mamba model achieves near-perfect accuracy on $Dyck_{8,10}$ strings at extended lengths (up to 1400 tokens), demonstrating optimal scaling behavior over 1-layer variants.
Mamba accuracy on Dyck tasks across varying memory dimensions and layer counts.

Limitations and Future Work

The primary limitation is that this study focuses strictly on in-principle expressiveness (what an architecture can represent) rather than optimization dynamics (what gradient descent can easily discover).

The negative results regarding modular counting apply specifically to current architectures with nonnegative gates. The authors suggest that exploring complex-valued or negative gate parameterizations is a vital direction for tasks requiring periodic state tracking. Finally, because Transformers and SSMs possess complementary strengths, the authors highlight hybrid architectures (like Jamba) as a highly promising frontier for future large language models.

Summary updated

BibTeX
@inproceedings{sarrof2024expressive,
  author = {Yash Sarrof and Yana Veitsman and Michael Hahn},
  title = {{The Expressive Capacity of State Space Models: A Formal Language Perspective}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=eV5YIrJPdy},
}
Figure