# Evaluating Compositional Generalization in Transformers: The Role of Composition Equivalence and Module Coverage

Benchmark splits, not architecture, drive transformers' compositional generalization scores

Purva Pruthi, Andrew Yuan, Alexander D'Amour, David Jensen · arXiv · 2026-11-10

- **Problem** Reported compositional generalization scores for transformers conflict across studies, because benchmarks use ad hoc train-test splits.
- **Method** The authors vary composition equivalence and module coverage in each train-test split, unlike ad hoc splits, and train direct and step-by-step transformers on them.
- **Results** Direct-model accuracy on the diverse benchmark at k=6 rises from 0% to roughly 80% as shared equivalences grow.

![Figure 1: (a) A sequential composition task combines “atomic” functions (e.g., sort, mode, filter). Task-basedcompositional generalization is the ability to ge…](https://refivu.com/papers/51035e38-2ad0-44b9-9a53-5f7b0e4038b4/figures/figure-7a5aebc47d185f663da07d3d4d48a951.png?thumb=512)

**Figure 1** : (a) A sequential composition task combines “atomic” functions (e.g., sort, mode, filter). Task-basedcompositional generalization is the ability to generalize to unseen sequences after training on a subset. (b)Composition equivalence:Different sequences are composition equivalent if they reduce to the same end-to-end function. For example, one equivalence class consisting of the first four sequences reduces to returning the most frequently occurring vowel in a set of strings; direct models succeed on the test sequence (mode◦filter◦sort ) from this class but fail on the remaining two test sequences from a different composition equivalence class. (c)Module coverage:Examples of coverage failures includeposition-wise(e.g., function 2 never appearing in the first position, shown with dashed lines) andpair-wise(e.g., missing pair (2,1) in the training set, shown with solid lines).

[Original paper](https://arxiv.org/abs/2611.13498v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Purva Pruthi, Andrew Yuan, Alexander D'Amour, David Jensen · Evaluating Compositional Generalization in Transformers: The Role of Composition Equivalence and Module Coverage · Original paper figure · Extracted the figure area from page 2 of the original PDF.

## Why direct-model results conflict

Compositional generalization asks a model to handle combinations of modules it never saw during training. Studies of this ability report conflicting findings, and the authors trace much of that conflict to how the splits are built. A high score may therefore reflect test compositions that the model already saw in its training data.

The authors instead offer a data-centric explanation, arguing that the variability can come from benchmark design and how train and test sets are created. They argue this holds irrespective of the model architecture.

The closest framework to this work is Ramesh et al. \[2024\], which focuses primarily on a single module type. The authors include modules with varied functional properties, which lets them discover composition equivalence. Ramesh et al. \[2024\] combine within-k and cross-k evaluations using identity modules as padding.

## Two properties of the train-test split

The split itself, not only the architecture, controls much of the measured result in this paper. The authors name two properties: composition equivalence and module coverage. Because the authors control each property explicitly, they can dial the degree of shift up or down.

A test sequence that shares its end-to-end function with a training sequence can look solved without real composition. Direct models trained only on final outputs appear to generalize when their splits share such equivalences. Module coverage matters for a related reason, since spurious correlations between positions and modules break when the test distribution shifts.

The authors quantify this shift with KL divergence, which is asymmetric and measures the test distribution relative to training. They define a position-wise divergence Dpos and a pair-wise divergence Dpair over the module distributions.

In the controlled runs, direct models appear to generalize when their splits share equivalences. Their accuracy falls to near zero once the overlap between training and test equivalences is removed. The authors also find that performance degrades monotonically as module coverage shifts increase, for both direct and step-by-step models. So the split properties, not only the model, shape the results a benchmark reports.

## Building splits with controlled shift

The uniform data set starts from six random bijections, each a one-to-one lookup table over input tokens. Because the mappings are unique and non-identity, any k-module composition gives a unique labeling function with high probability, so no two compositions are equivalent by default. Rare cases exist, such as two bijections that are inverses of each other, which produce an identity labeling function.

The authors compared every pair of compositions on 1000 random strings and found no duplicate labeling functions. Adding an identity module introduces exact identity-based equivalence, so the uniform set can contrast no equivalence with exact equivalence.

The diverse data set uses six string functions inspired by RASP primitives: sort, concatenate, filter, shift, union and mode. Shift moves each character one position forward, and filter extracts vowels in order.

The diverse set has no predefined equivalence classes, so the authors learn them from the data. They score each pair of compositions by the fraction of matching outputs over N = 1000 inputs. They link two compositions in an undirected graph when their score is above a threshold of 0.01. The threshold is deliberately low, so weak equivalences are captured, and connected components become the equivalence classes.

Disjoint splits assign each equivalence class wholly to train or to test, so no class appears in both sets. Module coverage is set by a bias strength parameter alpha between 0 and 1, which skews sampling in complementary directions for train and test. At alpha equal to 0 both distributions stay uniform, and as alpha approaches 1 the position-wise KL divergence Dpos rises monotonically.

Dpos averages, over positions, the KL divergence of the test distribution from the training distribution.

## Training and scoring the models on controlled splits

The authors train four transformer variants, pairing direct and step-by-step models with absolute or relative positional embeddings. The backbone is a small nanoGPT model with 3 layers and 6 heads, which keeps many train-test splits affordable to evaluate. Larger models with 12 layers and 12 heads show similar generalization trends, so the small setup doesn't drive the findings.

Each model trains on 100k samples for 100 to 200 epochs, until training loss saturates. At that point, training accuracy reaches 100%, and validation accuracy on unseen strings within training compositions sits between 90% and 100%.

Within-k draws random disjoint 80/20 splits of each set of compositions for k from 2 to 6, where k counts the non-identity modules. Cross-k trains on compositions of one length and tests on a different length, so identity modules pad the sequences to match. To compare the two settings fairly, the authors run within-k in two variants. The without-identity variant uses no identity modules, so a within-2 model trained on shift◦sort is tested on sort◦shift.

The with-identity variant pads every composition to a fixed length of 7, which mirrors the cross-k setup.

Scoring uses exact match, so a prediction earns 1.0 when it is perfect and 0.0 otherwise. The reported metric is the mean accuracy on unseen sequences, which the authors average over five random seeds. Each test set draws 10k samples uniformly for every composition, using inputs of six tokens from a to z. Because every split uses this same scoring rule, the results in Section 4 rest on one metric.

## Where direct models look like they generalize within k

Direct models fail completely on the uniform benchmark when identity modules are removed from the within-k splits. Their accuracy stays at exactly zero for every k from 2 to 6, because the setup leaves no composition equivalences to exploit. Step-by-step models keep near-perfect scores across all conditions in the same figure.

The picture reverses once identity padding enters the compositions. Random 80/20 splits on the diverse benchmark with identity modules contain exact identity-based equivalences, so direct models score near perfectly. The uniform benchmark with identity modules also reaches near-perfect performance, because identity modules introduce exact equivalence classes.

Across these settings, direct models reach 70–100% accuracy even at k = 2.

Without identity modules, the diverse benchmark yields exact and approximate equivalences, such as sort◦mode≡mode◦sort. Direct models exploit these equivalences and reach significant performance, especially for k = 4 to 6. Identity tokens or diverse function types appear necessary for direct models to generalize in this setup.

Cross-k behaves differently, because function-property equivalences persist across nearby k values on the diverse benchmark. That persistence explains the non-zero performance near the training k. Uniform cross-k fails because identity-based equivalences change once the number of non-identity modules changes. Direct models therefore fail on compositions that produce novel end-to-end functions.

## How strongly shared equivalences drive accuracy

This section asks how direct-model accuracy changes as more test sequences share an equivalence class with training on the diverse benchmark at k=6. Figure 4(a) sweeps that share across 0%, 4%, 10%, 16%, 29%, 54%, and 100%. Direct-model accuracy climbs steeply, from 0% with no sharing to roughly 80% with full sharing. The authors see the same trend for fine-tuned Gemma-3-1B, so the effect isn't limited to small GPT-2-style transformers.

![Figure 4: Isolating the effect of composition equivalence in the diverse benchmark ( k= 6 ):(a) Generalization performance increases with the degree of shared…](https://refivu.com/papers/51035e38-2ad0-44b9-9a53-5f7b0e4038b4/figures/figure-709234659f40dd4ce9278a05bf41438e.png?thumb=512)

**Figure 4** :Isolating the effect of composition equivalence in the diverse benchmark ( k= 6 ):(a) Generalization performance increases with the degree of shared composition equivalence classes between train and test. (b) The direct model generalizes primarily to test sequences that share equivalence classes and fails on classes exhibiting novel end-to-end behavior.

[Original paper](https://arxiv.org/abs/2611.13498v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)

Accuracy never reaches 100% even with full sharing, because some equivalences hold only for a subset of inputs. Some classes also have only 4 to 6 members, which leaves training subsets too small for perfect generalization. Figure 4(b) shows that the nGPT (12h12l) model scores higher on shared classes than on non-shared ones. Some shared classes still score low, especially when the class is small, so shared classes are necessary but not sufficient.

The authors report similar results on the uniform benchmark, shown in Figure 10 of the Appendix.

The threshold study changes how equivalence classes are learned, and the 0% shared split depends on that threshold. At threshold 0.01, the 0% shared split scores 0.04, while at threshold 0.95 it scores 0.84. Higher thresholds miss weak equivalences, so the 0% shared split still contains sharing that inflates accuracy. The 100% shared accuracy ranges from 0.70 at threshold 0.01 to 0.91 at threshold 0.95.

The authors connect this pattern to Ramesh et al. \[2024\], whose limited direct-model results could come from pooled train and test accuracy. They also note that identity padding in that setup inadvertently introduces equivalences. At the low threshold of 0.01, the 0% shared condition holds disjoint classes with no shared equivalence, weak or strong.

## How module coverage shift erodes accuracy

Module coverage shift gets a single number in the paper: the position-wise KL divergence, written Dpos. Dpos averages, over positions, the KL divergence from the training position distribution to the test one. KL divergence is asymmetric, so Dpos measures how far the test distribution moves relative to training. The bias strength alpha, between 0 and 1, skews sampling in complementary directions for train and test.

As alpha approaches 1, Dpos rises monotonically while the train and test sets stay disjoint.

![Figure 5: Effect of position-wise distribution shift:As the position-wise KL divergence in- creases, the compositional generalization perfor- mance of both dir…](https://refivu.com/papers/51035e38-2ad0-44b9-9a53-5f7b0e4038b4/figures/figure-4383deb49aac0c5510bb01211bfbaacd.png?thumb=512)

**Figure 5** :Effect of position-wise distribution shift:As the position-wise KL divergence in- creases, the compositional generalization perfor- mance of both direct and step-by-step models de- creases.

[Original paper](https://arxiv.org/abs/2611.13498v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)

Accuracy of both direct and step-by-step models falls monotonically as Dpos increases, on both benchmarks. The authors read this pattern as models relying on uniform module sampling to generalize. On the diverse benchmark, equivalences make this drop steeper for every model, because shortcuts compound coverage failures. Among step-by-step models, absolute position encodings react more to position-wise shifts than relative encodings.

That gap is clearest on the uniform benchmark, as Figure 5(b) shows.

Step-by-step models stay robust across all splits in within-k evaluation, as Figure 2 shows. In cross-k evaluation, they perform well only near the training k, because their position-wise and pair-wise distributions shift as k moves away. Divergence values for these shifts appear in Figure 18 of the appendix.

For pair-wise shifts, models are more sensitive on the diverse benchmark than on the uniform one. The authors attribute that sensitivity to equivalence-driven shortcuts. On the uniform benchmark, performance stays robust except under extreme support violations. Direct models with absolute position embeddings also fail to learn correct equivalences when coverage breaks.

One example is test compositions that always start with id.

## Equivalence leakage in a pre-trained LLM

The authors test Llama3-8B on the code-output prediction task in the LiveCodeBench benchmark. They group programs into equivalence classes that share function names, then hold out 0, 0.5 or 1.0 of those classes from fine-tuning. Each split is fine-tuned with LoRA, and the total number of fine-tuning samples stays fixed across leakage levels.

The base model without LoRA serves as a baseline, and it checks that pre-training didn't include code-output prediction.

Overall accuracy rises substantially when classes leak into training at h=0.5 and h=1.0. Held-out functions with h=0.0 gain only minimally, so the leaked classes drive the improvement. The same pattern holds when the authors replace function names with random strings.

![Figure 6: (a)Code output prediction performance of Llama3-8b on LiveCodeBench benchmark: We show the accuracy of the base model (No LoRA) and three LoRA fine-t…](https://refivu.com/papers/51035e38-2ad0-44b9-9a53-5f7b0e4038b4/figures/figure-8172007ac241d3f31a87d9a22a359420.png?thumb=512)

**Figure 6** : (a)Code output prediction performance of Llama3-8b on LiveCodeBench benchmark: We show the accuracy of the base model (No LoRA) and three LoRA fine-tuned models on splits with varying ratios of shared equivalence classes (defined by the same function names) (held out h=0, 0.5, 1.0). As splits share composition equivalences, accuracy improves substantially. (b)Performance grouped by equivalence classes:We observe that performance onmostfunctions only improves when equivalences are leaked into the fine-tuning set.

[Original paper](https://arxiv.org/abs/2611.13498v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)

Per-function accuracy in Figure 6(b) improves for most functions only when equivalences leak into fine-tuning. For some functions, such as distanceTraveled, leaking equivalences also improves the remaining held-out equivalences. A small number of functions, such as minLength, improve even without leakage. The authors suspect unaccounted equivalences, such as structurally similar functions on different data types with different names.

Individual implementations also differ in their libraries, so the authors can't control compositional structure in this setting.

For benchmark design, they argue that equivalences can significantly overestimate direct model generalization.

## What the findings do not establish

The evidence comes mainly from sequential compositional tasks, so the conclusions can't yet be carried over to other structures. Hierarchical and graph-based compositions were not tested, leaving open whether composition equivalence and module coverage behave the same way there. The controlled results rest on the synthetic setting, which is why they can isolate individual factors.

On LiveCodeBench, implementations sometimes differed a lot in structure because they used different libraries. Moving to real code means the synthetic controls disappear. Module coverage, sequence length, order and compositional structure can no longer be set by the authors. That loss of control makes it harder to attribute each effect to one factor.

The authors don't claim composition equivalence is the only mechanism behind the performance gains on real code. They say instead that the observed behaviors align strongly with their hypotheses about its effect. The real-world result is therefore alignment with those hypotheses, not isolation of one cause.

Isolating each factor would need either controlled synthetic settings or careful curation of real-world datasets with explicitly controlled shifts. The authors call this curation an exciting future direction, and they don't test it in this work.

## Paper info

- **Authors**: Purva Pruthi, Andrew Yuan, Alexander D'Amour, David Jensen
- **Venue**: arXiv · Preprint
- **First published**: 2026-11-10
- **Added**: 2026-11-11
- **Updated**: 2026-11-10
- **Version**: v1
- **arXiv**: 2611.13498
- **Category**: cs.LG · cs.CL
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2611.13498v1) · [PDF ↗](https://arxiv.org/pdf/2611.13498v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

Compositional generalization is an important form of out-of-distribution generalization, defined as the ability to train on some combinations of modules (e.g., functions such as sort, filter) and then generalize to unseen combinations. Despite substantial empirical work evaluating compositional generalization in transformers, findings have been inconsistent because evaluations were often conducted on a limited set of train-test splits, defined in an ad hoc manner. Through a systematic evaluation, we identify two key aspects of the train-test distribution that strongly affect performance: composition equivalence and module coverage. We show that the apparent performance of direct models (trained only on final outputs) results primarily from exploiting composition equivalences, meaning different sequences of modules that reduce to identical end-to-end functions. When benchmarks eliminate these equivalences, performance drops significantly, showing their inability to generalize to compositions of known modules that produce novel end-to-end functions. We further demonstrate that performance degrades monotonically as module coverage shifts increase (when modules appear in different contexts between train and test), affecting both direct and step-by-step models (trained on intermediate and final outputs). These findings have concrete implications for benchmark design: benchmarks that include compositional equivalences can lead to significant overestimation of the generalization abilities of direct models, and benchmarks that include both module coverage violations and compositional equivalences can exacerbate shortcut learning. As a case study, we demonstrate the role of compositional equivalence on the generalization performance of the pre-trained model Llama3-8B on the code-output prediction task in the coding benchmark LiveCodeBench.

## Quote from the paper

Purva Pruthi, Andrew Yuan, Alexander D'Amour, David Jensen (2026). Evaluating Compositional Generalization in Transformers: The Role of Composition Equivalence and Module Coverage. arXiv:2611.13498v1. https://arxiv.org/abs/2611.13498v1

**BibTeX**

```
@misc{pruthi2026evaluating,
  title = {{Evaluating Compositional Generalization in Transformers: The Role of Composition Equivalence and Module Coverage}},
  author = {Purva Pruthi and Andrew Yuan and Alexander D'Amour and David Jensen},
  year = {2026},
  eprint = {2611.13498},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.13498v1}
}
```

## Other paper commentary

- [Is Persona Generalization Predictable?](https://refivu.com/en/papers/ae408b05-af42-4e04-bc37-7a735a9a0b4d-is-persona-generalization-predictable.md)
- [Decoupled Weight Decay Regularization](https://refivu.com/en/papers/19eca1c5-1291-475b-a58c-daedbe769654-decoupled-weight-decay-regularization.md)
- [SGDR: Stochastic Gradient Descent with Warm Restarts](https://refivu.com/en/papers/69cc99a3-59f2-4776-b5e2-a3baaeb53f0c-sgdr-stochastic-gradient-descent-with-warm-restarts.md)
- [mixup: Beyond Empirical Risk Minimization](https://refivu.com/en/papers/cc1e3261-af7e-47fa-99d8-0806fbe6afcf-mixup-beyond-empirical-risk-minimization.md)
- [Weight Normalization: A Simple Reparameterization to Accelerate Training of Deep Neural Networks](https://refivu.com/en/papers/c1050ccf-ffa6-4158-8fff-24b3a8223df6-weight-normalization-a-simple-reparameterization-to.md)
- [The Lottery Ticket Hypothesis: Finding Sparse, Trainable Neural Networks](https://refivu.com/en/papers/9c072b5c-bd96-4202-8960-653ce6a7f2fb-the-lottery-ticket-hypothesis-finding-sparse-trainable.md)
- [The Indic Token Tax in 2026: Measuring Tokenizer. Disparity and Its Cost for the Languages of India](https://refivu.com/en/papers/94ad0eca-69d1-49c3-a2dd-49e3e35883a8-the-indic-token-tax-in-2026-measuring-tokenizer.md)
- [Bursts That Outlast Themselves: Persistent Degradation in Prefix-Cached Agent Serving](https://refivu.com/en/papers/f586e747-0f45-4182-ad11-8ba2e00193e6-bursts-that-outlast-themselves-persistent-degradation-in.md)
- [Counting Under Disagreement: Dollar-Weighted Measurement, Selective Machine Labelling and Budgeted Human Review from Disagreeing AI Readers of Administrative Text](https://refivu.com/en/papers/af261e08-56f4-4c82-95e0-57ec1ecf0304-counting-under-disagreement-dollar-weighted-measurement.md)
- [Near-Optimal Sample Complexity of Deterministic Agnostic PAC Learning](https://refivu.com/en/papers/39c5e4f6-4a92-4c1d-b07b-0e6ecad3cdc4-near-optimal-sample-complexity-of-deterministic-agnostic-pac.md)
- [Audited Gradients, Anchored Policies: Model-Based Reinforcement Learning for Efficient Flow Control](https://refivu.com/en/papers/59b36b93-d7e6-4e24-a0db-14eab8639fe2-audited-gradients-anchored-policies-model-based.md)
- [RadRef: A Reference-Free Metric for Radiology Report Generation](https://refivu.com/en/papers/c021bdd5-9b56-4971-9197-cb24eda10255-radref-a-reference-free-metric-for-radiology-report.md)

## Terms in this paper

- [LoRA](https://refivu.com/en/terms/bee764895c36-lora)
- [LiveCodeBench](https://refivu.com/en/terms/a42eecb00259-livecodebench)
- [shortcut learning](https://refivu.com/en/terms/06126519243d-shortcut-learning)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/51035e38-2ad0-44b9-9a53-5f7b0e4038b4-evaluating-compositional-generalization-in-transformers-the)
