Skip to main content
QUICK REVIEW

[Paper Review] What Algorithms can Transformers Learn? A Study in Length Generalization

Hattie Zhou, Arwen Bradley|arXiv (Cornell University)|Oct 24, 2023
Topic ModelingComputer Science7 citations
TL;DR

This paper proposes the RASP-Generalization Conjecture, which posits that Transformers exhibit strong length generalization on algorithmic tasks if and only if the task can be solved by a short RASP-L program— a formal language for expressing algorithms in a way compatible with Transformer inductive biases. The conjecture successfully predicts length generalization across diverse tasks, including previously hard problems like parity and addition, when input formats are restructured to enable concise RASP-L solutions, offering a unifying framework for understanding algorithmic learning in Transformers.

ABSTRACT

Large language models exhibit surprising emergent generalization properties, yet also struggle on many simple reasoning tasks such as arithmetic and parity. This raises the question of if and when Transformer models can learn the true algorithm for solving a task. We study the scope of Transformers' abilities in the specific setting of length generalization on algorithmic tasks. Here, we propose a unifying framework to understand when and how Transformers can exhibit strong length generalization on a given task. Specifically, we leverage RASP (Weiss et al., 2021) -- a programming language designed for the computational model of a Transformer -- and introduce the RASP-Generalization Conjecture: Transformers tend to length generalize on a task if the task can be solved by a short RASP program which works for all input lengths. This simple conjecture remarkably captures most known instances of length generalization on algorithmic tasks. Moreover, we leverage our insights to drastically improve generalization performance on traditionally hard tasks (such as parity and addition). On the theoretical side, we give a simple example where the "min-degree-interpolator" model of learning from Abbe et al. (2023) does not correctly predict Transformers' out-of-distribution behavior, but our conjecture does. Overall, our work provides a novel perspective on the mechanisms of compositional generalization and the algorithmic capabilities of Transformers.

Motivation & Objective

  • To understand under what conditions Transformers can generalize systematically beyond their training distribution, particularly in length generalization on algorithmic tasks.
  • To resolve the contradiction between Transformers’ surprising success on some reasoning tasks and their failure on others, especially in out-of-distribution generalization.
  • To develop a unifying framework that predicts when and why Transformers learn true algorithms rather than memorizing patterns.
  • To demonstrate that architectural and prompt engineering choices can unlock strong generalization by enabling concise RASP-L program representations.
  • To provide a theoretical and empirical foundation for algorithmic reasoning in Transformers, grounded in a formal language of algorithmic simplicity.

Proposed method

  • The authors introduce RASP-L, a restricted subset of the RASP programming language, designed to express algorithms that are simple and natural for Transformers to learn.
  • They define 'simple-to-represent' as expressibility via a short RASP-L program, forming the basis of the RASP-Generalization Conjecture.
  • The conjecture states that Transformers length generalize if and only if a task admits a short RASP-L solution, which is tested across diverse algorithmic tasks.
  • The authors restructure input and scratchpad formats to make previously intractable tasks (e.g., parity, addition) amenable to short RASP-L programs, enabling strong generalization.
  • They evaluate generalization performance on test sequences longer than any seen during training, measuring exact match accuracy at +10 length.
  • They compare their conjecture against existing theoretical models, such as the min-degree-interpolator, showing that their framework correctly predicts behavior where prior models fail.

Experimental results

Research questions

  • RQ1Under what conditions do Transformers exhibit strong length generalization on algorithmic tasks?
  • RQ2Can a formal language be used to predict whether a task will generalize beyond training distribution in Transformers?
  • RQ3Why do some algorithmic tasks generalize while others fail, despite similar model architectures?
  • RQ4Can reformatting input and scratchpad representations unlock generalization on traditionally hard tasks like parity and addition?
  • RQ5How does the RASP-Generalization Conjecture compare to existing theoretical models of inductive bias in Transformers?

Key findings

  • All tasks that admit a short RASP-L program exhibit strong length generalization, while those without such programs do not, supporting the RASP-Generalization Conjecture.
  • Parity and addition tasks, previously considered intractable for length generalization, achieve 100% exact match accuracy on inputs 10 digits longer than training when reformatted to allow short RASP-L solutions.
  • Models trained on sequences of length 60 or more show near-perfect length generalization up to length 150 on the counting task, demonstrating robustness to distribution shift.
  • The RASP-Generalization Conjecture correctly predicts generalization behavior in cases where the min-degree-interpolator model of Abbe et al. (2023) fails, indicating a more accurate inductive bias characterization.
  • The conjecture unifies diverse instances of length generalization across tasks such as copy, sort, mode, and addition, providing a single predictive framework.
  • The study reveals that Transformers can learn true algorithms when the underlying task admits a concise RASP-L representation, challenging the view that they rely solely on analogical pattern matching.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.