From Sequence to Structure: Uncovering Substructure Reasoning in Transformers

Xinnan Dai, Kai Yang, Jay Revolinsky, Kai Guo, Aoran Wang, Bohang Zhang, Jiliang Tang

Introduction

Large Language Models (LLMs) have demonstrated an unexpected proficiency in graph-related reasoning tasks, such as finding shortest paths or identifying network cycles. This proficiency is paradoxical given that Transformers are fundamentally designed to process one-dimensional sequences. This paper investigates the internal mechanisms that allow Transformers to comprehend multi-dimensional graph structures, specifically focusing on how they identify non-linear "motifs"—such as triangles, squares, and complex clusters—from textual representations like adjacency lists.

Methodology: Induced Substructure Filtration

The core theoretical contribution of this work is Induced Substructure Filtration (ISF). This framework models Transformer layers as a progressive assembly line for structural information. According to ISF, initial layers identify basic components (e.g., individual edges), while subsequent layers aggregate these components into increasingly complex paths and eventually closed substructures.

Overview of the substructure extraction task and the interpretation modules used to analyze Transformer mechanisms.

To further enhance reasoning, the authors introduce the Thinking-in-Substructures (Tins) framework. Inspired by Chain-of-Thought prompting, Tins encourages the model to decompose complex target patterns into simpler, intermediate components. For instance, identifying a "house" shape involves first recognizing a triangle "roof" and a square "base." This decomposition significantly reduces computational complexity from $O(n^k)$ to $O(n^q)$, where $q$ represents the size of the largest sub-component.

Experimental Results

The study utilized a combination of synthetic graph datasets (5 million directed graphs) and real-world molecular data (QM9 and PCBA). Empirical evaluation shows a clear relationship between architectural depth and the complexity of the substructure being identified. While a 3-node triangle can be identified within 3 layers, a 5-node pentagon requires at least 5 layers to achieve high accuracy.

Performance metrics across different substructures, training sizes, and layer counts, demonstrating the correlation between depth and complexity.

Quantitative results show that small, 4-layer Transformers can achieve over 85% accuracy in extracting 4-node substructures. The Tins approach provided a performance boost of up to 46% on complex structures like "Diagonal" or "House" patterns compared to direct prediction. Furthermore, the model successfully identified functional groups in molecular graphs with over 90% accuracy. Experiments on large-scale models like Llama 3.1-8B and Qwen confirmed that these findings generalize to massive, general-purpose models, which progressively organize their understanding of graph structures in their middle-to-late layers.

Discussion and Conclusion

The research confirms that Transformers do not "see" graphs holistically but rather through layer-wise node aggregation. Each layer serves as a filter, narrowing the search space until the target motif is isolated. Interestingly, the choice of textual representation matters; while Adjacency Lists (AL) and Edge Lists (EL) are informationally equivalent, the compactness of AL allows the model to process information more efficiently, requiring fewer layers for the same task.

While this work provides a robust explanation for substructure extraction, future research is needed to explore global graph properties like isomorphism. Nonetheless, the ISF and Tins frameworks offer a significant step toward designing more efficient, graph-aware neural architectures.

Summary updated

BibTeX
@inproceedings{dai2025from,
  author = {Xinnan Dai and Kai Yang and Jay Revolinsky and Kai Guo and Aoran Wang and Bohang Zhang and Jiliang Tang},
  title = {{From Sequence to Structure: Uncovering Substructure Reasoning in Transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=1Qo6DzdPOG},
}
Figure