HAN: Heterogeneous Graph Attention Networks
Published:

The Two-Level Attention Idea
HAN’s key insight: in a heterogeneous graph, not all neighbours are equally informative, and not all relationship types are equally relevant to the task. Two separate attention mechanisms handle these two sources of variability.
- Node-level attention: given a meta-path \(\Phi\), weight the importance of the different neighbours reachable via \(\Phi\)
- Semantic-level attention: weight the importance of the different meta-paths \(\Phi_1, \dots, \Phi_P\) for the overall prediction
The order matters and is not arbitrary: node-level attention runs first, producing one embedding per node per meta-path, and semantic-level attention then runs over those to fuse the meta-path views into a single embedding. The two levels operate on different objects — neighbours within a view, then views themselves.
Step 1: Meta-Path-Based Neighbour Projection
For each meta-path \(\Phi\), the heterogeneous graph induces a projected meta-path graph: a homogeneous graph in which an edge connects \(u\) to \(v\) whenever some path of type \(\Phi\) exists between them.
For example, in an academic network:
- APA (\(\text{Author} \to \text{Paper} \to \text{Author}\)): co-authorship graph
- APCPA (\(\text{Author} \to \text{Paper} \to \text{Conference} \to \text{Paper} \to \text{Author}\)): same-venue collaboration graph
Each meta-path gives a different view of the Author–Author relationships. Because these views are built by composing edges, they are typically far denser than the original graph — the APA neighbourhood of a prolific author can be very large — which is one source of HAN’s cost.
Before attention, project all node features to a common dimension (different node types may arrive with different feature dimensions):
Step 2: Node-Level Attention (Within Meta-Path)
For a given meta-path \(\Phi\), apply GAT-style attention over the meta-path neighbourhood \(\mathcal{N}^{\Phi}_i\).
Compute an unnormalised attention score between nodes \(i\) and \(j\):
Here \(a^{\Phi} \in \mathbb{R}^{2d'}\) is a meta-path-specific attention vector and \(\Vert\) denotes concatenation. Crucially \(a^{\Phi}\) is not shared between meta-paths: what makes a neighbour important along a co-authorship path is a different question from what makes one important along a same-venue path.
Normalise over the meta-path neighbourhood with a softmax:
Aggregate:
\(z^{\Phi}_i\) is node \(i\)’s embedding under meta-path \(\Phi\). With multi-head attention, run \(K\) independent heads and concatenate them:
Step 3: Semantic-Level Attention (Across Meta-Paths)
After computing \(\{z^{\Phi_1}_i, \dots, z^{\Phi_P}_i\}\) for every node \(i\), we need to combine them, because each meta-path may contribute differently to the task.
Learn a meta-path importance score. Note it is shared across nodes: a meta-path’s relevance is treated as a global property of the task, so the score is averaged over all nodes before the softmax rather than computed per node.
Normalise across the \(P\) meta-paths:
Final embedding — the same \(P\) weights applied to every node:
This is the design decision that distinguishes the two levels. Node-level attention is per node: node \(i\) decides which of its own neighbours matter. Semantic-level attention is per graph: one set of \(P\) weights, learned from the whole node set, decides which relationships matter for the task. The consequence is a limitation as well as a simplification — HAN cannot let one author be better explained by co-authorship while another is better explained by venue.
Full HAN Pipeline
Input: Heterogeneous graph G with multiple node/edge types
Pre-defined meta-paths {Φ₁, ..., Φ_P}
For each meta-path Φ_p:
1. Project node features to common space
2. Construct meta-path graph (who is connected via Φ_p?)
3. Apply node-level GAT attention → z^{Φ_p}_i for each node
Semantic-level attention:
4. Compute meta-path importance β^{Φ_p}
5. Weighted combination: h_i = Σ_p β^{Φ_p} z^{Φ_p}_i
Classifier:
6. MLP(h_i) → ŷ_i
Worked Example: Semantic Attention Weights
Suppose we have two meta-paths for author classification:
- APA (\(\text{Author} \to \text{Paper} \to \text{Author}\)): co-authorship
- APCPA (\(\text{Author} \to \text{Paper} \to \text{Conference} \to \text{Paper} \to \text{Author}\)): same-venue collaboration
After node-level attention, author \(i\) has two embeddings, \(z^{\mathrm{APA}}_i\) and \(z^{\mathrm{APCPA}}_i\).
Semantic attention computes the two importance scores, each averaged over all authors:
w_APA = (1/|V|) Σ_i qᵀ · tanh(W · z^APA_i + b) → suppose w_APA = 0.8
w_APCPA = (1/|V|) Σ_i qᵀ · tanh(W · z^APCPA_i + b) → suppose w_APCPA = 0.3
After softmax normalisation over the two meta-paths:
\(\beta_{\mathrm{APA}} = \dfrac{e^{0.8}}{e^{0.8} + e^{0.3}} \approx \dfrac{2.23}{2.23 + 1.35} \approx 0.62\), and \(\beta_{\mathrm{APCPA}} \approx \dfrac{1.35}{3.58} \approx 0.38\).
Final embedding: \(h_i = 0.62\, z^{\mathrm{APA}}_i + 0.38\, z^{\mathrm{APCPA}}_i\) — the same two weights for every author in the graph.
The model has learned that co-authorship carries more weight than shared venue for research area prediction, and it learned it from the labels alone rather than from a hand-set weighting. Read the ratio with care, though: \(\beta\) weights are relative to the meta-path set you chose and to the scale of the \(z^{\Phi}\) vectors, so they rank the views you supplied — they are not a calibrated measure of how informative each relationship is in absolute terms.
Limitations
Manual meta-path definition: domain knowledge required to define meaningful meta-paths. Wrong meta-paths → poor performance.
Combinatorial explosion: for complex HINs with many relation types, the number of meaningful meta-paths grows combinatorially.
Node-type coverage: HAN focuses on target node type; other node types are only intermediaries in meta-paths.
Scalability: constructing meta-path graphs and running multiple GATs is expensive for large graphs.
Later architectures (HGT: Heterogeneous Graph Transformer) address these by learning relation-specific attention without explicit meta-path definition.
Summary
| Component | What it learns | Scope |
|---|---|---|
| Node projection \(W_{\tau(v)}\) | Common embedding space across types | Per node type |
| Node-level attention \(\alpha^{\Phi}_{ij}\) | Which neighbours matter | Per node, per meta-path |
| Semantic attention \(\beta^{\Phi_p}\) | Which meta-paths matter | Per graph (shared by all nodes) |
| Multi-head node attention | Multiple perspectives within a meta-path | Per node, per meta-path |
HAN applies attention at two levels to heterogeneous graphs, making the point that which relation is as much a learnable question as which neighbour in complex multi-relational data.
References
- Wang, X., Ji, H., Shi, C., Wang, B., Ye, Y., Cui, P., & Yu, P. S. (2019). Heterogeneous Graph Attention Network. WWW 2019.
- Veličković, P., Cucurull, G., Casanova, A., Romero, A., Liò, P., & Bengio, Y. (2018). Graph Attention Networks. ICLR 2018 (base GAT that HAN extends).
- Hu, Z., Dong, Y., Wang, K., & Sun, Y. (2020). Heterogeneous Graph Transformer. WWW 2020 (successor to HAN without explicit meta-paths).
