Graph2Token: Tokenizing Graphs for Transformers
- Graph2Token is a framework that transforms graph structures into token sequences, enabling Transformers to process nodes, edges, and subgraphs effectively.
- It organizes tokenization into granularity levels—node, hop, composite, quantized, and serialized—to reveal structural details and optimize performance.
- Empirical systems like TokenGT, NAGphormer, and NTFormer demonstrate that Graph2Token methods can achieve expressivity comparable to specialized graph neural networks.
Searching arXiv for papers on Graph2Token and related graph tokenization frameworks. Graph2Token denotes a family of graph-to-token mappings that convert a graph into tokenized inputs consumable by Transformers or LLMs. In the contemporary graph-learning literature, the output may be a real-valued token matrix , a discrete sequence , a tuple of codebook indices produced by vector quantization, or a small set of continuous prompt vectors inserted directly into an LLM. The common objective is to expose graph structure, attributes, and multiscale context through a sequence-model interface. A separate algebraic-graph-theoretic usage of “token graph” refers instead to the -token graph , the symmetric -th power of a graph, which is conceptually distinct from learned graph tokenizers (Bechler-Speicher et al., 21 May 2026, Yu et al., 2 Jan 2025, Perozzi et al., 2024, Reyes et al., 2023).
1. Formalization and design space
A general Graph2Token pipeline can be factorized into graph decomposition, tokenization, and sequence construction. In the formulation summarized in the LLM4graph perspective, graph elements such as nodes, edges, and subgraphs are mapped by tokenization functions , , and , then ordered into a sequence . In a more general transformer-theoretic formulation, a graph tokenization is a possibly non-learnable map , so the token interface need not be discrete in the NLP sense (Yu et al., 2 Jan 2025, Bechler-Speicher et al., 21 May 2026).
The survey on Graph Transformers divides graph tokenization into four granularity levels: node-level tokenization, edge-level tokenization, subgraph-level tokenization, and hop-level tokenization. That taxonomy is useful because later systems differ less in the existence of a token interface than in what graph object becomes a token and how much structural information is made explicit before attention is applied (Yuan et al., 23 Feb 2025).
| Granularity | Token construction | Representative instantiations |
|---|---|---|
| Node+edge | One token per node and per edge | TokenGT (Kim et al., 2022) |
| Hop-level | 0 | NAGphormer (Chen et al., 2022), NAGphormer+ (Chen et al., 2023) |
| Composite node-centric | Multiple sequences from topology and attribute views | NTFormer (Chen et al., 2024), SwapGT (Chen et al., 12 Feb 2025) |
| Quantized or pooled | Codebook indices or pooled soft tokens | GQT (Wang et al., 2024), GraphToken (Perozzi et al., 2024), Graph2Token for molecules (Wang et al., 5 Mar 2025) |
| Serialized discrete | Reversible graph sequence followed by BPE | GraphTokenizer (Guo et al., 11 Mar 2026) |
This design space also separates three token modalities. Some methods emit explicit discrete IDs from learned vocabularies or codebooks; some serialize graphs into symbol sequences and then apply a text tokenizer; others produce continuous “soft tokens” in the embedding space of a frozen LLM. This suggests that Graph2Token is best understood as an interface layer rather than a single architecture.
2. Tokenized graph Transformers
A canonical edge-level Graph2Token system is TokenGT, which treats each node and each edge as an independent token. Given node feature 1 and edge feature 2, TokenGT defines
3
where 4 are fixed orthonormal node identifiers and 5 are learned type identifiers. The packed token matrix is then linearly projected and processed by a standard Transformer with a prepended 6 token. The paper proves that, with appropriate token embeddings, a pure Transformer on these tokens is at least as expressive as a 2-IGN and can approximate any 2-IGN to arbitrary precision; on PCQM4Mv2, TokenGT with Laplacian node identifiers attained validation MAE 7, while a linear-cost Performer variant achieved 8 (Kim et al., 2022).
Hop-level tokenization was systematized by NAGphormer through Hop2Token. For each node 9, the model precomputes
0
and forms the sequence 1, where 2 is the 3-th row of 4. The resulting per-node token sequence is short, enabling mini-batch training with per-node attention rather than full-graph attention. NAGphormer reports time complexity 5 and outperforms scalable GNNs on large graphs; on Amazon2M, it reached 6 accuracy, exceeded PPRGo, GraphSAINT, and GRAND+, and required 7 s and 8 MB per epoch in the reported efficiency comparison (Chen et al., 2022). The neighborhood-augmentation variant adds Global Neighborhood Augmentation and Local Neighborhood Augmentation on the hop-token sequences and reports further gains, including 9 on Amazon2M and state of the art on 0 small benchmarks in the summarized experiments (Chen et al., 2023).
Later node-tokenized graph Transformers broadened the token generator itself. NTFormer’s Node2Par maps each node 1 to four sequences: 2, 3, 4, and 5, combining topology-view and attribute-view neighborhood tokens with topology-view and attribute-view sampled node tokens. These are encoded by plain Transformer blocks without graph-specific modifications, and the resulting representations are fused by learned weights. The reported gains include 6 on Squirrel, 7 on Roman-empire, and 8 on Reddit (Chen et al., 2024). SwapGT extends the same node-tokenized regime with a token-swapping augmentation that replaces a token by a randomly sampled neighbor of that token in a k-NN similarity graph, then constrains consistency by a center alignment loss. Across eight datasets and two train/validation/test regimes, the summary reports uniform improvements over classical GNNs and recent graph Transformers by approximately 9–0 points (Chen et al., 12 Feb 2025).
3. Discrete tokenizers: quantization, serialization, and indexing
Quantization-based Graph2Token systems explicitly learn a discrete vocabulary for graphs. GQT, “Graph Quantized Tokenizer,” first trains a multi-layer GNN encoder under multi-task self-supervision, then quantizes node or subgraph embeddings with vector quantization and Residual Vector Quantization (RVQ). For each embedding 1, nearest-neighbor assignment in a codebook 2 yields 3, and the RVQ hierarchy recursively quantizes the residual,
4
so the discrete token is the tuple 5. Tokenizer training minimizes 6, combines semantic edges and PPR during sequence construction, and feeds the resulting token sequence into a standard TransformerEncoder. The detailed summary reports memory reductions of 7 for a 8-node graph with 9-dimensional features, 0 on Physics, and 1 on ogbn-products with 2; it also reports wins on 3 medium-scale homophilous datasets, 4 heterophilous datasets, and strong large-scale results including 5 ROC-AUC on ogbn-proteins and 6 on ogbn-products (Wang et al., 2024).
A later hierarchical quantization framework, implemented in the QUIET framework and also referred to as Graph2Token, keeps the encoder frozen and introduces a self-weighted gating mechanism over multiple RVQ levels. The tokenizer adds a VQ-VAE commitment loss, a balance loss to discourage uneven codeword usage, and a diversity loss between adjacent levels. For each node, a small gating MLP computes logits 7, transforms them into weights 8 by temperature-scaled softmax, and forms the final token embedding 9. In the reported experiments, Graph2Token improves Corafull node classification by approximately 0 over GQT under the same codebook size, increases Cora link-prediction MRR from 1 to 2, reduces required epochs by 3–4, and yields token sequences 5–6 shorter than raw GNN embeddings (Xiang et al., 14 Oct 2025).
A distinct discrete route is reversible graph serialization followed by subword tokenization. “Graph Tokenization for Bridging Graphs and Transformers” constructs deterministic edge-covering walks guided by global frequencies 7 of labeled edge-context patterns 8, then trains a BPE vocabulary over the serialized sequences. The tokenizer is reversible up to isomorphism, and BPE is trained by repeated merges of the most frequent adjacent pair. On 14 benchmarks, GT+GTE achieved 9 ROC-AUC on OGBG-molhiv, 0 accuracy on Mutag, and 1 MAE on QM9; on ZINC, raw reversible Eulerian sequences of approximately 2 tokens were reduced to approximately 3 tokens after BPE, with reported 4 compression and approximately 5 faster per-epoch training than the no-BPE variant (Guo et al., 11 Mar 2026).
Graph2Token can also serve indexing rather than prediction. CoRGII learns dense node embeddings with a shared GNN, maps them through sigmoid MLP heads into 6-bit soft codes with 7, hard-thresholds them into binary codes, and interprets the 8 possible codes as a latent vocabulary for an inverted index. It then augments classical inverted-index scoring with a learned impact network 9 and supports Hamming and co-occurrence multi-probing. The summary reports that CoRGII strictly outperforms baselines in space–accuracy tradeoff on four TU datasets; on COX2, it reaches MAP approximately 0 at 1, and on PTC-FR it reaches MAP approximately 2 while retrieving only about 3 of the corpus (Chakraborty et al., 26 Oct 2025).
4. Graph2Token as an interface to LLMs
Graph2Token methods for LLMs often replace discrete graph vocabularies with continuous soft prompts. GraphToken learns an encoder 4 that maps an attributed graph 5 to 6, where 7 is a fixed-length sequence of continuous token embeddings in the LLM token space. Internally, it uses a lightweight GNN body and projection heads to produce node-, edge-, and graph-level prompt vectors, which are then spliced directly into the frozen LLM input. On the GraphQA benchmark, the reported gains include node-count 8, cycle-check 9, edge-existence 0, shortest-path 1, and an increase on triangle-counting from 2 zero-shot and 3 soft-prompt to 4, described as up to 5 absolute accuracy on triangle-counting; overall average accuracy rises from approximately 6 for text-only baselines to approximately 7 (Perozzi et al., 2024).
In molecular few-shot learning, Graph2Token is used to align graph representations with an LLM’s native vocabulary without fine-tuning the LLM backbone. The method constructs a molecule–text paired dataset from CHEBI, HMDB, and PubChem IUPAC names, yielding approximately 8 K unique molecules with short descriptions of average 9 tokens. A 5-layer GIN encoder produces a graph vector 00, BERT-base yields a text vector 01, and a CLIP-style InfoNCE objective aligns them. A cross-attention retrieval module then maps 02 into the LLM token-embedding space, producing a vector 03 that replaces a special token 04 in Llama3-8B. IUPAC names are placed at the start of the prompt. The reported few-shot results include classification averages of 05 and 06 in the 07 and 08 settings for the TOX21 transfer protocol, regression averages of 09 and 10, and parameter efficiency of 11 M tuned parameters, or 12 of total parameters (Wang et al., 5 Mar 2025).
The single-token bottleneck of graph-to-LLM interfaces has also been studied directly. “Is One Token All It Takes?” formulates pooling as 13 and evaluates Top-k, SAGPool, DiffPool, MinCutPool, and Virtual Node Pooling (VNPool). The paper reports that pooling can be unstable under soft-prompt tuning, while LoRA stabilizes specific hierarchical projections, especially VNPool and pruning methods; VNPool is shown to be structurally equivalent to a single-layer Perceiver IO encoder. On WebQSP with 14 tokens and LoRA 15, mean pooling with one token attains 16 Hit@1, all-tokens reaches 17, and VNPool reaches 18 (Grover et al., 1 Apr 2026).
The LLM4graph perspective organizes these systems around four modality-gap challenges: alignment, position, multi-level semantics, and context. Alignment concerns projection into the LLM token space; position concerns replacing linear token order by graph positional encodings; multi-level semantics concerns the mismatch between text’s long-range dependencies and graphs’ multi-hop structure; context concerns the limited corpus-level context available in a single graph. In that framing, Graph2Token is one of two major transformation paradigms alongside Graph2text (Yu et al., 2 Jan 2025).
5. Expressivity, trade-offs, and a terminological ambiguity
A central theoretical result is that Graph2Token is not merely an implementation detail. TokenGT proves that a standard Transformer operating on node and edge tokens with suitable embeddings can simulate the equivariant basis structure of 2-IGNs. The proof proceeds through a construction in which, with 19 heads, one can approximate a single 20 layer, and stacking such layers yields approximation of any 2-IGN. The survey accordingly identifies edge-level tokenization as a route to 2-WL power, in contrast to node-only tokens without structural positional encoding, which are at best 1-WL expressive (Kim et al., 2022, Yuan et al., 23 Feb 2025).
“Lost in Tokenization” shifts the emphasis from expressivity within a fixed tokenizer to trade-offs across tokenizers. It studies three core Graph2Token maps: spectral tokenization, random-walk tokenization, and adjacency tokenization. The paper proves depth separations: 21-closed-walk detection is available in 22 depth under random-walk tokenization but requires 23 depth with adjacency tokens; graph connectivity can be decided with 24 under full spectral tokens but requires 25 layers with adjacency tokens. It also proves that random-walk tokenization is lossy for any walk length, that full spectral tokenization is lossless up to isomorphism but ill-conditioned for local tasks such as edge prediction, and that limited-depth transformers generally cannot translate between tokenization families. In the empirical section, local tasks favor adjacency tokens, global molecular tasks favor spectral tokens, and concatenating multiple tokenizations often gives the best overall performance (Bechler-Speicher et al., 21 May 2026).
The term “token graph” has an older and unrelated meaning in algebraic graph theory. There, the 26-token graph 27 has as vertices the 28-subsets of 29, and two such subsets are adjacent when their symmetric difference is an edge of 30. This construction satisfies 31 and 32, the Johnson graph. The literature cited here studies the adjacency and Laplacian spectra of 33, exact spectral-radius results for walk-regular graphs, quotient-matrix analyses for 34 when 35 is distance-regular, and a proposed generalization of Aldous’ spectral-gap conjecture (Reyes et al., 2023). A common misconception is therefore terminological: Graph2Token in machine learning and 36-token graphs in combinatorics are not the same object.
6. Empirical regularities, limitations, and future directions
Several regularities recur across the literature. Hop-level and neighborhood-token methods enable mini-batch training and large-graph scalability, as seen in NAGphormer and its augmentation-based extension (Chen et al., 2022, Chen et al., 2023). Quantization-based interfaces can trade continuous embeddings for compact discrete codes while retaining downstream performance and substantially reducing memory, as in GQT and QUIET (Wang et al., 2024, Xiang et al., 14 Oct 2025). LLM-oriented Graph2Token systems often preserve the LLM backbone and concentrate learning in small encoders, tokenizers, or low-rank adapters, as in GraphToken, molecular Graph2Token, and LoRA-stabilized multi-token pooling (Perozzi et al., 2024, Wang et al., 5 Mar 2025, Grover et al., 1 Apr 2026). Theoretical and empirical work further indicate that no single tokenization family dominates across all tasks; different tasks favor different structural views (Bechler-Speicher et al., 21 May 2026).
The literature also rejects several simplifying assumptions. Graph2Token is not inherently discrete: it may produce codebook indices, symbol sequences, or continuous prompt vectors. It is not tied to one granularity: tokens may represent nodes, edges, hop neighborhoods, subgraphs, whole graphs, or pooled latent slots. Nor is tokenization a neutral preprocessing step. One theory paper states explicitly that the graph-to-token map is a fundamental component of transformer expressivity, and several empirical studies report that the choice of token sequence generator substantially changes performance even when the Transformer backbone remains vanilla (Bechler-Speicher et al., 21 May 2026, Chen et al., 2024, Chen et al., 12 Feb 2025).
Open problems are correspondingly diverse. The survey identifies token explosion and the 37 burden of self-attention for edge-level tokenization on dense graphs, motivating hierarchical token pruning and linearized attention (Yuan et al., 23 Feb 2025). GraphTokenizer notes that continuous node and edge features must be quantized, that BPE can obscure node-level or edge-level targets, and that serialization becomes a CPU bottleneck at OGB scale (Guo et al., 11 Mar 2026). The hierarchical quantization literature highlights sensitivity to hyperparameters such as 38 and suggests non-Euclidean quantizers and large-scale unsupervised pre-training of codebooks (Xiang et al., 14 Oct 2025). Molecular Graph2Token points to dependence on CHEBI and HMDB coverage and proposes adding corpora such as ChEMBL and PubMed abstracts, while also noting that multitoken graph vocabularies may help large or complex molecules (Wang et al., 5 Mar 2025). The GraphQA pooling study reports instability of dense clustering operators and benchmark saturation, with FandE scores 39 on ExplaGraphs and 40 on WebQSP (Grover et al., 1 Apr 2026). This suggests that future Graph2Token research will be shaped as much by benchmark design and tokenizer objectives as by Transformer scale.