GNNs Meet Sequence Models Along the Shortest-Path: an Expressive Method for Link Prediction

Francesco Ferrini, Veronica Lachi, Antonio Longa, Bruno Lepri, Andrea PasseriniNeurIPS 2026

TL;DR

Predicting whether two nodes in a network should be connected requires looking at the journey between them, not just the destinations. Standard Graph Neural Networks (GNNs) suffer from a major blind spot when nodes sit in symmetrical positions, often failing to tell close neighbors apart from distant strangers. This paper introduces SP4LP, a method that pairs GNNs with sequence models—reading the shortest path between two nodes like a sentence—to achieve state-of-the-art link prediction without breaking the computational bank.

What Problem Does This Paper Address?

Suppose you want to predict missing connections in a network—whether recommending friends, completing a knowledge graph, or discovering drug interactions. Standard GNNs tackle this by generating an embedding (a summary vector) for each node based on its local neighborhood, and then simply combining the embeddings of two target nodes to guess if a link exists between them.

Here’s the catch: graphs have symmetries. Two completely separate nodes can have identical local neighborhoods—a phenomenon called automorphism. Because a standard GNN summarizes nodes purely by their local surroundings, it assigns these symmetrical nodes the exact same representation.

Automorphic nodes fooling a standard GNN

Look at nodes $u$ and $u'$ in the figure above. Locally, their worlds look identical, so a standard GNN gives them identical embeddings. Consequently, the model thinks the pair $(v, u')$ and the pair $(v, u)$ are identical—completely missing the fact that $v$ and $u'$ share a neighbor just two steps away, while $v$ and $u$ are separated by the entire graph!

Existing fixes force an unpleasant choice: either extract and run a GNN on a custom subgraph for every single candidate link (expressive, but painfully slow), or rely on simple shortcuts like counting "common neighbors" (fast, but useless in sparse graphs where valid links often share zero neighbors).

Methods

The authors propose SP4LP (Shortest Path for Link Prediction), which operates under a "GNN-then-Structural-Features" paradigm. It bridges the gap between expressiveness and speed in three modular steps:

  1. Global Node Encoding (Standard): Run a standard GNN (like GCN, GAT, or GraphSAGE) once over the entire graph to generate context-rich embeddings for every node.
  2. Shortest-Path Extraction (Preprocessing): For any candidate node pair $(u, v)$, find the shortest path connecting them using Breadth-First Search (BFS). Crucially, this is done offline before training and cached, meaning zero graph-traversal overhead during training or inference. (In their implementation, the authors select the first shortest path returned by BFS; if two nodes are completely disconnected, it falls back to just the two endpoints).
  3. Sequential Path Modeling (Novel): Treat the GNN embeddings of the nodes along that shortest path as an ordered sequence, feeding them into a sequence model like an LSTM or Transformer. Finally, combine this path representation with the endpoint embeddings using a simple Multi-Layer Perceptron (MLP) to predict the link.
Figure 2: Overview of the SP4LP framework. First, a GNN is used to compute contextualized embeddings for all nodes in the graph. Then, for each target link, the shortest path connecting the two endpoints is extracted. The embeddings of the nodes along this path are passed to a sequence model (e.g., Transformer or LSTM) to compute a path-aware link representation.

Datasets

The authors evaluate SP4LP across seven standard real-world benchmarks:

  • Planetoid Citation Networks: Cora, Citeseer, and Pubmed.
  • Open Graph Benchmark (OGB): ogbl-citation2, ogbl-ppa (protein-protein associations), ogbl-collab (author collaborations), and ogbl-ddi (drug-drug interactions).

No new datasets are introduced, but the authors evaluate everything under the HeaRT protocol. Traditional link prediction benchmarks pit positive links against random, easy-to-spot fake links. HeaRT uses tailored, "hard" negative samples, creating a much tougher testbed that closely mimics real-world deployment.

Key Insights and Ideas

  • "Common neighbors" fail surprisingly often: Relying on overlapping neighbors is fragile in incomplete, real-world graphs. The authors point out that 46% to 67% of true test links in citation networks—and 52% in ogbl-collab—share zero common neighbors. Where neighbor-counting baselines go blind and revert to basic GNNs, shortest paths remain well-defined so long as the graph is connected.
  • Order matters: Treating a path as an ordered sequence (via LSTMs or Transformers) rather than an unordered bag of nodes allows the model to capture directional, step-by-step relational patterns. This makes SP4LP provably strictly more expressive than pure GNNs and leading common-neighbor methods.
  • Neither piece works alone: In ablation studies, feeding raw node features into a sequence model without a GNN, or feeding GNN embeddings plus just the numeric length of the shortest path (ignoring the intermediate nodes), both caused performance to plummet. You need both the local context (from message passing) and the intermediate stepping stones (from the sequence model).

Key Results

Under the rigorous HeaRT benchmark, SP4LP ranks 1st in Mean Reciprocal Rank (MRR) on six out of seven datasets (and 3rd on the seventh, ogbl-ppa):

  • Substantial MRR leaps: On Cora, SP4LP hits 28.84% MRR, a 57% relative improvement over the runner-up (GAE at 18.32%). On ogbl-collab, it reaches 9.46% MRR, a 24% gain over the second-best model, LPFormer (7.62%).
  • Memory and speed: Because GNN message passing happens once and paths are pre-cached, SP4LP scales gracefully. On ogbl-collab at a massive batch size of 65,536, SP4LP uses just 6.84 GB of GPU memory and runs in 4.29 seconds—avoiding the out-of-memory crashes that plague subgraph methods like SEAL and NCNC, while running orders of magnitude faster than positional-encoding models like PEG (>23 seconds).

Limitations and Future Work

  • Preprocessing overhead: Caching shortest paths adds an upfront step compared to purely end-to-end models. While amortized during training, scaling to massive, dynamic graphs may require approximations like truncated BFS or landmark-based distance methods.
  • Diminishing returns on ultra-dense graphs: On ogbl-ddi, the average shortest path length is roughly 2, and 99.96% of positive links already share common neighbors. Here, tracing a single path adds little beyond what local neighborhood methods already see (explaining why SP4LP wins on MRR, 15.00%, but trails pure GNNs on Hits@20, 47.96% vs. SAGE's 67.19%).
  • Single-path bottleneck: The current implementation picks just one shortest path per pair, potentially discarding rich evidence spread across multiple tied paths. Future work aims to aggregate multiple shortest paths and adapt the sequence encoder to heterogeneous graphs (networks with diverse node and edge types).

Summary updated

Abstract

Graph Neural Networks (GNNs) often fail to capture the link-specific structural patterns essential for accurate link prediction, since their node-centric message passing might overlook the subgraph structures connecting two nodes. Prior attempts to inject such structural context either suffer from high computational cost or rely on oversimplified heuristics (e.g., common neighbor counts) that cannot capture multi-hop dependencies. We propose SP4LP (Shortest Path for Link Prediction), a new framework that integrates GNN-based node encodings with sequence modeling over shortest paths. Specifically, SP4LP first computes node representations with a GNN, then extracts the shortest path between each candidate node pair and processes the sequence of node embeddings with a sequence model. This design allows SP4LP to efficiently capture expressive multi-hop relational patterns. Theoretically, we show that SP4LP is strictly more expressive than both standard message-passing GNNs and several leading structural feature methods, positioning it as a general and principled framework for link prediction in graphs. Empirically, SP4LP sets a new state of the art on many standard link prediction benchmarks.
BibTeX
@inproceedings{ferrini2026gnns,
  author = {Francesco Ferrini and Veronica Lachi and Antonio Longa and Bruno Lepri and Andrea Passerini},
  title = {{GNNs Meet Sequence Models Along the Shortest-Path: an Expressive Method for Link Prediction}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=asqTlVBye5},
}
Figure