ML Systems Lab Open interactive version →
Intermediate 45 min read GATGATv2attentionedge featuresheterophily

Graph Attention Networks

Attention coefficients, multi-head GAT, GATv2 dynamic attention, edge features, when attention wins

A citation network has 2708 papers. GCN weights all neighbor contributions equally by degree normalization — a paper cited by Nature and one cited by a predatory journal receive identical aggregation weights. The GCN has no mechanism to distinguish citation quality. For homophilic graphs where all neighbors are roughly equally informative, this is a reasonable prior. For graphs where neighbor relevance varies widely, it discards the most important signal.

Graph Attention Networks replace fixed aggregation weights with learned, data-dependent attention coefficients. For each edge (i, j), GAT computes an attention score from the features of both endpoints: α_{ij} = softmax(LeakyReLU(a^T [W h_i ‖ W h_j])). The aggregation becomes a weighted sum over neighbors, where each weight is proportional to how relevant that neighbor's features are. The Nature citation gets high attention weight; the predatory journal citation gets near zero.

The original GAT has a subtle flaw discovered by Brody et al. (2022): its attention is static. The computation e_{ij} = a^T · LeakyReLU(W₁h_i + W₂h_j) decomposes into independent source and target terms — the ranking of neighbor j is the same for every source node i. If neighbor A ranks above neighbor B for node i, it ranks above B for every other node in the graph. GATv2 fixes this by applying the nonlinearity after concatenating source and target features rather than before: e_{ij} = a^T · LeakyReLU(W · [h_i ‖ h_j]). Now the joint (i, j) representation enters the nonlinearity, making attention genuinely dynamic — different source nodes produce different neighbor rankings.

NOT this. "GAT always outperforms GCN." GAT adds attention parameters and significantly more compute. For homogeneous graphs where all neighbors are equally relevant — regular lattices, uniformly connected networks — the attention overhead produces near-uniform weights and doesn't pay off. Inspect the learned α_{ij} distribution before claiming attention is doing useful work: concentrated attention indicates genuine differential relevance; near-uniform attention indicates mean aggregation would work equally well at lower cost. Use GCN for uniform-weight problems, GAT when neighbor importance genuinely varies.

Key points

Takeaway

GATv2 fixes a subtle but consequential flaw in the original GAT: original GAT attention is static — the ranking of neighbors is the same for every source node because the nonlinearity is applied to linearly separable source and target terms. GATv2 applies the nonlinearity after concatenating source and target features, making attention dynamic — different source nodes produce different neighbor rankings. This matters whenever the relevance of a neighbor depends on the identity of the querying node, which is the common case in heterophilic graphs, heterogeneous graphs, and any setting where relationships are asymmetric.

Recap

Check your understanding

Q1. What is the static attention problem in the original GAT, and how does GATv2 solve it?

Q2. You are building a fraud detection GNN. The graph has legitimate users with many connections (hubs) and fraudsters with few connections. Why might mean aggregation fail, and how would GAT help?

Q3. Which two of the following statements about softmax normalization in GAT on high-degree hub nodes are TRUE? (Select two.)

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →