Abstract
Link prediction is a core challenge in graph machine learning, demanding models that capture rich and complex topological dependencies. While Graph Neural Networks (GNNs) are the standard solution, state-of-the-art pipelines often rely on explicit structural heuristics or memory-intensive node embeddings -- approaches that struggle to generalize or scale to massive graphs. Emerging Graph Transformers (GTs) offer a potential alternative but often incur significant overhead due to complex structural encodings, hindering their applications to large-scale link prediction. We challenge these sophisticated paradigms with PENCIL, an encoder-only plain Transformer that replaces hand-crafted priors with attention over sampled local subgraphs, retaining the scalability and hardware efficiency of standard Transformers. Through experimental and theoretical analysis, we show that PENCIL extracts richer structural signals than GNNs, implicitly generalizing a broad class of heuristics and subgraph-based expressivity. Empirically, PENCIL outperforms heuristic-informed GNNs and is far more parameter-efficient than ID-embedding--based alternatives, while remaining competitive across diverse benchmarks -- even without node features. Our results challenge the prevailing reliance on complex engineering techniques, demonstrating that simple design choices are potentially sufficient to achieve the same capabilities.
Introduction
Link prediction—determining the likelihood of an edge between two nodes—is fundamental to graph ML, with applications ranging from social recommendations to bioinformatics. Traditional Message-Passing Neural Networks (MPNNs) often fail here because they are "node-centric"; they struggle to distinguish between node pairs with structurally similar neighborhoods. To overcome this, current state-of-the-art methods typically rely on two "hacks": explicit structural heuristics (e.g., Common Neighbors) or unique node ID embeddings.
However, these solutions introduce significant drawbacks. Heuristics are often task-specific and fail to generalize, while ID embeddings scale poorly, requiring massive memory and retraining for dynamic graphs. Even modern Graph Transformers frequently depend on expensive precomputed structural encodings. This paper introduces PENCIL (Plain ENCoder for Inferring Links), a BERT-style Transformer that achieves superior performance by attending over sampled local subgraphs without these complex dependencies.
Methodology: The PENCIL Framework
PENCIL utilizes a standard, encoder-only Transformer architecture. Its effectiveness stems from a novel Graph Encoding Scheme that transforms local graph topology into a format suitable for sequence-based attention.
The process involves three key steps:
- Local Sampling: For any candidate link $(u, v)$, PENCIL extracts a small local subgraph.
- Tokenization: Each node in the subgraph is treated as a token. Features include a relative one-hot identifier and the node's corresponding row in the subgraph's adjacency matrix.
- Multiplicative Residual: A dedicated branch injects one-hop connectivity directly into the hidden states, ensuring the model maintains structural awareness throughout deep attention layers.
The authors theoretically demonstrate that PENCIL is permutation invariant in distribution, ensuring consistent outputs regardless of node indexing within the sampled subgraph.
Key Insights and Empirical Performance
PENCIL demonstrates that "plain" Transformers can implicitly learn complex structural signals. Theoretical analysis shows that the attention mechanism can recover classical heuristics like the Katz Index or Common Neighbors directly from raw adjacency tokens.
Key results from the evaluation on OGB and Planetoid benchmarks include:
- Efficiency: PENCIL is remarkably parameter-efficient, using 22x to 146x fewer parameters than leading ID-embedding methods while achieving higher accuracy on datasets like
ogbl-ppa(79.54% Hit@100). - Convergence Speed: On
ogbl-citation2, PENCIL converges in just 0.5 epochs, significantly faster than the 20-100+ epochs required by standard GNNs. - Structural Sufficiency: PENCIL often outperforms competing models even when node features are removed, indicating that local topology is a dominant signal for link prediction.
- Scalability with Depth: Unlike MPNNs, which suffer from oversmoothing, PENCIL's performance improves with depth, leveraging attention to navigate subgraphs effectively.
Conclusion and Future Directions
PENCIL challenges the necessity of complex structural encodings and memory-intensive embeddings in link prediction. By treating subgraphs as sequences for a plain Transformer, it achieves state-of-the-art performance with unprecedented efficiency. Future work includes addressing the inference overhead of subgraph extraction through hybrid "two-tower" architectures and exploring self-supervised pre-training on massive graph corpora to further leverage the Transformer's capacity for structural learning.
Summary updated