A Formal Hierarchy of RNN Architectures

William Merrill, Gail Weiss, Yoav Goldberg, Roy Schwartz, Noah A. Smith, Eran Yahav

Abstract

We develop a formal hierarchy of the expressive capacity of RNN architectures. The hierarchy is based on two formal properties: space complexity, which measures the RNN's memory, and rational recurrence, defined as whether the recurrent update can be described by a weighted finite-state machine. We place several RNN variants within this hierarchy. For example, we prove the LSTM is not rational, which formally separates it from the related QRNN (Bradbury et al., 2016). We also show how these models' expressive capacity is expanded by stacking multiple layers or composing them with different pooling functions. Our results build on the theory of "saturated" RNNs (Merrill, 2019). While formally extending these findings to unsaturated RNNs is left to future work, we hypothesize that the practical learnable capacity of unsaturated RNNs obeys a similar hierarchy. Experimental findings from training unsaturated networks on formal languages support this conjecture.

Introduction

While recurrent neural networks (RNNs) with infinite precision are theoretically Turing-complete, this idealization does not reflect the reality of finite-precision hardware and gradient-based training. Consequently, a gap exists in our formal understanding of why certain architectures, like the LSTM, often outperform simpler models like the GRU or QRNN on specific tasks. This paper addresses this gap by establishing a rigorous framework to compare architectures based on their expressive power.

To facilitate formal analysis, we focus on saturated RNNs—versions where activation functions (e.g., sigmoid or tanh) are pushed to their limits, effectively becoming step functions. This simplification allows the application of tools from automata theory to determine the precise computational limits of various architectures.

Theoretical Framework

Our classification system relies on two primary dimensions:

  1. Space Complexity: This measures how much memory a model requires as the input string length ($n$) grows. We categorize models into $\Theta(1)$ (constant memory, similar to a finite state machine), $\Theta(\log n)$ (counting memory), and $\Theta(n)$ (unbounded memory, similar to a stack).
  2. Rational Recurrence (RR): This property asks whether an RNN's update can be described as a Weighted Finite Automaton (WFA). "Rational" models, such as QRNNs or CNNs, feature simpler, highly parallelizable updates. We investigate whether this efficiency imposes a cost on expressivity.
Venn diagram illustrating the containment relationships between different RNN classes and space complexity bounds.

The RNN Hierarchy

By analyzing popular architectures—including Elman RNNs, GRUs, LSTMs, QRNNs, and self-attention—we map them into a unified hierarchy. A key finding is the power of "counter-awareness." The fundamental difference between an LSTM and a QRNN is that the LSTM can "see" its own internal memory vector to condition its next state update. In contrast, the QRNN is "counter-blind"; it updates its state based on the input but cannot condition that update on its current internal count. This makes the LSTM non-rational and strictly more powerful than the QRNN.

The proposed hierarchy of RNN architectures based on space complexity and rational recurrence.

Our analysis reveals several critical insights:

  • The Suffix Attack: A single-layer QRNN cannot recognize languages like $a^n b^n \Sigma^*$ because it lacks the ability to "freeze" a computed value and protect it from corruption by subsequent inputs.
  • Stacking Benefits: While stacking two QRNN layers allows the model to recognize $a^n b^n$ (which a single layer cannot), even a multi-layer QRNN remains rational and cannot match the state expressiveness of a single LSTM.
  • WFA Expressivity: Although often considered simple, WFAs have $\Theta(n)$ space complexity and can encode binary strings into numeric values, a capability absent in standard saturated RNNs like the LSTM.

Empirical Validation

To test these theoretical findings, we evaluated "unsaturated" (standard) versions of these networks on formal languages designed to probe specific computational abilities, such as $a^n b^n$ (counting) and $L_5$ (tracking bounded differences). The experimental results closely matched our theoretical predictions: LSTMs generalized well on counting tasks where QRNNs failed, and 2-layer QRNNs outperformed 1-layer versions in exactly the scenarios predicted by the theory.

Conclusion

This work provides a formal map of the RNN landscape, distinguishing models by their memory capacity and structural complexity. While our proofs rely on the saturation assumption, empirical evidence suggests these hierarchies hold for standard networks. Future work will focus on extending these formal proofs to unsaturated networks and providing a more exhaustive treatment of Transformers within this hierarchy.

Summary updated

BibTeX
@inproceedings{merrill2020formal,
  author = {William Merrill and Gail Weiss and Yoav Goldberg and Roy Schwartz and Noah A. Smith and Eran Yahav},
  title = {{A Formal Hierarchy of RNN Architectures}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2020},
  doi = {10.18653/v1/2020.acl-main.43},
}
Figure