ML Systems Lab Open interactive version →
Advanced 60 min read heterogeneous graphHANHGTmeta-pathknowledge graph

Heterogeneous Graph Neural Networks

Node/edge types, HAN, HGT, meta-paths, knowledge graphs, when to model heterogeneity

Pinterest has Pin, Board, User, and Image nodes connected by Save, Click, Follow, and Similarity edges. A homogeneous GNN that ignores node and edge types aggregates all neighbor types together — a "Click" edge and a "Purchase" edge contribute identically to the target node's embedding. But a user purchasing an item is a fundamentally different signal than a user clicking it. Treating them the same discards the relational semantics that distinguish high-intent from low-intent interactions — often the most commercially valuable signals in the graph.

Heterogeneous GNNs model type information explicitly. RGCN uses relation-specific weight matrices: one W_r per relation type. With 25 relation types and embedding dimension 256, that is 25 × 256² = 1.6 million parameters just for relation weights — and rare relation types with under 1,000 training edges have insufficient gradient to learn their full matrix. This is the overparameterization problem.

HGT (Heterogeneous Graph Transformer) solves this with shared weights and small relation-specific modifiers. Type-specific key/query/value projections handle the (src_type, edge_type, dst_type) triplet with parameter growth O(|A| × d²) plus O(|R| × d) for relation modifiers — substantially better than RGCN's O(|R| × d²). HGT learns which relation triplets are informative end-to-end without manual meta-path specification.

NOT this. "You can encode type information as a feature instead of modeling it architecturally." Adding a one-hot type embedding to node or edge features and using a homogeneous GNN is a reasonable baseline. It works when relation types are numerous and sparse (100+ types with few examples each) and when you need a fast baseline. It fails when edge types carry fundamentally different semantic meaning — a purchase deserves different aggregation weights than a click, not just a different input feature to the same aggregation function. Architectural heterogeneity is not advanced; ignoring it is a lossy choice that should be made deliberately, not by default.

Key points

Takeaway

Heterogeneous graphs are the production default, not the exception. The key architecture decision is RGCN (relation-specific full weight matrices, O(|R|×d²) parameter growth) vs HGT (relation-specific attention with shared weights, linear parameter growth). With 25+ relation types and d=256, RGCN's parameter count becomes infeasible for rare relation types that have insufficient training signal; HGT's shared weights with type-specific modifiers handle this gracefully. Basis decomposition is non-optional for RGCN at scale — reducing O(|R|×d²) to O(B×d²) + O(|R|×B) provides ~12× parameter reduction at d=256 with B=40.

Recap

Check your understanding

Q1. Which two of the following statements about RGCN vs HGT on a 10-node-type, 25-edge-type e-commerce graph are TRUE? (Select two.)

Q2. Meta-paths in HAN are defined manually. What is wrong with this, and how would you make meta-path selection data-driven?

Q3. In a knowledge graph with 1M entities and 500 relation types, how would you handle the scalability and rare-relation problems simultaneously?

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 →