Why GNNs Need Positional Encodings

7 minute read

Published:

TL;DR: Message-passing GNNs are permutation-equivariant, and their node representations are refinements of the 1-WL colouring. Two nodes that 1-WL cannot separate get the same embedding, however far apart they sit in the graph. Positional encodings add node-specific structural information computed from the graph — Laplacian eigenvectors, random-walk return profiles, distances to anchors — that message passing alone cannot derive.
Why GNNs need positional encodings
Positional encodings as graph structure signals (Dwivedi et al., 2022)

Intuition First

Imagine reading a sentence where all words are presented as an unordered bag — you lose the crucial information about what comes first, second, last. Transformers solve this with sinusoidal positional encodings that inject a unique “address” for each position.

Graphs face the same problem, but harder: there is no canonical position 1, 2, 3 — the graph has no start or end. Two nodes can have the same local neighborhood structure yet be in fundamentally different global positions. Without positional encodings, a GNN is forced to treat them identically.

Without PE: B = D (same embedding) A B C D E B and D: same 1-WL colour at every round → same GNN output but B is 2nd node from A; D is 4th — different global positions With PE: B ≠ D (unique identity) A B C D Fiedler vector on P₅: B gets +0.37, D gets −0.37 Now the model can separate them
Path graph A–B–C–D–E. Message passing gives B and D the same 1-WL colour at every round, so a GNN assigns them the same embedding. The Fiedler vector of \(P_5\) is \(u_2 \approx [0.602,\, 0.372,\, 0,\, -0.372,\, -0.602]\), which separates them — but note it does so only through the sign: \(\lvert u_2(B)\rvert = \lvert u_2(D)\rvert\). B and D are exchanged by the path-reversal automorphism, so any sign-invariant treatment of the eigenvector puts them back together. See the post on sign ambiguity.

Permutation Equivariance: A Double-Edged Sword

GNNs are designed to be permutation equivariant: the result of processing a graph should not depend on the arbitrary labelling of nodes. If you permute the node indices, the output node embeddings permute accordingly.

This is a desirable property — the graph has no canonical ordering, so the model should not depend on one.

But it has a sharp consequence. A message-passing GNN’s node representations are always a refinement of the 1-WL colouring: if 1-WL assigns two nodes the same colour after \(k\) rounds, no \(k\)-layer MPNN can give them different embeddings. Whatever 1-WL cannot see, message passing cannot see either.

Two distinct things get conflated here, and it is worth separating them:

  • Automorphic nodes. If some automorphism of the graph maps \(v\) to \(w\), then every permutation-equivariant function — GNN, Laplacian eigenvector, random-walk profile, anything computed from the graph alone — must assign them the same value. This is not a limitation of message passing; it is a theorem about equivariance, and no positional encoding escapes it.
  • 1-WL-equivalent but non-automorphic nodes. These are merely invisible to message passing. A positional encoding computed by other means can separate them, and this is the gap that graph PEs actually fill.

The Symmetric Node Problem

Consider a path graph: A — B — C — D — E

1-WL colours B and D identically at every round — from either node’s perspective the graph looks the same — so no MPNN of any depth separates them. And in this example they are genuinely automorphic (reverse the path), so this is the hard case: nothing equivariant will give them different values, and LapPE separates them only up to the eigenvector’s sign.

But B and D may still need different predictions. If A carries a feature that makes “the second node from A” meaningful, the model needs some way to break the tie — which in practice means either a task-specific anchor (distance from A, which is not permutation-invariant by design) or accepting sign information from the eigenvectors.

More extreme: in a regular graph with uniform initial node features, 1-WL never refines past a single colour, so all nodes get the same embedding for any depth. (With distinct input features, message passing can of course still tell nodes apart — the collapse is about what structure alone provides.)

Why Sequences Don’t Have This Problem

In a Transformer processing a sentence, position 3 is always “position 3” regardless of the token’s content. Positional encodings inject this absolute location.

In graphs, there is no canonical position 3. The graph has no start, no end, no linear order. This is why graph PEs must be derived from the graph structure itself.

What Positional Encodings Can Provide

A good graph PE \(p_v\) should:

  1. Separate as much as possible — ideally distinct values for nodes that are not automorphic (full uniqueness is unattainable, since automorphic nodes must tie)
  2. Vary continuously with structure — structurally similar nodes get similar encodings, so small perturbations of the graph do not scramble the representation
  3. Be computationally affordable — no dense \(O(N^3)\) eigendecomposition
  4. Be well defined — free of arbitrary choices (sign, basis, anchor selection) that differ between two runs on the same graph
  5. Be transferable — a PE computed on training graphs should carry the same meaning on test graphs

Points 1 and 2 pull against each other, and point 4 is exactly where Laplacian eigenvectors get into trouble.

Types of Graph Positional Information

TypeWhat it encodesExample
PositionalWhere the node is in the global graphLaplacian eigenvectors
StructuralWhat role the node plays locallyDegree, clustering coefficient, cycle membership
Distance-basedDistances to other nodesRandom walk landing probabilities

Positional and structural encodings are complementary — some tasks need absolute position, others need local role information.

Key Insight: Positional and structural encodings answer different questions. "Where is this node in the graph?" (positional — Laplacian eigenvectors) vs "What structural role does this node play?" (structural — RWPE, degree). For molecule property prediction, you usually want structural (is this atom in a ring?). For tracking specific atoms across a simulation, you want positional (which atom is this?). Use both when in doubt — GPS does exactly this.

Impact on Graph Transformers

For Graph Transformers (which lack the inductive structural bias of message passing), positional encodings are essential. Without them, the Transformer has no information about which nodes are connected — it processes a set of feature vectors with no graph structure at all.

With Laplacian eigenvector PEs: the model can compute attention scores that reflect graph distance. With random walk PEs: the model can identify structurally similar nodes. Graph PEs are to Graph Transformers what sinusoidal encodings are to sequence Transformers.

Summary

Without PEsWith PEs
1-WL-equivalent nodes are indistinguishableNodes get a structural fingerprint that message passing cannot derive
Regular graph + uniform features: all nodes identicalEigenvector and random-walk PEs separate many such nodes
Graph Transformer ignores structure entirelyStructure enters via node PEs and pairwise attention biases
Bounded by 1-WLCan exceed 1-WL — though automorphic nodes still tie, for any equivariant encoding

The next posts cover specific PE methods: Laplacian eigenvectors, random walk PEs, shortest-path encodings, and the challenges they introduce.

References