# Traversal-Invariant Positional Encoding for Serialized Graphs

*Krish Mody, Sridhar Radhakrishnan, Chandra N Sekharan*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/150855) · [OpenReview](https://openreview.net/forum?id=erlgJjFpeV) · [Open on the map](../papers.html#p150855)

Category: [Graphs, OOD Detection & Medical Imaging](../pcat/7.md) › [Graph Diffusion and Positional Encodings](../pgroup/301.md) · Type: new method · Keywords: graph positional encoding, traversal invariance, canonical cycle basis, serialized graphs, molecular property prediction

Areas: [Model Architectures & Sequence Modeling](../areas/architectures.md) › Dynamic and relational architectures › Graph Structural Encoding; [Graph Learning](../areas/graph-learning.md) › Graph Analysis Methods › Structural Encoding

## Summary
Tree+Cycle Positional Encoding provides a traversal-invariant encoding for serialized graphs, enabling graph-aware sequence models to be invariant to node ordering without architectural changes.

## Explained to a 5-year-old
Sometimes people draw pictures of things that are connected, like molecules or computer programs. To talk about them with computers, they write the picture as a list of pieces, like a story. Different people can write the same picture in different orders, making different lists. The researchers added special numbers to the list so that the computer can see that the lists belong to the same picture, no matter the order. This helps computers understand graphs without having to change how they work.

## Explained to a 5-year-old, longer
Imagine a puzzle where pieces are connected, like a molecule or a computer program. To solve the puzzle with a computer, you need to tell the computer which pieces are there and how they are linked. One way to do this is to write down the pieces in a line, like a sentence. If you walk around the puzzle in different ways, you might write the same pieces in a different order. This makes the computer think the puzzles are different, even though they are the same. The researchers noticed this problem and wanted a way to make the computer ignore the order. They looked at how trees can be written in a special way that stays the same no matter where you start. They also studied how cycles, like loops, appear in the puzzle. By adding extra information about which pieces belong to cycles, they created a new kind of label that stays the same no matter how you walk around the puzzle. This label can be added to the list of pieces without changing the computer’s usual way of working. As a result, the computer can now understand that two different lists actually describe the same puzzle, which is useful for tasks like predicting properties of molecules or analyzing computer code.

## For a technical reader
The paper addresses the issue that sequence models treat different traversals of a graph as distinct inputs, breaking invariance. It provides a theoretical foundation showing that tree-positional encoding works for acyclic graphs but fails for cyclic ones due to spanning-tree ambiguity. By augmenting with a cycle-membership encoding derived from a canonical cycle basis, the authors create a traversal-invariant anchor on cycle vertices. This Tree+Cycle Positional Encoding can be dropped into existing graph-aware serialization pipelines as a direct replacement for sinusoidal PE, requiring no architectural changes. Experiments on synthetic cycle-counting and ring-membership tasks, as well as molecular property benchmarks (BACE, BBBP), demonstrate that the approach matches or exceeds graph-native Transformers while preserving token-to-atom alignment for interpretability.

## Problem
Sequence Transformers treat different traversals of the same graph as distinct inputs, losing graph invariance. Many practical pipelines receive serialized graph inputs and cannot be redesigned to operate directly on graphs. This creates a need for a traversal-invariant positional encoding that can be used as a drop-in replacement in existing sequence models.

## Method
The approach theoretically characterizes tree-positional encoding for acyclic graphs and augments it with cycle-membership encoding derived from a canonical cycle basis, creating a traversal-invariant anchor on cycle vertices. This Tree+Cycle Positional Encoding can replace sinusoidal positional encoding in graph-aware serialization pipelines without altering the sequence model architecture. It is computed from the graph structure and added to token embeddings, preserving token-to-atom alignment.

## Results
The approach achieves 2× improvement over GIN on synthetic cycle counting, matches GIN on ring membership, reaches 0.977 ± 0.029 mean cosine similarity across re-rootings on molecular property prediction, and outperforms Graphormer on BACE and BBBP with +5 points on alert alignment.

## Contributions
The paper provides a theoretical analysis of traversal invariance for serialized graphs, introduces a cycle-membership encoding that anchors cycle vertices, and demonstrates that the resulting encoding can replace sinusoidal PE in existing pipelines while achieving competitive performance on graph tasks.

## Limitations and assumptions
The method assumes that the serialized input preserves token-to-atom alignment for structural tokens, restricting its applicability to pipelines that maintain this alignment.

## Practical relevance
It enables existing sequence models to handle graph data invariantly, facilitating deployment in molecular property prediction and program analysis without redesign.

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/150855)
