A graph attention network (GAT) is a graph neural network that updates each node by aggregating its neighbors’ features with learned, data-dependent attention weights, so that more relevant neighbors contribute more to the new representation. In graph learning, GAT replaced the fixed, degree-based weights of the graph convolutional network with masked self-attention over the local neighborhood, which made node aggregation adaptive without requiring expensive spectral operations.
Introduced in 2018 by Veličković and colleagues, the architecture became a standard baseline in artificial intelligence research on graphs. It is used for node classification, link prediction and graph classification, and its attention mechanism inspired later graph transformers. GAT is a member of the broader message passing neural network family.
How graph attention computes neighbor weights
A GAT layer first applies a shared linear transformation W to every node feature vector. For each edge from neighbor j to node i, it then computes an unnormalized attention score by concatenating the two transformed vectors, multiplying by a learnable vector a and applying a LeakyReLU nonlinearity with a negative slope of 0.2.
The scores are normalized with a softmax over the neighborhood of node i, usually including a self-loop, so the weights of all neighbors sum to one. The new node representation is the attention-weighted sum of transformed neighbor features, followed by a nonlinearity such as ELU. Because attention is computed only along existing edges, the graph structure acts as a mask on the attention pattern.
| Component | Role | Learned |
|---|---|---|
| Linear projection W | Maps input features to a new space | Yes |
| Attention vector a | Scores each node pair | Yes |
| LeakyReLU | Adds nonlinearity to raw scores | No |
| Neighborhood softmax | Normalizes scores into weights | No |
| Weighted aggregation | Combines neighbor messages | No |
| Output activation | Applies ELU or similar function | No |
Multi-head attention and key hyperparameters
Like transformers, GAT uses multi-head attention to stabilize learning. K independent heads compute their own weights and outputs; in hidden layers the results are concatenated, while in the final prediction layer they are usually averaged. Typical settings use 4 to 8 heads with small hidden sizes per head.
| Hyperparameter | Common range | Effect |
|---|---|---|
| Number of layers | 2 to 3 | Receptive field of 2 to 3 hops |
| Attention heads | 4 to 8 | Stability and representational capacity |
| Hidden size per head | 8 to 64 | Feature capacity per head |
| Feature dropout | 0.4 to 0.6 | Regularization on small graphs |
| Attention dropout | 0.3 to 0.6 | Randomly removes neighbors per step |
| LeakyReLU slope | Around 0.2 | Shape of score nonlinearity |
Dropout on the attention coefficients is distinctive: each training step sees a randomly sparsified neighborhood, which acts as strong regularization on small citation benchmarks such as Cora, Citeseer and PubMed, where GAT was first evaluated.
How GAT compares with other graph neural networks
The main difference between GAT and the graph convolutional network lies in how neighbor weights are set. GCN uses fixed weights derived from node degrees, GraphSAGE uses a learned aggregator over sampled neighbors, and the graph isomorphism network uses sum aggregation to maximize expressive power under the Weisfeiler-Lehman test.
| Model | Neighbor weighting | Main strength |
|---|---|---|
| GCN | Fixed, normalized by degree | Simple and efficient |
| GAT | Learned attention per edge | Adaptive neighbor importance |
| GATv2 | Dynamic attention after nonlinearity | More expressive ranking |
| GraphSAGE | Learned aggregator on samples | Inductive scaling |
| GIN | Sum with learned MLP | Discriminates graph structures |
| Graph transformer | Attention over all nodes | Long-range dependencies |
A known theoretical limitation motivated GATv2. In the original formulation, the ranking of neighbors by attention score is the same for every query node, which is called static attention. GATv2 applies the nonlinearity before the attention vector, producing dynamic attention that can rank neighbors differently per node.
Practical use and computational cost
GAT is inductive: its parameters do not depend on a fixed graph, so a trained model can be applied to unseen nodes or entirely new graphs. This makes it suitable for protein interaction networks, recommendation graphs and fraud detection, where new entities appear constantly.
The cost of one layer is roughly linear in the number of edges times the number of heads, plus the feature projection for every node. Memory is often the bottleneck, because attention coefficients must be stored per edge and per head. Large graphs therefore rely on neighbor sampling or subgraph methods such as Cluster-GCN.
| Situation | Recommendation | Reason |
|---|---|---|
| Neighbors differ in relevance | Use GAT or GATv2 | Attention filters weak links |
| Very large, dense graph | Prefer GCN or sampled GraphSAGE | Lower memory per edge |
| Strong heterophily | Combine with ego and neighbor separation | Attention alone may not suffice |
| Need for interpretability | Inspect attention weights cautiously | Weights hint but do not explain |
Limitations and common misconceptions
Attention weights are frequently presented as explanations, but they are not a reliable measure of feature importance. Different weight patterns can produce similar predictions, and multi-head averaging blurs individual signals. Proper explanation requires dedicated attribution methods.
- Over-smoothing: stacking many GAT layers makes node representations converge, so depth beyond three layers rarely helps without residual connections.
- Over-squashing: information from distant nodes is compressed through narrow bottlenecks, which attention does not resolve.
- Heterophily: when connected nodes tend to have different labels, softmax aggregation can still mix in misleading neighbors.
- Edge features: the original GAT ignores edge attributes, so variants are needed for typed or weighted relations.
On many homophilous benchmarks, a well-tuned GCN performs within a small margin of GAT. The advantage of attention appears mostly when neighborhoods are noisy or heterogeneous in relevance.
Explained without jargon
Many kinds of data form networks. People follow each other, papers cite each other, and proteins interact. A graph attention network learns about each item by looking at its connections.
It does not treat every connection as equally useful. It learns which neighbors to listen to more. Imagine asking friends for a restaurant tip. You trust the friend who loves food more than the one who rarely eats out.
The network gives each neighbor a score, then mixes their information by those scores.
A typical use case
An online payments company wants to flag fraudulent accounts in a graph of about two million accounts linked by shared devices, cards and transfers. Many legitimate accounts share a device with hundreds of others, for example in an internet cafe, so plain averaging over neighbors adds noise.
The data team trains a two-layer GATv2 model with eight heads, using neighbor sampling to fit in GPU memory. The attention mechanism learns to give low weight to the crowded device hubs and higher weight to direct money transfers with recently flagged accounts.
Compared with a graph convolutional baseline, the model catches more fraudulent accounts at the same false-positive rate on a time-based test split. Analysts also review the highest-attention edges as leads for manual investigation, while treating them as hints rather than proof.