Exploring Compositional Generalization (in COGS/ReCOGS_pos) by Transformers using Restricted Access Sequence Processing (RASP)
William Bruns
TL;DR
The paper investigates whether Transformers can achieve true compositional generalization on COGS and ReCOGS tasks by using Restricted Access Sequence Processing (RASP), a flat, non-hierarchical, Transformer-compatible language. By compiling RASP programs into Transformer weights, the authors demonstrate near-perfect performance on structural generalization—including prepositional phrase recursion and sentential complements—without requiring tree-structured representations. They show that a carefully designed, word-level POS/verb-type embedding plus 19 pattern-matching rules, coupled with decoder loop unrolling, can yield exact semantic and string matches across both COGS and ReCOGS generalization sets. The work also analyzes errors in a strong baseline Transformer (Wu2023), identifying attraction errors and illustrating how masking in a flat pattern framework mitigates them, thereby offering new insights into Transformer inductive biases and the role of data/inductive design in grammatical generalization. Overall, the study argues that compositional generalization in these tasks can be achieved with flat, non-recursive strategies and highlights RASP as a valuable tool for diagnosing Transformer capabilities and guiding future research.
Abstract
Humans understand new combinations of words encountered if they are combinations of words recognized from different contexts, an ability called Compositional Generalization. The COGS benchmark (Kim and Linzen, 2020) arXiv:2010.05465 reports 0% accuracy for Transformer models on some structural generalizations. We use (Weiss et al., 2021) arXiv:2106.06981's Restricted Access Sequence Processing (RASP), a Transformer-equivalent programming language, to demonstrate that a Transformer Encoder-Decoder can perform COGS and the semantically equivalent ReCOGS_pos (Wu et al., 2024) arXiv:2303.13716 systematically and compositionally: Our RASP models attain near perfect scores on structural generalization splits on COGS (exact match) and ReCOGS_pos (semantic exact match). Our RASP models show the (Re)COGS tasks do not require a hierarchical or tree-structured solution (contrary to (Kim and Linzen, 2020) arXiv:2010.05465, (Yao and Koller, 2022) arXiv:2210.13050, (Murty et al., 2022) arXiv:2211.01288, (Liu et al., 2021) arXiv:2107.06516): we use word-level tokens with an "embedding" layer that tags with possible part of speech, applying just once per encoder pass 19 attention-head compatible flat pattern-matching rules (easily identified with specific training examples), shown using grammar coverage (Zeller et al., 2023) to cover the non-recursive aspects of the input grammar, plus masking out prepositional phrases ("pp noun") and/or sentential complements (cp) when recognizing grammar patterns and extracting nouns related to the main verb in the sentence, and output the next logical form (LF) token (repeating until the LF is complete). The models do not apply recursive, tree-structured rules like "np_det pp np -> np_pp -> np", but score near perfect semantic and string exact match on both COGS and ReCOGS pp recursion, cp recursion using the decoder loop.
