arXiv:2610.39016cs.CLOct 2026

Manuscript Offprint

arXiv:2610.39016

Implicit Reasoning in Transformers: Bridging the Compositionality Gap in GPT-2-like Models

Davide Venuto, Leonardo Venuto

Abstract

Compositional generalization remains a persistent limitation of transformer language models: even when a model learns to combine known facts correctly in-distribution (ID), the same compositional mechanism may fail when applied to out-of-distribution (OOD) knowledge. We investigate this compositionality gap in a controlled two-hop reasoning setting using a GPT-2-like transformer model trained from scratch. Building on prior work identifying a circuit associated with compositional generalization, we test whether the failure of OOD transfer is related to how atomic knowledge is structurally exposed during training. We modify the training distribution by presenting both ID and OOD atomic facts in a format positionally aligned with the second-hop retrieval step of the learned compositional circuit, without modifying the model architecture or adding OOD compositional supervision. Under this intervention, the model successfully transfers the learned ID compositional behaviour to held-out OOD atomic facts, closing the observed compositionality gap in the controlled setting. Our results provide evidence that the observed compositionality gap is not a fundamental architecture limitation and that it can be overcome through mechanically informed training distribution design.

1 Introduction

Large language models (LLMs) can store vast amounts of knowledge, but recalling individual facts is rarely enough, many questions require combining several pieces of information through multi-hop reasoning [Wei et al., 2023, Press et al., 2023, Wang et al., 2024]. When this composition happens inside a single forward pass, without verbalizing intermediate steps, it is called implicit reasoning. This step is all but trivial, it has been shown that models that can reliably answers two atomic queries will often fail on their composition [Press et al., 2023, Yang et al., 2025], a failure Press et al. [2023] called the compositionality gap.

Explicit decomposition methods such as Chain-of-Thought can narrow the compositionality gap by verbalizing intermediate steps [Wei et al., 2023, Press et al., 2023], an inference-time solution that acts on top of the core capabilities the model acquires during (pre-)training [Zhou et al., 2023, Lin et al., 2023].

Code available at: https://github.com/Davide011/implicit-reasoning-bridging-compositionality-gap

Controlled studies show that grokked transformers (i.e. trained far beyond overfitting) can learn implicit two-hop composition tasks. For example, given the atomic facts “Barack’s wife is Michelle” and “Michelle was born in 1964,” the model can infer that “Barack’s wife was born in 1964.” These models generalize to unseen In-Distribution (ID) cases (atomic facts that appear in compositional training examples), yet fail to systematically transfer the same compositional behaviour to Out-of-Distribution (OOD) cases (atomic facts seen only in isolation, never in compositional training examples) [Wang et al., 2024, Karmim et al., 2026, Yang et al., 2025, Biran et al., 2024]. Ye et al. [2025] pushed this further by showing that generalization extends to queries whose first-hop is OOD, but never to those whose second-hop is. So the natural question is: what limits the transfer of a learned compositional mechanism to OOD atomic facts, and under what training-data conditions can such generalization emerge?

We address this question by modifying the training distribution while keeping the task and model architecture fixed, without introducing any additional compositional supervision, working with the same rigorous synthetic setup from Wang et al. [2024]. Specifically, we introduce a position-aligned atomic-fact format that exposes atomic facts in the configuration associated with second-hop processing, and use controlled ablations to identify the conditions under which the learned compositional behaviour transfers to OOD knowledge, enabling OOD compositional generalization.

The main contributions of this work are as follows:

We show that exposing atomic facts at the position corresponding to the second hop is insufficient on its own for OOD compositional rule transfer, demonstrating that positional alignment alone does not close the compositionality gap.

We identify an additional training-distribution condition associated with the successful OOD compositional transfer: a shared position-aligned representation across ID and OOD atomic facts that implicitly connects the learned ID compositional rule to OOD facts.