Learning Elementary Cellular Automata with Transformers

Mikhail Burtsev

TL;DR

Can Transformers truly learn abstract logic, or do they simply memorize patterns? By evaluating standard Transformer encoders on Elementary Cellular Automata (ECAs) across completely unseen Boolean rules, this study demonstrates that Transformers can internalize dynamical rules rather than just memorizing states. However, while they excel at next-step autoregressive rollouts, their ability to "jump ahead" without intermediate scratchpad steps is strictly constrained by network depth.

What Problem Does This Paper Address?

Large Language Models (LLMs) often struggle with multi-step reasoning, rule induction, and forward planning. It remains an open question whether these reasoning bottlenecks stem from training objectives, data distributions, or fundamental architectural limits of the Transformer.

To isolate this problem from the messy nuances of natural language, the author studies Elementary Cellular Automata (ECAs) as a controlled sandbox. The goal is to determine whether Transformers can observe a sequence of states, infer an underlying local Boolean rule that was never seen during training, and accurately predict future states over varying horizons.

Methods

The paper frames ECA evolution as sequence modeling over binary strings:

  • The Environment: A 1D lattice of width $W = 20$ with neighborhood radius $r = 2$. Each cell updates according to a local rule $\rho: \{0, 1\}^5 \to \{0, 1\}$, spanning $2^{32} \approx 4.3 \times 10^9$ possible Boolean functions.
  • Model Architecture: A 4-layer, 8-head Transformer encoder ($d_{\text{model}} = 512$) with full self-attention. Tokens represent individual bits, separators ([SEP]), or masks ([M]).
  • Experimental Paradigms: The author tests four distinct objective formulations:
  • Orbit-State (O-S): Given a history of states $O^T(x)$, predict the next state $x^{(T)}$.
  • Orbit-Orbit (O-O): Given history up to step $k$, predict subsequent states up to step $T$ in parallel.
  • Orbit-State and Rule (O-SR): Given $O^T(x)$, jointly predict the next state and infer the binary string of the local rule $\rho$.
  • Rule and Orbit-State (RO-S): The exact local rule $\rho$ is explicitly prepended to the context to predict the next state.

Datasets

  • Synthetic ECA Dataset: Generated using CellPyLib.
  • Scale: $9.5 \times 10^5$ training trajectories and $10^5$ test trajectories, each evolved for $T = 20$ steps.
  • Generalization Split: Crucially, the test set consists entirely of unseen rules ($\rho_{\text{test}} \cap \rho_{\text{train}} = \emptyset$). Evaluating on unseen rules tests true algorithmic abstraction rather than memorization of dynamical trajectories.

Key Insights and Ideas

  • In-Context Rule Induction: Rooted in the coupon collector’s problem, observing an orbit requires a theoretical minimum of $T_{\min} \approx 6.47$ steps to expose all local transitions. Empirically, the model's accuracy plateaus around 8 input steps, matching theoretical expectations and confirming that the model dynamically extracts the rule from context.
  • The "Jump-Ahead" Planning Bottleneck: When tasked with predicting states multiple steps ahead without generating intermediate states (direct planning / look-ahead), accuracy collapses. Even when provided the exact rule (RO-S), skipping 2 or 3 steps causes performance to plunge to ~75%.
  • Autoregressive Generation Outperforms Direct Planning: Generating rollouts state-by-state autoregressively dramatically outperforms trying to predict future states in one shot. Intermediate states act as an essential "chain-of-thought" or scratchpad.
  • Rule Supervision Aids Abstraction: Training the model to explicitly output the rule (O-SR) helps it build richer latent representations, maintaining ~85% accuracy on 3-step look-ahead planning compared to ~75% for models trained solely on states.
  • Network Depth Equates to Sequential Computation Steps: Depth directly bounds how many rule compositions the network can execute in a single forward pass:
  • 1 step ahead requires $\ge 2$ layers
  • 2 steps ahead requires $\ge 4$ layers
  • 3 steps ahead requires $\ge 7$ layers
  • 4 steps ahead requires $\ge 10$ layers

Key Results

  • Next-State Prediction: The base O-S model achieves 96% per-bit accuracy on completely novel Boolean rules.
  • Planning Decay: In direct look-ahead planning without intermediate steps, accuracy drops from 96% (step 0) to 80% ($k=1$ step ahead) and below 75% for $k \in \{2, 3\}$.
  • O-SR vs. O-O: Joint rule-and-state prediction (O-SR) maintains ~85% accuracy on 2- and 3-step look-aheads, substantially higher than the ~75% achieved by intermediate state prediction (O-O).
  • Autoregressive Rollouts: Autoregressive rollout accuracy remains above 80% over a 10-step trajectory for RO-S, O-O, and O-SR, sharply outperforming unguided look-ahead predictions.

Limitations and Future Work

  • Fixed-Depth Compute Limitations: Standard Transformer forward passes cannot dynamically scale their computation for problems requiring deep composition without intermediate token generation.
  • Architectural Implications: The author notes that improving long-horizon reasoning will likely require moving beyond vanilla static feedforward architectures toward:
  • Training objectives with multi-token or future-horizon loss signals.
  • Recurrent Transformer variants (e.g., Universal Transformers).
  • Adaptive Computation Time (ACT) to dynamically allocate layer depth according to problem difficulty.

Summary updated

BibTeX
@inproceedings{burtsev2024learning,
  author = {Mikhail Burtsev},
  title = {{Learning Elementary Cellular Automata with Transformers}},
  booktitle = {MATH-AI @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=rROdzn4DSb},
}
Figure