Random-Walk Tokenization for Graph Transformers
- Random-walk tokenization is a method for encoding graph structure by representing each node as a sequence of return probabilities from short random walks.
- It enables efficient, constant-depth inference tasks such as k-closed-walk detection, while inherently sacrificing fine-grained edge-level details.
- Compared to adjacency and spectral tokenizations, it offers a unique diffusion-oriented summary that balances computational efficiency with information loss.
Random-walk tokenization is a principled method for encoding graph structure as input for transformer models, in which each node is represented by a feature vector consisting of return probabilities from short random walks on the graph. This approach provides a diffusion-oriented summary of the local and global connectivity patterns surrounding each node, making it a fundamental tokenization paradigm in graph-transformer architectures. Its expressivity and limitations have been rigorously analyzed, especially in contrast to adjacency and spectral tokenizations, revealing fundamental trade-offs regarding information retention, inference depth, and task suitability (Bechler-Speicher et al., 21 May 2026).
1. Formal Construction
Let be an undirected graph with vertices, adjacency matrix , degree matrix , and random-walk transition matrix . Select a walk length function . The random-walk tokenization constructs a token for each node by recording the sequence of return probabilities:
where 0 is the probability that a random walk of length 1 starting at 2 returns to 3. The full token matrix is
4
These token vectors are linearly projected to the transformer’s hidden dimension and used as the initial token inputs. The transformer encoder architecture then processes these tokens, with each node able to attend globally, but its positional information is constrained to the random-walk statistics for its location in the graph.
2. Theoretical Expressivity and Limitations
Random-walk tokenization exhibits categorical expressivity limitations. The core limitation is its fundamental lossiness: key structural information, including global topological properties, is irrecoverable from random-walk tokens for any finite walk length.
Planarity Undecidability Theorem:
For any walk-length function 5, there exist planar and non-planar graphs 6 with
7
yet one can arrange for 8 to be non-planar (contain a Kuratowski minor such as 9) while 0 is planar. The construction leverages Godsil–McKay switching: for suitably chosen switching sets, the modified graph 1 satisfies 2, with 3 an orthogonal involution, yielding invariant return probabilities for all 4. As a result, no Graph Transformer, regardless of depth or width, can decide global planarity or reconstruct the full adjacency matrix from these tokens (Bechler-Speicher et al., 21 May 2026).
3. Inference Depth and Computational Regimes
Random-walk tokenization enables certain computations inaccessible to shallow transformers when using other tokenizations. Specifically, it directly exposes 5 statistics, allowing tasks such as 6-closed-walk detection to be solved in constant (7) transformer layers.
Depth Separation:
- With random-walk tokens, a transformer requires only 8 layers to decide if 9 exceeds a threshold.
- By contrast, when input tokens are only adjacency rows, extracting 0-closed-walks incurs a lower bound of 1 layers under the conjecture 2 (Bechler-Speicher et al., 21 May 2026).
| Tokenization | Information Retention | Inference Depth |
|---|---|---|
| Adjacency | Lossless (full reconstruction) | 3 for edge queries; 4 for 5-walks |
| Spectral (full) | Lossless up to isomorphism | 6 for global tasks |
| Random-walk | Lossy (fixed 7) | 8 for 9-walks, ill-suited for edges |
This table summarizes several depth and information trade-offs under each tokenization regime.
4. Comparison with Adjacency and Spectral Tokenizations
Relative to other tokenizations, random-walk tokenization offers a unique set of capabilities and shortcomings:
- Adjacency (0): Enables exact graph reconstruction; local queries (edge existence) are trivial with 1 layers, but recovering diffusion statistics like 2-walks requires 3 layers.
- Spectral (4): Full spectral tokenization (all Laplacian eigenpairs) is also lossless up to graph isomorphism. However, extracting local edge information is ill-conditioned—gradient magnitudes required for local queries scale at least linearly in the maximum degree.
- Random-walk (5): Intrinsically lossy—cannot reconstruct the adjacency matrix or decide planarity. However, provides well-conditioned, shallow access to diffusion-oriented statistics and 6-walk counts, and does not experience the conditioning issues of the spectral encoding.
A crucial result is that, despite both random-walk and spectral tokenizations deriving from adjacency information, there is a provable depth separation: a limited-depth transformer cannot in general convert between these representations.
5. Empirical Performance Across Tasks
Empirical experiments confirm the theoretical separations:
- Synthetic 7-walk Recovery:
Training a transformer to predict 8 from adjacency tokens produces a relative error increasing with 9, manifesting the depth barrier. Conversely, using random-walk tokens as input, the error remains stable at around 6–8%, regardless of 0.
- Downstream Benchmarks:
On applied datasets (e.g., molecular regression, node classification), random-walk tokenization excels where global connectivity or diffusion-like properties are target-relevant (such as ZINC property prediction). It is suboptimal for tasks requiring precise edge-level information, such as MaxClique and Topological Ordering, where adjacency tokens excel. Combining all three tokenizations—random-walk, adjacency, and spectral—by concatenating embeddings per node, often achieves the best aggregate results, as complementary information is exploited by the transformer (Bechler-Speicher et al., 21 May 2026).
6. Practical Guidance and Application Suitability
Random-walk tokenization is well-suited for tasks that depend primarily on diffusion processes or random-walk return probabilities, such as cycle detection or regression problems sensitive to spectral graph properties (e.g., spectral gap). It is particularly advantageous when shallow, constant-depth inference for such statistics is needed.
However, as it is provably blind to finer structural details—specifically, exact adjacency and global planarity—it should not be used in isolation for tasks requiring these properties. For such scenarios, it should be paired with:
- Adjacency tokens where fine-grained edge information is essential (e.g., clique detection, shortest paths, planarity),
- Spectral tokens when a globally well-conditioned representation is desired, especially for connectivity or community structure detection, while being aware of spectral tokenization’s ill-conditioning for local queries.
A highly effective practice is to combine the three paradigms—random-walk, adjacency, and spectral—by concatenating their respective node embeddings, enabling the model to exploit the distinct local and global signals available at shallow depth (Bechler-Speicher et al., 21 May 2026).