Table of Contents
Fetching ...

From Sequence to Structure: Uncovering Substructure Reasoning in Transformers

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

TL;DR

This work investigates how decoder-only Transformers infer graph structure from text by introducing Induced Substructure Filtration (ISF), a layer-wise process of progressively identifying subgraphs. It provides a rigorous framework including a Subgraph Isomorphism Indicator Tensor $ ext{T}(G,G')$ and a filtration-based theory that explains how substructures emerge across layers, supported by visualization and experiments on synthetic graphs. It further extends the framework with Thinking-in-Substructure (Tins) to decompose complex patterns and to attributed graphs, such as molecular graphs, demonstrating robust substructure extraction and relevance to graph reasoning in LLMs. The findings suggest a unified perspective on graph understanding in Transformers, with practical implications for building graph-aware LLMs and graph foundation models that can handle composite and labeled graphs. The work highlights the potential to improve efficiency and scalability by decomposing reasoning into substructures and by leveraging prompt design and input representations to align model behavior with graph topology, while outlining limitations and avenues for future theory and experimentation.

Abstract

Recent studies suggest that large language models (LLMs) possess the capability to solve graph reasoning tasks. Notably, even when graph structures are embedded within textual descriptions, LLMs can still effectively answer related questions. This raises a fundamental question: How can a decoder-only Transformer architecture understand underlying graph structures? To address this, we start with the substructure extraction task, interpreting the inner mechanisms inside the transformers and analyzing the impact of the input queries. Specifically, through both empirical results and theoretical analysis, we present Induced Substructure Filtration (ISF), a perspective that captures the substructure identification in the multi-layer transformers. We further validate the ISF process in LLMs, revealing consistent internal dynamics across layers. Building on these insights, we explore the broader capabilities of Transformers in handling diverse graph types. Specifically, we introduce the concept of thinking in substructures to efficiently extract complex composite patterns, and demonstrate that decoder-only Transformers can successfully extract substructures from attributed graphs, such as molecular graphs. Together, our findings offer a new insight on how sequence-based Transformers perform the substructure extraction task over graph data.

From Sequence to Structure: Uncovering Substructure Reasoning in Transformers

TL;DR

This work investigates how decoder-only Transformers infer graph structure from text by introducing Induced Substructure Filtration (ISF), a layer-wise process of progressively identifying subgraphs. It provides a rigorous framework including a Subgraph Isomorphism Indicator Tensor and a filtration-based theory that explains how substructures emerge across layers, supported by visualization and experiments on synthetic graphs. It further extends the framework with Thinking-in-Substructure (Tins) to decompose complex patterns and to attributed graphs, such as molecular graphs, demonstrating robust substructure extraction and relevance to graph reasoning in LLMs. The findings suggest a unified perspective on graph understanding in Transformers, with practical implications for building graph-aware LLMs and graph foundation models that can handle composite and labeled graphs. The work highlights the potential to improve efficiency and scalability by decomposing reasoning into substructures and by leveraging prompt design and input representations to align model behavior with graph topology, while outlining limitations and avenues for future theory and experimentation.

Abstract

Recent studies suggest that large language models (LLMs) possess the capability to solve graph reasoning tasks. Notably, even when graph structures are embedded within textual descriptions, LLMs can still effectively answer related questions. This raises a fundamental question: How can a decoder-only Transformer architecture understand underlying graph structures? To address this, we start with the substructure extraction task, interpreting the inner mechanisms inside the transformers and analyzing the impact of the input queries. Specifically, through both empirical results and theoretical analysis, we present Induced Substructure Filtration (ISF), a perspective that captures the substructure identification in the multi-layer transformers. We further validate the ISF process in LLMs, revealing consistent internal dynamics across layers. Building on these insights, we explore the broader capabilities of Transformers in handling diverse graph types. Specifically, we introduce the concept of thinking in substructures to efficiently extract complex composite patterns, and demonstrate that decoder-only Transformers can successfully extract substructures from attributed graphs, such as molecular graphs. Together, our findings offer a new insight on how sequence-based Transformers perform the substructure extraction task over graph data.

Paper Structure

This paper contains 54 sections, 16 theorems, 26 equations, 11 figures, 11 tables.

Key Result

Theorem 3.3

Given a $k$-node $m$-filtration ${\mathcal{F}}(V')$ on $V'=\{v_1', \dots, v_k'\}$. For any directed graphs $G=(V,E)$ ($|V|=n$) and $G'=(V',E')$, a log-precision Transformer with $m+2$ layers, constant heads, and $O(n^k)$ hidden dimension can output $\mathsf{vec}({\mathcal{T}}(G, G'[V_i']))$ at layer

Figures (11)

  • Figure 1: An overview of the interpretation for the substructure extraction task. a) Substructure Extraction Task: The Transformer receives a graph description and a question prompt as input and generates an answer. b) Interpretation Modules: The analysis includes input queries and internal Transformer processing. c) Simplified Substructure Extraction: The extraction process is simplified to highlight the core mechanism.
  • Figure 2: Visualization across 4 layers. We show the node ID distributions of target substructures. Legends indicate the node IDs
  • Figure 3: 4-Node 3-Filtration and Induced Subgraph Filtration
  • Figure 4: Tasks in Simultaneous detection
  • Figure 5: The Multi-Num setting results
  • ...and 6 more figures

Theorems & Definitions (36)

  • Definition 3.1: $k$-Node $m$-Filtration and Induced Subgraph Filtration
  • Definition 3.2: Subgraph Isomorphism Indicator Tensor
  • Theorem 3.3: Expressiveness for Progressive Identification
  • Theorem 3.5: Expressiveness for Pattern Extraction
  • Remark 3.6
  • Definition 3.7: Single-Shape-Multi-Num Extraction
  • Theorem 3.8: Expressiveness for Single-Shape-Multi-Num Extraction
  • Definition 3.9: Multi-Shape-Single-Num Extraction
  • Theorem 3.10: Expressiveness for Multi-Shape-Single-Num Extraction
  • Definition D.1: Adjacency List Graph Representation
  • ...and 26 more