Transformers are Graph Neural Networks
Chaitanya K. Joshi
TL;DR
The paper formalizes a deep connection between Transformer architectures and Graph Neural Networks (GNNs) by showing that self-attention on a fully connected token graph performs graph-like message passing. It draws explicit parallels between Transformers and Graph Attention Networks, and discusses how positional encodings can inject graph structure without hard constraints, motivating Graph Transformers. The main contributions include a precise equivalence between multi-head self-attention and GNN message passing, and an argument that Transformers’ hardware efficiency underpins their practical dominance for graph-structured data. The work highlights the significance of hardware-aware design in representation learning and suggests directions that blend local, graph-inspired inductive biases with global attention mechanisms.
Abstract
We establish connections between the Transformer architecture, originally introduced for natural language processing, and Graph Neural Networks (GNNs) for representation learning on graphs. We show how Transformers can be viewed as message passing GNNs operating on fully connected graphs of tokens, where the self-attention mechanism capture the relative importance of all tokens w.r.t. each-other, and positional encodings provide hints about sequential ordering or structure. Thus, Transformers are expressive set processing networks that learn relationships among input elements without being constrained by apriori graphs. Despite this mathematical connection to GNNs, Transformers are implemented via dense matrix operations that are significantly more efficient on modern hardware than sparse message passing. This leads to the perspective that Transformers are GNNs currently winning the hardware lottery.
