- Introduced by
- Veličković, P. et al.
- Year
- 2018
- Type
- Graph neural network (attention-based)
What does it do?
The Graph Attention Network (GAT), introduced by Veličković and colleagues in 2018, is a graph neural network that learns how much each neighbouring node should contribute to a node's updated representation, using a self-attention mechanism.
The attention scores are computed from the features of the two connected nodes, not from the graph layout alone. The original paper reports results competitive with or better than graph convolutional networks (GCN) on its node-classification benchmarks, but the size and direction of any gain depend on the benchmark and task.
The intuition behind the method
A node in a graph is described by its own features and by its neighbours. In a simple neighbourhood average, every neighbour counts equally. GAT instead scores each neighbour relative to the node being updated, so the node can draw more from neighbours it judges informative for the task and less from the rest. These scores are learned during training rather than fixed by the shape of the graph.
History
Graph Attention Networks were introduced by Veličković and colleagues at ICLR 2018, with evaluation on node-classification benchmarks including Cora, Citeseer and Pubmed (transductive) and PPI (inductive). They added self-attention to graph neural networks so that the weight of each neighbour is learned rather than determined by the graph structure alone. Brody and colleagues' 2022 paper, How Attentive are Graph Attention Networks?, showed that standard GAT computes static attention, in which the ranking of neighbours does not depend on the query node, and proposed GATv2, which applies the nonlinearity after the transformation of the concatenated features so that attention can be dynamic.
When to use it
Choose GAT when your problem is naturally a graph: each node has a feature vector, connections between nodes are known and meaningful, and you have a supervised target such as node labels. The original GAT works on node features and graph adjacency only; it does not natively use edge features, so it is not the direct choice when edge attributes carry the main signal. It suits settings where neighbours differ in relevance and you want the model to learn those differences rather than fix them by hand. It has been applied in both transductive settings (a single fixed graph, with unlabelled nodes present during training) and inductive settings (prediction on graphs unseen during training). Do not use GAT when there is no meaningful graph, when node features have not been computed, or when labelled data are too scarce for the attention weights to be estimated reliably; in those cases simpler models, including classical machine-learning methods on tabular features, are usually easier to justify. Training is typically done on a GPU.
Limitations and considerations
- The original GAT operates on node features and graph adjacency only; edge attributes or edge types do not enter the formula, so any information carried by edges must be encoded in node features or handled by a different model.
- Attention is computed only over each node's neighbours, so a node with few connections has little neighbourhood from which to learn a meaningful weighting.
- The attention function adds parameters to estimate; with few labelled nodes these weights can be unstable and the model can overfit.
- Standard GAT computes static attention: Brody et al. (2022) show that the ranking of neighbours is the same for every query node, which limits expressiveness.
- Training is computationally heavier than fixed-weight graph convolution because attention scores must be computed for every edge at every layer, and a GPU is recommended.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Neighbour weights are learned from the features of both endpoints, so the relative importance of a connection can differ between nodes and between tasks.
- Softmax normalisation makes each node's attention weights sum to one over its neighbourhood, so the weights can be compared node by node.
- The original paper reports results competitive with or better than GCN on its benchmarks, and the attention weights can be inspected, although whether they constitute an explanation of a prediction is debated.
Applications
- Node classification on graph-structured data, where each node has features and a label.
- Relational learning across connected entities.
- Graphs in which neighbours differ in relevance and a uniform, unweighted aggregation is considered too coarse.
- Tasks in which the relative importance of connections needs to be learned from data.
How it works
How it works
Each node's features are first multiplied by a shared weight matrix W. For each pair of connected nodes i and j, the transformed features are concatenated and passed through a single-layer scoring function, a learned weight vector a followed by a LeakyReLU nonlinearity, giving a raw score e_ij. Because the score depends on both endpoints, the same neighbour can receive different scores from different nodes. In the original formulation each node's neighbourhood includes the node itself (a self-loop).
Formula
e_{ij} = \operatorname{LeakyReLU}\!\left(\mathbf{a}^{\top}\,[\,W h_i \,\Vert\, W h_j\,]\right)For each node i, the raw scores over its neighbourhood are passed through a softmax across the neighbours j. Scores are computed only for existing edges (the softmax is masked by the graph structure). The resulting weights alpha_ij are positive and sum to one over the neighbours of i, so each one can be read as the share of node i's update that comes from that neighbour.
Formula
\alpha_{ij} = \operatorname{softmax}_j(e_{ij})Each node's new representation is the sum of its neighbours' transformed features, each multiplied by its attention weight, passed through a nonlinearity sigma. The formula shown is for one attention head. The original GAT uses K independent attention heads: in hidden layers their outputs are concatenated, and in the output layer they are averaged. A single-head implementation is therefore only one component of the original method. Stacking layers lets information travel beyond immediate neighbours.
Formula
h_i' = \sigma\!\left(\sum_{j \in \mathcal{N}_i} \alpha_{ij} W h_j\right)Common pitfalls
- Computing node features differently at training and prediction time, since the attention scores are calculated directly from them.
- Reading the attention weights as evidence of causal importance or as a faithful explanation. They are learned scores that fit the training objective; a high weight does not by itself show that a neighbour caused or drove an outcome.
- Applying the model to a graph whose edges do not carry task-relevant information, so the attention mechanism learns to weight noise.
- Assuming the gains reported over GCN will transfer to a new dataset; the comparison depends on the benchmark and should be re-checked on the target data.
- Omitting self-loops or applying the softmax over all nodes rather than only over each node's neighbours, which departs from the original formulation.
- Mixing up transductive and inductive evaluation, so that results from one setting are assumed to hold in the other.
Frequently asked questions
How is GAT different from a graph convolutional network (GCN)?
A GCN combines a node's neighbours using weights derived from the graph's connectivity, so the weighting is fixed by the structure. GAT computes its weights from the node features with a learned attention function and normalises them over each neighbourhood, so the weighting is learned for the task.
How much data does GAT need?
There is no firm minimum. The main risk is that with few labelled nodes the learned attention weights are poorly estimated and the model overfits. In that situation a simpler model is often the more defensible choice.
Do I need a GPU to use GAT?
A GPU is recommended. Attention scores are computed for every edge at every layer, which is computationally demanding, and a GPU makes training on larger graphs practical.
What do I need before applying GAT?
You need an existing graph structure with meaningful connections and node features that have already been computed, since the attention mechanism operates on the features of connected nodes.
What is GATv2?
GATv2 is a modification proposed by Brody et al. (2022). Standard GAT yields static attention, with the same neighbour ranking for every query node. GATv2 changes the order of operations in the scoring function so that attention can depend on the query node.
Related methods
Sources
Veličković, P. et al. (2018). Graph Attention Networks. ICLR.
Open publication referenceBrody, S. et al. (2022). How Attentive are Graph Attention Networks? ICLR.
Open publication reference