ALTA: Compiler-Based Analysis of Transformers

Peter Shaw, James Cohan, Jacob Eisenstein, Kenton Lee, Jonathan Berant, Kristina Toutanova

Introduction

Transformers have revolutionized machine learning, yet they often struggle with "System 2" reasoning—tasks requiring multi-step logic or compositional generalization, such as multi-digit addition or the SCAN benchmark. A central question in AI research is whether these failures stem from fundamental architectural limitations or from the nuances of the training process.

ALTA (A Language for Transformer Analysis) addresses this by bridging the gap between symbolic algorithms and neural weights. It is a new programming language and compiler that translates symbolic algorithms directly into Transformer weights. By providing a "ground truth" program for algorithmic tasks, ALTA allows researchers to diagnose why models often fail to learn robust solutions during standard training.

The ALTA Framework

ALTA consists of a symbolic language and a specialized compiler designed to map high-level logic to the specific operations of a Transformer.

The ALTA compilation pipeline: from symbolic program to Transformer weights.

The framework introduces three key innovations:

  1. The Language: Supports categorical, numerical, and set variables, with explicit support for loops via compilation to Universal Transformers (models with weight sharing across layers).
  2. The Compiler: Unlike previous tools like RASP or Tracr that relied on dense lookup tables, ALTA represents MLP sub-layers as a sparse set of transition rules. This prevents "combinatorial explosion" and allows complex programs to be mapped to reasonably sized models.
  3. Trace Supervision: This technique involves supervising the model on intermediate "execution traces" generated by the ALTA interpreter, rather than just the final output.

Algorithmic Benchmarks and Results

The authors evaluated ALTA on several classic benchmarks, including Parity, Addition, the SCAN benchmark for compositional generalization, and SUBLEQ (a Turing-complete language).

Parity and Trace Supervision

For the parity task—determining if a binary sequence contains an even number of ones—ALTA compiles a sequential algorithm. Using trace supervision, models can learn this correct internal logic and achieve 100% accuracy on sequences significantly longer than those seen during training.

Execution trace of a compiled Transformer solving the parity task, showing intermediate states across layers.

Compositional Generalization in SCAN

ALTA provides the first constructive demonstration of a Transformer solving the SCAN task with 100% accuracy using a shift-reduce parsing algorithm. Interestingly, while the compiled version generalizes perfectly, models trained end-to-end on the same data often fail, highlighting that the "inductive bias" of standard training is a major hurdle.

Key Insights: The Learnability Gap

ALTA reveals several critical insights into Transformer behavior:

  • Internal Loops: Transformers can represent length-invariant algorithms internally using weight-shared layers without needing external "scratchpads."
  • Sparsity and Efficiency: Treating the MLP as a sparse rule-checker allows for efficient representation; for instance, a SCAN parser requires fewer than 2,000 hidden dimensions.
  • Simplicity Bias: Standard training often settles on "simpler" (fewer layers) but less robust algorithms. In parity, models often learn a "Sum + Modulo" approach that fails on long sequences, rather than the robust sequential algorithm ALTA provides.
  • Minimality Theory: If training data doesn't exercise every part of an algorithm, the model contains "free parameters" that lead to unpredictable behavior on test data.

Conclusion and Future Work

ALTA provides a powerful tool for understanding the theoretical expressivity versus the actual learnability of Transformers. While currently focused on deterministic algorithms and encoder-only architectures, future work could extend ALTA to decoder-only models and probabilistic outputs. It also opens doors for creating "interpretability benchmarks" to see if researchers can recover known compiled algorithms from trained weights.

Reference: Shaw, P., et al. (2025). ALTA: Compiler-Based Analysis of Transformers. Published in Transactions on Machine Learning Research.

Summary updated

BibTeX
@article{shaw2025alta,
  author = {Peter Shaw and James Cohan and Jacob Eisenstein and Kenton Lee and Jonathan Berant and Kristina Toutanova},
  title = {{ALTA: Compiler-Based Analysis of Transformers}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2025},
}
Figure