The Graph Convolutional Network (GCN)'s flat average treats every neighbor as equally important — a node with one quiet neighbor and one wildly different one gets pulled toward their plain mean regardless. Real relationships aren't equal. What if the aggregation rule itself could decide who to listen to?
Click a node. Every edge in its neighborhood gets its own thickness now — that's an attention weight, not a fixed share. Node 3's neighbors don't all matter the same amount to it, and the graph now shows exactly how much each one does.
A Graph Attention Network (GAT) layer replaces GCN's fixed mean with a learned, per-neighbor weight. For node and each member of its neighborhood (itself included):
- — the raw, unnormalized attention score between node and neighbor .
- — the normalized attention weight node assigns to neighbor , after softmax.
- — a learned weight matrix applied to every node's features before scoring.
- — a learned attention vector that scores how compatible two transformed features are.
- , — node 's and neighbor 's current feature vectors.
- — node 's updated feature: the attention-weighted sum over itself and its neighbors.
- — node 's neighborhood, including itself.
- W and a score compatibility, like query-key attention
is a learned weight matrix and a learned attention vector — together they score how compatible and are, exactly the way a query and key score compatibility in Part IV's attention chapter.
- This chapter's simplification
With one scalar feature per node and fixed to the identity, that score collapses to a straight comparison of the two raw features. This chapter fixes it at .
- LeakyReLU lets asymmetric signal through
A neighbor with a much larger feature scores far higher, one with a much smaller feature is only mildly suppressed — LeakyReLU's whole point is to leak a little of that signal through instead of zeroing it, the same nonlinearity from Part III.
Every bar is one node's GAT update minus what GCN's plain mean would have produced, on the exact same starting graph. None of them are zero — attention never reduces to a flat average unless every neighbor already agrees. Node 4's bar is the tallest: it's a leaf with exactly one neighbor, so there's no averaging-out effect to soften how hard that neighbor's much larger feature pulls the update.
Node (feature ), attending to itself and its three neighbors — node (feature ), node (feature ), node (feature ):
- Raw scores
Node 's score is the only one that grows past its raw gap — every negative score gets shrunk to a fifth of its size.
- Softmax turns those into weights
Subtracting the max score () for stability, then exponentiating:
- (self)
- (node )
- (node )
- (node )
Sum . Normalizing:
Node alone gets more than half the attention, despite being just one of three neighbors.
- The weighted sum lands far from a plain average
. GCN's flat mean of the same four numbers is exactly — attention pulls node 's update a full higher, entirely because node dominates the weighted sum instead of counting for a plain .
Click through the nodes and find the one whose GAT update diverges furthest from what GCN's flat average would give it.
GCN assumes every neighbor deserves an equal vote; GAT learns the votes instead, using the same query-key compatibility idea that made Part IV's attention mechanism work on sequences — just scored between a node and its graph neighbors instead of between sequence positions. Real GAT layers typically run several of these attention heads in parallel (exactly like multi-head attention) and stack a learned per layer; this chapter fixed both to keep every number checkable by hand. The next chapter wires message passing and attention together on a genuinely different kind of graph: a molecule, where the "neighbors" are chemical bonds and the thing being predicted is a property of the whole structure.