Graph Attention Networks (GAT)
A GCN weights every neighbor by a fixed rule based on degree; a GAT instead learns which neighbors matter more, computing a different attention weight for every edge based on what the two connected nodes actually contain.
Prerequisites: Graph Convolutional Networks (GCN), The Self-Attention Mechanism
A graph convolutional network weights a neighbor's contribution by a rule fixed in advance — one over the square root of the two nodes' degrees, computed purely from graph structure, with no regard for what those nodes actually contain. But two suppliers of a company might have identical degree and still matter very differently: one might be a critical single-source supplier of a key component, the other a replaceable commodity vendor. Degree alone can't distinguish them. A graph attention network instead learns how much weight each neighbor deserves, computed from the content of the two nodes' feature vectors, exactly the way self-attention lets one word learn how much to attend to another based on what they actually mean, not just their position in the sentence.
The analogy: a manager weighing advisors by relevance, not headcount
A portfolio manager consults several analysts before making a call. A GCN-style rule would weight every analyst's opinion by some fixed organizational fact, like how many other people report to them — irrelevant to whether their specific opinion is useful right now. A GAT-style manager instead judges, case by case, how relevant each analyst's specific input is to the specific decision at hand: the credit analyst's view matters enormously when the question is about default risk and much less when the question is about a rate-sensitivity trade. The weight given to each advisor is computed fresh for each decision, based on the content of what's being asked and what each advisor actually knows — not a fixed number set by the org chart.
The mechanism: a learned compatibility score per edge
For an edge between node and neighbor , a GAT first computes a raw, unnormalized attention score:
Here and are the current feature vectors of nodes and , is a shared learned weight matrix that transforms both into a common space, means concatenation — stitching the two transformed vectors together end to end into one longer vector, is a learned vector of weights that turns that concatenated vector into a single number, and LeakyReLU is a mild nonlinearity. In words: transform both nodes' features, glue the two transformed vectors together, and pass the result through one small learned scoring function to get a single number saying "how relevant is to right now." This score depends on the actual content of both nodes, unlike a GCN's purely structural degree weight.
These raw scores are then normalized with softmax across all of 's neighbors, so they sum to one and behave like proper weights:
In words: exponentiate every neighbor's raw score and divide by the sum across all neighbors, exactly the same softmax normalization used in ordinary self-attention. Finally, the node's update is the attention-weighted sum of its (transformed) neighbors:
which looks structurally identical to a GCN's update, with one crucial difference: is learned and content-dependent, not a fixed function of degree.
Worked example 1: computing one attention weight by hand
Simplify to a 1-dimensional feature per node, with (identity), so directly. Node has , neighbor has , neighbor has . Suppose the learned scoring function collapses (after concatenation and ) to for simplicity of the arithmetic. Then and .
Softmax: , , sum . So and . Despite both being direct neighbors with the same graph-structural role, node receives essentially all the attention weight because its content is far more compatible with 's — this couldn't happen in a GCN, where two neighbors of equal degree always get identical structural weight regardless of content.
Worked example 2: the update after weighting
Continuing the example, suppose and are the values being aggregated (same as above, ). The node's update is
The result, , sits almost exactly at 's value — node 's new representation has essentially adopted its most relevant neighbor's information and nearly ignored the other, a sharp, content-driven decision that a fixed degree-based rule could never make, since a GCN would have blended both neighbors according to structure alone, regardless of how relevant either one actually was.
A GAT replaces a GCN's fixed, structure-only edge weight with a learned, content-dependent one, computed the same way self-attention scores word relevance — by comparing the two connected nodes' features and normalizing with softmax across all of a node's neighbors.
What this means in practice
GATs are the right tool when a graph's edges are structurally identical but not equally important — every supplier link looks the same in the raw graph, but a single-source critical supplier should influence a company's risk score far more than a commodity vendor with ten alternatives, and only the actual features of the two connected nodes can reveal that difference. Multi-head attention (running several independent attention computations per edge and combining them, exactly as in transformer self-attention) is standard in GATs too, letting the model learn several different notions of "relevance" simultaneously — say, financial exposure and operational dependence as two separate attention heads.
A common mistake is assuming a GAT's learned weights are automatically more "correct" than a GCN's fixed ones, simply because they're learned. Learned attention weights are only as good as the training signal and the node features feeding them — with too little training data or uninformative features, a GAT's attention can end up noisy or nearly uniform anyway, losing the theoretical advantage while adding real computational cost (an attention score must be computed for every edge, not just looked up from degree). The extra flexibility is not free, and it isn't automatically better on every graph or every task.
Practice
- Two neighbors of node have identical degree but very different feature vectors. Explain, step by step, why a GCN would weight them identically while a GAT would not.
- If the learned scoring function were replaced with a constant (say, always outputting 1 regardless of ), what would the resulting attention weights reduce to, and how would the GAT then compare to an unweighted average?
- Why does GAT normalize attention scores per node (softmax over just that node's neighbors) rather than across the entire graph at once?
Practice in interviews
Further reading
- Velickovic et al., Graph Attention Networks (2018)