This repository contains the Dedicated Heads checkpoint for the 2D stochastic V=2, K=5 cellular-automaton task introduced in Spatial Induction Heads: In-Context Learning of Multidimensional Cellular Automata.
The model performs in-context learning of cellular-automaton rules. It receives the first frames of a trajectory generated by an unknown rule and predicts the rest of the trajectory. The rule table is never given to the model, and test trajectories are generated by rules that were not seen during training.
| Property | Value |
|---|---|
| Model key | 2d-stoch-v2k5-dedicated |
| Task | 2D stochastic cellular automata |
| Number of cell states V | 2 |
| Neighborhood size K | 5 (von Neumann) |
| Grid | 6×6 (torus, periodic boundaries) |
| Trajectory length T | 20 |
| Context length M | 10 |
| Architecture | Dedicated Heads |
| Transformer layers | 2 |
| Attention heads per layer | [8, 1] |
| MLP per layer (1 = yes, 0 = no) | [0, 1] |
| Hidden dimension | 512 |
| MLP dimension | 2048 |
| Positional encoding | learned absolute |
| Checkpoint file | checkpoint.pt |
T is the total number of frames in a trajectory and M is the number of initial frames given as context. The model predicts frames M to T-1.
The Dedicated-heads architecture has two layers. The first layer is attention-only with 8 heads (one head per neighbor); the second layer has one attention head and one MLP.
The paper's construction implements a two-stage spatial induction head:
See the paper for the full construction and mechanistic analysis.
Cell states are token IDs 0, 1. The time-separator token has ID 2 and the row-separator token has ID 3.
A trajectory is serialized frame by frame. Each frame is flattened row by row with a row separator between rows, and a time separator is placed between consecutive frames. The model produces next-token logits over this sequence.
The inference utilities in the code repository convert between trajectories and token sequences, so you normally do not need to handle tokens yourself.
Each trajectory starts from an initial frame whose cells are sampled independently and uniformly over the V states. A single rule is applied at every step, with periodic boundary conditions.
Each trajectory independently samples a new stochastic rule: for every neighborhood configuration, the distribution over next-cell states is drawn from a Dirichlet(1, ..., 1) distribution. Because the rule distribution is continuous, independently generated trajectories almost surely use different rule tables, including across the training, validation and test data.
Validation and test trajectories are kept only if all 32 neighborhood configurations appear in the context frames, so every entry of the rule table can be inferred from the context. Training trajectories are not filtered.
The original training set contained 50 million trajectories. The training script in the code repository generates fresh trajectories from the same distribution on the fly, and the released rule pools ship with the code.
| Hyperparameter | Value |
|---|---|
| Optimizer | AdamW |
| Learning rate | 0.001 |
| Weight decay | 0.2 |
| Adam betas | (0.9, 0.95) |
| Schedule | cosine with linear warmup |
| Warmup ratio | 0.004 |
| Global batch size | 1024 |
| Dropout | 0.0 |
| Epochs (maximum) | 5 |
| Early stopping | after 5 evaluations without improvement |
| Checkpoint selection | best validation loss |
| Precision | bfloat16 autocast |
| Random seed | 42 |
One epoch is 50 million training trajectories. Validation runs every 5000 optimizer steps.
The model is evaluated on test trajectories generated by held-out rules. Only cell tokens in frames M to T-1 are scored.
The model is compared with the true rule and with a causal add-one k-gram baseline, which counts how often each neighborhood configuration was followed by each state earlier in the same trajectory. This baseline is the Bayes-optimal predictor under the Dirichlet(1, ..., 1) prior. KL divergences are in nats and written as KL(reference ‖ predictor).
| Metric | Value |
|---|---|
| TF KL(q_kgram ‖ q_model) | 0.0033 |
| TF KL(p_true ‖ q_model) | 0.0319 |
| TF model cell accuracy | 0.7333 |
| TF k-gram cell accuracy | 0.7351 |
| AR model cell accuracy | 0.5191 |
| AR k-gram cell accuracy | 0.5197 |
| AR KL(q_kgram ‖ q_model) | 0.0038 |
The paper-reported results for all released models are in configs/paper_results.json.
Clone and install the accompanying code. Install a PyTorch build that matches your hardware first.
git clone https://github.com/sdean-group/ICL-CA.git
cd ICL-CA
pip install -e .
Load the checkpoint and run inference:
from src import load_pretrained, generate_example, predict, plot_prediction
bundle = load_pretrained("2d-stoch-v2k5-dedicated")
# A fresh Dirichlet(1, ..., 1) rule, never seen in training.
example = generate_example(bundle.spec, seed=0)
result = predict(bundle, example)
print(result.metrics)
plot_prediction(example, result)
load_pretrained downloads checkpoint.pt from the Hugging Face Hub and caches it locally. A complete interactive example is in quickstart.ipynb.
bash scripts/eval.sh 2d-stoch-v2k5-dedicated # full evaluation
N=2000 bash scripts/eval.sh 2d-stoch-v2k5-dedicated # quicker, fewer trajectories
Results are written to results/. To retrain this model from scratch:
bash scripts/train.sh 2d-stoch-v2k5-dedicated
This checkpoint is intended for:
This checkpoint is one of 12 models in the Spatial Induction Heads collection. The collection covers 1D V=2, K=3; 1D V=3, K=3; and 2D V=2, K=5 (von Neumann) tasks, each with deterministic and stochastic rules and with Shared-head and Dedicated-heads architectures.
This model is released under the MIT License.
@misc{Kazemian2026:spatial,
title = {Spatial Induction Heads: In-Context Learning of Multidimensional Cellular Automata},
author = {Kimia Kazemian and Menghan Xu and John Thickstun and Sarah Dean},
year = {2026},
eprint = {2610.09124},
archiveprefix = {arXiv},
primaryclass = {cs.LG},
url = {https://arxiv.org/abs/2610.09124}
}