mlsanityData to 7 Oct 2026

Unveiling Transformers with LEGO: a synthetic reasoning task

arXiv 2206.04301 ↗First posted 9 Jun 2022cs.LG cs.AI cs.CLcited by 105

Not on the map. Why?

Abstract (arXiv)

We propose a synthetic reasoning task, LEGO (Learning Equality and Group Operations), that encapsulates the problem of following a chain of reasoning, and we study how the Transformer architectures learn this task. We pay special attention to data effects such as pretraining (on seemingly unrelated NLP tasks) and dataset composition (e.g., differing chain length at training and test time), as well as architectural variants such as weight-tied layers or adding convolutional components. We study how the trained models eventually succeed at the task, and in particular, we manage to understand some of the attention heads as well as how the information flows in the network. In particular, we have identified a novel association pattern that globally attends only to identical tokens. Based on these observations we propose a hypothesis that here pretraining helps for LEGO tasks due to certain structured attention patterns, and we experimentally verify this hypothesis. We also observe that in some data regime the trained transformer finds ``shortcut" solutions to follow the chain of reasoning, which impedes the model's robustness, and moreover we propose ways to prevent it. Motivated by our findings on structured attention patterns, we propose the LEGO attention module, a drop-in replacement for vanilla attention heads. This architectural change significantly reduces Flops and maintains or even improves the model's performance at large-scale pretraining.

Key facts. Cited by 105 papers in the map (data through 7 Oct 2026). Builds on 48 of its 67 references that are in the map. First posted on arXiv 9 Jun 2022.

Builds on

48 of 67 references.

References · 48

  1. 2017Attention Is All You Needcited by 59,932
  2. 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
  3. 2020Language Models are Few-Shot Learnerscited by 32,199
  4. 2020An Image is Worth 16x16 Words: Transformers for Image Recognition at Scalecited by 29,915
  5. 2021LoRA: Low-Rank Adaptation of Large Language Modelscited by 14,084
  6. 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,302
  7. 2021Swin Transformer: Hierarchical Vision Transformer using Shifted Windowscited by 12,082
  8. 2022Hierarchical Text-Conditional Image Generation with CLIP Latentscited by 6,539
  9. 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,304
  10. 2021Measuring Mathematical Problem Solving With the MATH Datasetcited by 5,203
  11. 2016SQuAD: 100,000+ Questions for Machine Comprehension of Textcited by 4,115
  12. 2022A ConvNet for the 2020scited by 3,545
36 more
  1. 2022OPT: Open Pre-trained Transformer Language Modelscited by 3,464
  2. 2022Training Compute-Optimal Large Language Modelscited by 2,927
  3. 2019ALBERT: A Lite BERT for Self-supervised Learning of Language Representationscited by 2,772
  4. 2016Xception: Deep Learning with Depthwise Separable Convolutionscited by 2,320
  5. 2021Decision Transformer: Reinforcement Learning via Sequence Modelingcited by 1,528
  6. 2022LaMDA: Language Models for Dialog Applicationscited by 1,218
  7. 2021Scaling Language Models: Methods, Analysis & Insights from Training Gophercited by 1,199
  8. 2019What Does BERT Look At? An Analysis of BERT's Attentioncited by 994
  9. 2016Deep Networks with Stochastic Depthcited by 973
  10. 2021GLaM: Efficient Scaling of Language Models with Mixture-of-Expertscited by 890
  11. 2021Show Your Work: Scratchpads for Intermediate Computation with Language Modelscited by 871
  12. 2019Right for the Wrong Reasons: Diagnosing Syntactic Heuristics in Natural Language Inferencecited by 864
  13. 2019Analyzing Multi-Head Self-Attention: Specialized Heads Do the Heavy Lifting, the Rest Can Be Prunedcited by 844
  14. 2020A Primer in BERTology: What we know about how BERT workscited by 807
  15. 2022A Generalist Agentcited by 802
  16. 2018Annotation Artifacts in Natural Language Inference Datacited by 656
  17. 2021CoAtNet: Marrying Convolution and Attention for All Data Sizescited by 566
  18. 2022Using DeepSpeed and Megatron to Train Megatron-Turing NLG 530B, A Large-Scale Generative Language Modelcited by 557
  19. 2019On the Relationship between Self-Attention and Convolutional Layerscited by 299
  20. 2019Measuring Compositional Generalization: A Comprehensive Method on Realistic Datacited by 280
  21. 2019Compositionality decomposed: how do neural networks generalise?cited by 264
  22. 2019Adaptively Sparse Transformerscited by 154
  23. 2022Formal Mathematics Statement Curriculum Learningcited by 141
  24. 2021Self-Attention Networks Can Process Bounded Hierarchical Languagescited by 105
  25. 2020ConvBERT: Improving BERT with Span-based Dynamic Convolutioncited by 88
  26. 2020Bongard-LOGO: A New Benchmark for Human-Level Concept Learning and Reasoningcited by 63
  27. 2020Robustness to Spurious Correlations via Human Annotationscited by 62
  28. 2021The Neural Data Router: Adaptive Control Flow in Transformers Improves Systematic Generalizationcited by 62
  29. 2020PRover: Proof Generation for Interpretable Reasoning over Rulescited by 53
  30. 2021LIME: Learning Inductive Bias for Primitives of Mathematical Reasoningcited by 46
  31. 2020Fixed Encoder Self-Attention Patterns in Transformer-Based Machine Translationcited by 42
  32. 2020Hard-Coded Gaussian Attention for Neural Machine Translationcited by 42
  33. 2021Latent Execution for Neural Program Synthesiscited by 35
  34. 2021Pointer Value Retrieval: A new benchmark for understanding the limits of neural network generalizationcited by 29
  35. 2022Revisiting the Compositional Generalization Abilities of Neural Sequence Modelscited by 20
  36. 2021Analyzing the Nuances of Transformers' Polynomial Simplification Abilitiescited by 9

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2022: 13; 2023: 32; 2024: 37; 2025: 15; 2026: 8.

105 papers.

Sort:

By area:

  1. 2023Sparks of Artificial General Intelligence: Early experiments with GPT-4cited by 2,579
  2. 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 700
  3. 2023Faith and Fate: Limits of Transformers on Compositionalitycited by 496
  4. 2023Hyena Hierarchy: Towards Larger Convolutional Language Modelscited by 388
  5. 2023The Impact of Positional Encoding on Length Generalization in Transformerscited by 319
  6. 2023Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selectioncited by 291
  7. 2022Transformers Learn Shortcuts to Automatacited by 260
  8. 2022Neural Networks and the Chomsky Hierarchycited by 214
  9. 2022Exploring Length Generalization in Large Language Modelscited by 204
  10. 2023Birth of a Transformer: A Memory Viewpointcited by 154
  11. 2022LIFT: Language-Interfaced Fine-Tuning for Non-Language Machine Learning Taskscited by 146
  12. 2023A Toy Model of Universality: Reverse Engineering How Networks Learn Group Operationscited by 141
38 more
  1. 2023Looped Transformers are Better at Learning Learning Algorithmscited by 135
  2. 2023Skill-it! A Data-Driven Skills Framework for Understanding and Training Language Modelscited by 120
  3. 2023Linear attention is (maybe) all you need (to understand transformer optimization)cited by 97
  4. 2023How Do Transformers Learn Topic Structure: Towards a Mechanistic Understandingcited by 85
  5. 2022Same Pre-training Loss, Better Downstream: Implicit Bias Matters for Language Modelscited by 84
  6. 2023Transformers as Decision Makers: Provable In-Context Reinforcement Learning via Supervised Pretrainingcited by 82
  7. 2024Transformers Can Achieve Length Generalization But Not Robustlycited by 82
  8. 2024Transformers, parallel computation, and logarithmic depthcited by 75
  9. 2023Exposing Attention Glitches with Flip-Flop Language Modelingcited by 74
  10. 2023Generalization on the Unseen, Logic Reasoning and Degree Curriculumcited by 73
  11. 2023Length Generalization in Arithmetic Transformerscited by 64
  12. 2024Understanding Transformer Reasoning Capabilities via Graph Algorithmscited by 64
  13. 2023Positional Description Matters for Transformers Arithmeticcited by 56
  14. 2024Active-Dormant Attention Heads: Mechanistically Demystifying Extreme-Token Phenomena in LLMscited by 54
  15. 2023Mimetic Initialization of Self-Attention Layerscited by 52
  16. 2022Learning threshold neurons via the "edge of stability"cited by 50
  17. 2023The Closeness of In-Context Learning and Weight Shifting for Softmax Regressioncited by 41
  18. 2023What can a Single Attention Layer Learn? A Study Through the Random Features Lenscited by 39
  19. 2024How Far Can Transformers Reason? The Globality Barrier and Inductive Scratchpadcited by 35
  20. 2023Transformers are uninterpretable with myopic methods: a case study with bounded Dyck grammarscited by 30
  21. 2022Towards Better Out-of-Distribution Generalization of Neural Algorithmic Reasoning Taskscited by 29
  22. 2023A Mathematical Abstraction for Balancing the Trade-off Between Creativity and Reality in Large Language Modelscited by 29
  23. 2024Out-of-distribution generalization via composition: a lens through induction heads in Transformerscited by 28
  24. 2023The Crucial Role of Normalization in Sharpness-Aware Minimizationcited by 26
  25. 2024Universal Length Generalization with Turing Programscited by 25
  26. 2025Quantitative Clustering in Mean-Field Transformer Modelscited by 23
  27. 2024Position Coupling: Improving Length Generalization of Arithmetic Transformers Using Task Structurecited by 22
  28. 2024Mixture of Parrots: Experts improve memorization more than reasoningcited by 20
  29. 2025How Do LLMs Perform Two-Hop Reasoning in Context?cited by 20
  30. 2023Mapping of attention mechanisms to a generalized Potts modelcited by 19
  31. 2023Learning to Extrapolate: A Transductive Approachcited by 19
  32. 2025How Do Transformers Learn Variable Binding in Symbolic Programs?cited by 19
  33. 2024ALPINE: Unveiling the Planning Capability of Autoregressive Learning in Language Modelscited by 18
  34. 2023Can Transformers Learn to Solve Problems Recursively?cited by 17
  35. 2024Spatio-Spectral Graph Neural Networkscited by 17
  36. 2024A Review of the Applications of Deep Learning-Based Emergent Communicationcited by 17
  37. 2022Understanding the Covariance Structure of Convolutional Filterscited by 16
  38. 2024On the Surprising Effectiveness of Attention Transfer for Vision Transformerscited by 16

50 most cited of 105 All 105 (JSON)