# Circuit explained: How does a transformer perform compositional generalization

**Authors:** Cheng Tang, Brenden Lake, Mehrdad Jazayeri, Constantine Dovrolis, Constantine Dovrolis, Constantine Dovrolis

PMC · DOI: 10.1371/journal.pone.0340088 · 2026-02-04

## TL;DR

This paper explains how a transformer model achieves compositional generalization by identifying and analyzing a specific circuit that enables predictable output through token remapping.

## Contribution

The paper identifies and mechanistically interprets a circuit in a transformer that enables compositional generalization through token remapping.

## Key findings

- The circuit performs function composition using a disentangled representation of token position and identity.
- Causal ablations show that the circuit can be isolated and edited to steer model outputs predictably.
- The mechanism suggests how symbolic compositionality might emerge in larger transformer models.

## Abstract

Compositional generalization—the systematic combination of known components into novel structures—is fundamental to flexible human cognition, yet the mechanisms that enable it in neural networks remain poorly understood in both machine learning and cognitive science. [1] showed that a compact encoder-decoder transformer can achieve simple forms of compositional generalization in a sequence arithmetic task. In this work, we identify and mechanistically interpret the circuit responsible for this behavior in such a model. Using causal ablations, we isolate the circuit and show that this understanding enables precise activation edits to steer the model’s outputs predictably. We find that the circuit performs function composition without encoding the specific semantics of any given function—instead, it leverages a disentangled representation of token position and identity to apply a general token remapping rule across an entire family of functions. Although the circuit mechanism was identified in a limited number of small scale models with a synthetic task, it sheds light to how symbolic compositionality can emerge in transformers and offer testable hypotheses for similar mechanisms in large-scale models. Code for model and analysis is publicly available.

## Full-text entities

- **Genes:** ARG1 (arginase 1) [NCBI Gene 383], ARG2 (arginase 2) [NCBI Gene 384]
- **Chemicals:** Constantine (-)
- **Species:** Homo sapiens (human, species) [taxon 9606]

## Figures

38 figures with captions in the complete paper: https://tomesphere.com/paper/PMC12871980/full.md

---
Source: https://tomesphere.com/paper/PMC12871980