NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Graph Linearization Methods for Reasoning on Graphs with Large Language Models

Christos Xypolopoulos, Guokan Shang, Xiao Fei, Giannis Nikolentzos, Hadi Abdine, Iakovos Evdaimon, Michail Chatzianastasis, Giorgos Stamou, Michalis Vazirgiannis

TL;DR

Large Language Models (LLMs) excel at sequential text but struggle with non-linear graph structures. This paper introduces structured "graph linearization" techniques based on graph centrality and degeneracy, combined with node relabeling, to format graphs into sequences that mimic natural language properties. This simple preprocessing step significantly boosts an LLM's ability to reason about graph connectivity, degrees, and topologies without any additional training.

What Problem Does This Paper Address?

Transformers are inherently sequence-based models trained on trillions of textual tokens, meaning they rely heavily on the natural flow, local context, and structural alignment of language. Graphs, on the other hand, are multi-dimensional, relational data structures.

When researchers try to feed graphs into LLMs, they typically use naive approaches like raw edge lists (e.g., [(1, 2), (2, 3)]) or basic textual descriptions. However, these formats lack a standardized order or meaningful labeling, forcing the LLM to waste its computational capacity just trying to piece the graph's topology together. This paper tackles a fundamental question: How can we represent general graphs as linear token sequences that naturally align with an LLM's text-trained inductive biases?

Methods

The authors propose sorting and renaming graph components to introduce two key natural language properties: local dependency (predicting a token based on its neighbors) and global alignment (consistent sequence structures across different samples).

  1. Edge Ordering via Centrality and Degeneracy: Instead of listing edges randomly, nodes are ranked using structural metrics:
  2. Degree Centrality: Ranking by the number of direct connections.
  3. PageRank Centrality: Ranking by both the quantity and quality of connections.
  4. Core Number (Graph Degeneracy): Ranking based on k-core decomposition, which identifies densely connected subgraphs. Edges are then explored and listed in descending order of the nodes' structural importance.

  5. Node Relabeling: To achieve global alignment, arbitrary node names (like random integers or letters) are replaced with their structural rank. For instance, the most central node in any graph is always relabeled as 0.

  6. Linegraph Transformation (LG): For edge-centric tasks, the graph is converted into a linegraph (where edges become nodes and vice versa) before linearization, allowing the model to focus directly on edge-to-edge relationships.
Figure 1: An example of degree-based graph lineariza- tion method. Given an input graph G, we rank its nodes based on their degree and then explore the edges in that order. The resulting linearized graph is then combined with a task-specific prompt and passed into a LLM.

Datasets

The methods were evaluated using zero-shot and one-shot prompting on two synthetic datasets:

  • GraphWave: A dataset of 3,000 graphs generated by attaching distinct structural motifs (cliques, stars, fans, diamonds, trees) to cycle or chain bases. This dataset evaluates an LLM's ability to recognize sub-graph patterns.
  • GraphQA: A standard benchmark containing graphs from various classic generators (Erdős–Rényi, Barabási–Albert, scale-free, and stochastic block models) ranging from 5 to 20 nodes, used to test fundamental topological properties.
Figure 2: Overview of GraphWave synthetic dataset.

Key Insights and Ideas

  • Structure Mimics Language: By sorting edges by structural importance, the authors create a "narrative arc" for the graph. The LLM can better predict subsequent tokens because the context flows logically from the most critical hubs to the periphery.
  • Labels Matter More Than You Think: Simply ordering the edges helps, but relabeling nodes based on their structural rank provides a massive performance leap. It gives the LLM a reliable anchor—knowing that node 0 is always the most connected hub helps it navigate the rest of the sequence.
  • No One-Size-Fits-All Linearization: Node-focused tasks (like finding the maximum degree) benefit most from simple Degree or PageRank sorting. Conversely, edge-focused tasks (like determining if a path exists) benefit more from CoreNumber or Linegraph representations because they preserve structural cohesiveness.

Key Results

Using Llama 3 8B, the structured linearization methods consistently outperformed fully random baselines across nearly all tasks:

  • GraphQA Benchmark: Combining degree-based ordering with node relabeling improved accuracy by roughly 35% on the maximum node degree estimation task and by 13% on shortest path tasks.
  • GraphWave Benchmark: The same combination boosted edge existence reasoning by approximately 26%.
  • The Scaling Wall: While scaling from an 8B to a 70B model significantly improved node counting and motif shape classification, diameter estimation (finding the longest shortest path) remained universally abysmal, proving that global graph properties are still a major blind spot for LLMs regardless of size.

Limitations and Future Work

  • Synthetic Constraints: The study relies entirely on synthetic graphs. Real-world networks (like social graphs or molecular structures) are much noisier and may behave differently.
  • Context Window Bottlenecks: Because graphs are linearized into text prompts, large graphs quickly hit the context window limits of the LLM.
  • Missing Complex Features: The current linearization metrics do not explicitly capture higher-order properties like community structures or distinct connected components.
  • Untrained Potential: The authors only tested off-the-shelf models via prompting. A natural next step is instruction fine-tuning an LLM directly on these linearization formats to see if it can unlock true graph-native reasoning.

Summary updated

BibTeX
@misc{xypolopoulos2024graph,
  author = {Christos Xypolopoulos and Guokan Shang and Xiao Fei and Giannis Nikolentzos and Hadi Abdine and Iakovos Evdaimon and Michail Chatzianastasis and Giorgos Stamou and Michalis Vazirgiannis},
  title = {{Graph Linearization Methods for Reasoning on Graphs with Large Language Models}},
  year = {2024},
  eprint = {2410.19494},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.19494},
}
Figure