Graph attention network

Also known as: GAT

On this page 7

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.

ComponentRoleLearned
Linear projection WMaps input features to a new spaceYes
Attention vector aScores each node pairYes
LeakyReLUAdds nonlinearity to raw scoresNo
Neighborhood softmaxNormalizes scores into weightsNo
Weighted aggregationCombines neighbor messagesNo
Output activationApplies ELU or similar functionNo
Components of a single GAT layer

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.

HyperparameterCommon rangeEffect
Number of layers2 to 3Receptive field of 2 to 3 hops
Attention heads4 to 8Stability and representational capacity
Hidden size per head8 to 64Feature capacity per head
Feature dropout0.4 to 0.6Regularization on small graphs
Attention dropout0.3 to 0.6Randomly removes neighbors per step
LeakyReLU slopeAround 0.2Shape of score nonlinearity
Typical hyperparameter ranges

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.

ModelNeighbor weightingMain strength
GCNFixed, normalized by degreeSimple and efficient
GATLearned attention per edgeAdaptive neighbor importance
GATv2Dynamic attention after nonlinearityMore expressive ranking
GraphSAGELearned aggregator on samplesInductive scaling
GINSum with learned MLPDiscriminates graph structures
Graph transformerAttention over all nodesLong-range dependencies
GAT and related architectures

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.

SituationRecommendationReason
Neighbors differ in relevanceUse GAT or GATv2Attention filters weak links
Very large, dense graphPrefer GCN or sampled GraphSAGELower memory per edge
Strong heterophilyCombine with ego and neighbor separationAttention alone may not suffice
Need for interpretabilityInspect attention weights cautiouslyWeights hint but do not explain
When to choose GAT

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.