Transformers are Graph Neural Networks

Chaitanya K. Joshi
6/27/2025
cs.LGcs.AI

No official code found. Best implementation: chaitjo/gated-graph-transformers (55 stars, MIT, PyTorch, last commit 2020-12-27).

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.

View on arXivView PDF

Code Implementations(1)

PyTorchMIT

Transformers are Graph Neural Networks!

557Shell, PythonDec 14, 20205 years agoMIT
deep-learninggraph-neural-networksgraph-representation-learningpytorchtransformers

Similar Papers

Cite this paper

@article{joshi2025transformers,
  title  = {Transformers are Graph Neural Networks},
  author = {Chaitanya K. Joshi},
  year   = {2025},
  eprint = {2506.22084},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2506.22084v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2506.22084.svg)](https://codeofpaper.com/paper/2506.22084)

Discussion