Are Transformers Able to Reason by Connecting Separated Knowledge in Training Data?
Yutong Yin, Zhaoran Wang
TL;DR
This work investigates whether Transformer models can perform compositional reasoning by connecting fragmented knowledge during training. Using the FTCT synthetic dataset, it shows that few-shot Chain-of-Thought prompting enables accurate assembly of long causal chains from fragmented training pieces, with zero-shot performance being limited. The paper argues that compositional reasoning emerges when training and testing data are sufficiently similar (quantified by $\lambda = M/N \geq 0.3$) and requires multi-layer attention, suggesting that Transformers learn an underlying generalizable program. It provides theoretical results showing a two-layer Transformer can simulate this program and offers empirical evidence via induction heads and attention-assignment analyses. Overall, the findings indicate Transformers can exhibit robust compositional reasoning under controlled conditions, shedding light on the mechanisms that enable generalizable reasoning in large language models.
Abstract
Humans exhibit remarkable compositional reasoning by integrating knowledge from various sources. For example, if someone learns ( B = f(A) ) from one source and ( C = g(B) ) from another, they can deduce ( C=g(B)=g(f(A)) ) even without encountering ( ABC ) together, showcasing the generalization ability of human intelligence. In this paper, we introduce a synthetic learning task, "FTCT" (Fragmented at Training, Chained at Testing), to validate the potential of Transformers in replicating this skill and interpret its inner mechanism. In the training phase, data consist of separated knowledge fragments from an overall causal graph. During testing, Transformers must infer complete causal graph traces by integrating these fragments. Our findings demonstrate that few-shot Chain-of-Thought prompting enables Transformers to perform compositional reasoning on FTCT by revealing correct combinations of fragments, even if such combinations were absent in the training data. Furthermore, the emergence of compositional reasoning ability is strongly correlated with the model complexity and training-testing data similarity. We propose, both theoretically and empirically, that Transformers learn an underlying generalizable program from training, enabling effective compositional reasoning during testing.
