Topological Encodings for Graph Transformers

This direction is merged into another direction: Laplacian positional encoding. Its last version stays readable and citable here.

Version 1 of 140 papers42 conceptsfrozen 2026-10-04

Standard Transformers are designed for sequences, where the order of tokens is linear and fixed. When we apply them to graphs, we encounter a fundamental mismatch: Transformers are permutation-invariant, meaning they treat their input as an unordered set. Without a way to "see" the connections between nodes, a Transformer perceives a complex molecule or a social network simply as a bag of isolated points.

To bridge this gap, researchers have developed Topological Positional Encodings. These mechanisms inject the "shape" of the graph directly into the Transformer’s attention layers, allowing the model to reason about connectivity, distance, and structural importance.

The Geometry of a Set

In a standard Transformer, we use sinusoidal or learnable embeddings to tell the model that "word A comes before word B." In a graph, there is no single "before" or "after." Instead, there is proximity, hierarchy, and role.

As Erxue Min and Wenbing Huang note in their architectural overview, graph-aware modifications generally fall into three categories: node-level features, modified attention matrices, and structural encodings. The goal of these encodings is to provide a "coordinate system" for the graph that remains stable even if we reorder the list of nodes.

Capturing Importance with Centrality Encodings

Not all nodes are created equal. In a social network, a celebrity is more "central" than a casual user; in a molecule, a carbon atom in a ring has a different structural role than a terminal hydrogen.

Graphormer, developed by Chengxuan Ying and Di He, introduced Centrality Encodings. By taking simple graph-theoretic metrics like in-degree and out-degree and converting them into learnable vectors, the model can weigh the influence of a node based on its connectivity. Similarly, WHATsNet by Minyoung Choe and Kijung Shin uses PageRank scores as a positional signal, allowing the attention mechanism to distinguish nodes based on their global popularity or influence within the network.

Measuring Proximity with Distance Encodings

While centrality tells us who a node is, distance encodings tell us where it is relative to others. In a sequence, distance is just the number of steps between two indices. In a graph, we use the Shortest Path Distance (SPD).

In the Hyperformer architecture, Yuxuan Zhou and Chao Li use SPD to bias the self-attention mechanism. If two joints in a skeleton are physically connected, the model gives them a stronger "structural prior." This concept is extended in GIMLET by Haiteng Zhao, which replaces standard sequential embeddings with distance-based metrics to help Transformers process molecules and text instructions in a unified space.

A more recent innovation, Weaver by Jiaxuan Chen, maps these graph distances into Rotary Positional Embeddings (RoPE). By rotating the hidden representations in the complex plane based on their topological distance, the model treats the graph's connectivity as a "virtual geometric context."

Spectral and Global Awareness

Some structural properties are global and cannot be captured by just looking at immediate neighbors or paths. To address this, researchers look to the "spectrum" of the graph.

The GPS framework by Ladislav Rampásek and Michael Galkin advocates for a modular approach, combining local structural features (like Random Walk diagonals) with global spectral features (like Laplacian eigenvectors). Laplacian eigenvectors act as a multi-dimensional coordinate system for the graph, similar to how Fourier transforms work for signals. As demonstrated in CrysToGraph by Ji Sun, these spectral encodings are particularly powerful for periodic structures like crystal lattices, where they compensate for the Transformer's inherent lack of spatial awareness.

Why It Works: Breaking Symmetry

The intuition behind all these methods is symmetry breaking. In a vanilla Transformer, every node is identical to every other node until the attention mechanism looks at their features. If two nodes have the same features but different positions in the graph, the Transformer cannot distinguish them.

By adding topological encodings—whether they are based on degree (PGTR), path routes (Graph Informer), or Weisfeiler-Lehman structural roles (TG-Transformer)—we provide the model with a unique "signature" for each node's location. This allows the global attention mechanism to act not just as a set aggregator, but as a powerful reasoner over the graph's underlying geometry.

Papers in this version

History & citationVersion 1 · 2026-10-04

Merged into another direction · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_topological_encodings_for_graph_transfor_ebc486db,
  title = {Topological Encodings for Graph Transformers},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/topological-encodings-for-graph-transformers/rdr_ebc486dbbb7f4d4c910921dc2581a5ac},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-24},
}

This exact version (version 1, frozen text):

@misc{lacuna_topological_encodings_for_graph_transfor_ebc486db_v1,
  title = {Topological Encodings for Graph Transformers},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/topological-encodings-for-graph-transformers/rdr_ebc486dbbb7f4d4c910921dc2581a5ac/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-24},
}