A graph neural network (GNN) is a class of neural networks that operates directly on graph-structured data, learning a vector representation for each node, edge or whole graph by repeatedly exchanging information between connected nodes. Where a convolutional network assumes a regular grid of pixels and a recurrent network assumes a sequence, a GNN assumes only that entities are linked by relationships of arbitrary shape.
GNNs are used wherever the connections carry as much meaning as the entities themselves: molecules as atoms and bonds, social platforms as users and follows, road networks, citation graphs, knowledge graphs and fraud rings. Their defining property is permutation invariance: the output does not depend on the arbitrary order in which nodes are listed.
How message passing works in a graph neural network
Most graph neural networks follow the message passing framework, in which each layer updates every node by combining its own state with information from its neighbors. A single layer has three steps: each neighbor produces a message, the messages are combined by an aggregation function, and an update function merges the result with the node’s previous representation.
The aggregation must be order independent, so typical choices are sum, mean or maximum, or an attention-weighted sum. Stacking k layers lets information travel k hops, so after three layers a node’s representation reflects its three-hop neighborhood. For graph-level tasks such as predicting a molecular property, a readout function pools all node vectors into one graph vector.
The table below lists the main components of a message passing layer and the role each one plays.
| Component | Role | Common choices |
|---|---|---|
| Message function | Transforms neighbor features into messages | Linear layer, small multilayer perceptron |
| Aggregation function | Combines messages without regard to order | Sum, mean, max, attention |
| Update function | Merges aggregate with the node state | Multilayer perceptron, gated recurrent unit |
| Readout function | Pools node vectors into a graph vector | Sum or mean pooling, hierarchical pooling |
| Edge features | Encode bond type, distance or relation | Embeddings added to messages |
Main GNN architectures
GNN architectures differ mainly in how they weight and aggregate neighbors. The choice affects expressive power, scalability and how well the model handles nodes with very different numbers of connections.
| Architecture | Aggregation idea | Typical strength |
|---|---|---|
| Graph convolutional network (GCN) | Degree-normalized mean of neighbors | Simple, fast semi-supervised node classification |
| GraphSAGE | Sampled neighbors with learnable aggregator | Large graphs and unseen nodes |
| Graph attention network (GAT) | Learned attention weights per neighbor | Neighbors of unequal importance |
| Graph isomorphism network (GIN) | Sum aggregation with a multilayer perceptron | High expressive power for graph classification |
| Relational GCN | Separate weights per edge type | Knowledge graphs with typed relations |
| Graph transformer | Attention over all nodes plus structural encodings | Long-range dependencies |
The Weisfeiler-Lehman test sets a known ceiling on standard message passing: such networks cannot distinguish graphs that this classical isomorphism heuristic also fails to separate. GIN reaches that ceiling, and higher-order or subgraph-based models are needed to go beyond it.
Tasks a GNN can solve
A graph neural network can make predictions at three levels of a graph: individual nodes, pairs of nodes or edges, and entire graphs. The same message passing backbone serves all three, and only the output head and the training objective change.
| Task level | Question answered | Example application |
|---|---|---|
| Node classification | What category does this node belong to | Flagging fraudulent accounts |
| Link prediction | Should an edge exist between two nodes | Product and friend recommendations |
| Graph classification | What property does the whole graph have | Predicting molecular toxicity |
| Graph regression | What continuous value does the graph have | Estimating binding energy |
| Graph generation | Which new graph satisfies a goal | Proposing candidate molecules |
Training can be transductive, where the whole graph including test nodes is visible during training, or inductive, where the model must generalize to new nodes or new graphs. Inductive settings are closer to production use and require architectures such as GraphSAGE that do not memorize node identities.
How GNNs compare with other neural network types
A GNN generalizes several familiar architectures by removing the assumption of fixed structure. An image can be viewed as a grid graph and a sentence as a chain graph, and a transformer’s self-attention behaves like message passing on a fully connected graph.
| Architecture | Assumed input structure | Neighborhood definition |
|---|---|---|
| Convolutional neural network | Regular grid | Fixed spatial window |
| Recurrent neural network | Ordered sequence | Previous time step |
| Transformer | Set of tokens with positions | All tokens through attention |
| Graph neural network | Arbitrary graph | Nodes linked by edges |
The practical difference is that a GNN uses explicit relational structure as an inductive bias. When the graph is meaningful, this bias improves sample efficiency; when the graph is noisy or arbitrary, it can mislead the model.
Limitations and practical pitfalls
The best-known limitation is over-smoothing: as layers are stacked, node representations converge toward one another and lose discriminative detail. For this reason most practical GNNs use only two to four layers, often with residual connections or normalization to delay the effect.
- Over-squashing: information from an exponentially growing neighborhood is compressed into a fixed-size vector, which weakens long-range signals.
- Scalability: full-graph training on billions of edges exceeds memory, so neighbor sampling or graph partitioning is required.
- Heterophily: when connected nodes tend to differ, simple averaging of neighbors can hurt accuracy.
- Leakage in link prediction: test edges left in the message passing graph inflate reported results.
The short version
Some data is best described as a web of connections: people who know each other, atoms held together by bonds, or stations linked by train lines. A graph neural network is a type of AI model built for connections.
It works by letting each point in the web listen to its neighbors a few times in a row. After several rounds, each point carries a summary of its surroundings, and the model uses those summaries to make predictions. Connections become part of what the model learns, not just the individual items.
Where it makes a difference
A payment processor wants to detect accounts that belong to coordinated fraud rings. Looking at each account alone, many fraudulent accounts appear normal: modest transaction amounts, ordinary login times and valid documents.
The data team builds a graph in which accounts, devices, cards and shipping addresses are nodes, and shared usage creates edges. A three-layer GraphSAGE model trained on confirmed fraud cases learns that accounts sharing devices and addresses with known fraudsters form suspicious clusters. Compared with the previous per-account gradient-boosting model, the GNN catches more fraud rings at the same false-positive rate, because it uses the relationships that fraudsters find hardest to hide.