R-GCN: Relational Graph Convolutional Networks

8 minute read

Published:

TL;DR: R-GCN (Schlichtkrull et al., 2018) adapts GCN for knowledge graphs with typed edges. Each relation \(r \in \mathcal{R}\) has its own weight matrix \(W_r\). A node aggregates messages from its neighbours separately per relation, then sums the results. The main challenge: \(\lvert\mathcal{R}\rvert\) full weight matrices per layer is far too many parameters. Solved by basis or block-diagonal decomposition.

The Problem: Multi-Relational Graphs

Key Insight: Imagine reading all your email with the same filter — work requests, spam, and love letters all treated identically. R-GCN gives the GNN a separate "filter" (weight matrix \(W_r\)) for each relation type. Messages arriving via "member_of" edges are transformed differently from those via "born_in" edges, so the aggregated embedding knows what kind of information came from where.

A knowledge graph (KG) is a directed multigraph where edges have types (relations). For example, Freebase contains entities (John_Lennon, Beatles, UK) connected by relations (member_of, born_in, from_country).

Standard GCN cannot handle this — it uses a single aggregation weight and cannot distinguish “member_of” from “born_in” edges.

The R-GCN Update Rule

\[ h_v^{(k+1)} \;=\; \sigma\!\left( W_0^{(k)} h_v^{(k)} \;+\; \sum_{r \in \mathcal{R}} \; \sum_{u \in \mathcal{N}_r(v)} \frac{1}{c_{v,r}}\, W_r^{(k)} h_u^{(k)} \right) \]

Where:

  • \(\mathcal{N}_r(v)\) — the neighbours of \(v\) connected via relation \(r\)
  • \(c_{v,r}\) — a normalisation constant, problem-specific but typically \(\lvert \mathcal{N}_r(v)\rvert\), so each relation’s contribution is a mean rather than a sum
  • \(W_0^{(k)}\) — the self-loop weight, applied to the node’s own representation
  • \(W_r^{(k)}\) — the relation-specific weight matrix, one per relation per layer

Interpretation: for each relation \(r\), node \(v\) collects messages from all neighbours connected by \(r\), transforms them by \(W_r\), and averages. The per-relation results are then summed and added to the self-loop term.

This is equivalent to running a separate GCN on each relation’s adjacency subgraph and summing the results — which is also the clearest way to see where the parameter cost comes from.

Directionality: Knowledge graphs are directed. R-GCN handles this by treating each directed relation \(r\) and its inverse \(r^{-1}\) as two separate members of \(\mathcal{R}\), with independent weight matrices. Writing \(r\) for "member of", the A–B edge creates a message from B to A using \(W_r\), and an inverse message from A to B using \(W_{r^{-1}}\). This lets information flow in both directions — and it doubles \(\lvert\mathcal{R}\rvert\), which is worth remembering when counting parameters below.

Worked Example: One R-GCN Update Step

Consider entity John Lennon with \(d = 3\) and \(h = [1, 0, 0]\), having two neighbours:

  • The Beatles via relation member of: \(h = [0, 1, 0]\)
  • UK via relation born in: \(h = [0, 0, 1]\)

Suppose, purely for illustration, that \(W_{\text{member}} = I\), \(W_{\text{born}} = 2I\), and the self-loop weight is \(W_0 = 0.5\,I\). Each node has one neighbour per relation, so \(c_{v,r} = 1\) throughout. Take \(\sigma\) to be the logistic sigmoid.

h_new = σ( W_0·h_JL + W_member·h_Beatles + W_born·h_UK )
      = σ( 0.5·[1,0,0] + 1·[0,1,0] + 2·[0,0,1] )
      = σ( [0.5, 1.0, 2.0] )
      ≈  [0.62, 0.73, 0.88]

The result reflects the band-membership signal (coordinate 2) and the nationality signal (coordinate 3, larger because \(W_{\text{born}}\) scales by 2) as separately identifiable contributions. A standard GCN, applying one shared \(W\) to both neighbours, would produce a sum in which the two are no longer distinguishable — that is precisely the information R-GCN recovers.

The Parameter Problem: Basis Decomposition

A separate \(W_r \in \mathbb{R}^{d \times d}\) per relation means the layer’s parameter count grows as \(\lvert\mathcal{R}\rvert d^2\). For a KG with \(\lvert\mathcal{R}\rvert = 100\) relations (200 once inverses are included) and \(d = 200\), that is \(100 \times 200 \times 200 = 4\) million parameters for a single layer.

The problem is not only the count. Relation frequencies in a knowledge graph are heavily long-tailed: a handful of relations account for most triples while many appear a few dozen times. Each rare relation still gets its own \(d^2\) free parameters, fit from almost no data, with no way to borrow strength from the common relations. Overfitting on the tail is the predictable result.

Basis decomposition (the R-GCN solution): express each \(W_r\) as a linear combination of \(B\) shared basis matrices:

\[ W_r^{(k)} \;=\; \sum_{b=1}^{B} a_{rb}^{(k)}\, V_b^{(k)} \]

The bases \(V_b \in \mathbb{R}^{d \times d}\) are shared across all relations; only the \(B\) coefficients \(a_{rb}\) are relation-specific. Parameters drop from \(\lvert\mathcal{R}\rvert d^2\) to \(B d^2 + \lvert\mathcal{R}\rvert B\), a large saving when \(B \ll \lvert\mathcal{R}\rvert\). The mechanism is weight sharing, so it also addresses the long tail directly: a rare relation only needs to learn \(B\) numbers, and it inherits structure the frequent relations paid for.

Block-diagonal decomposition (the alternative): constrain each \(W_r\) to be block-diagonal with \(B\) blocks of size \((d/B) \times (d/B)\):

\[ W_r^{(k)} \;=\; \bigoplus_{b=1}^{B} Q_{rb}^{(k)}, \qquad Q_{rb}^{(k)} \in \mathbb{R}^{(d/B) \times (d/B)} \]

This cuts parameters per relation from \(d^2\) to \(d^2/B\) without sharing anything between relations. Its inductive bias is different: it says the latent features come in groups, and a relation may only mix features within a group. Basis decomposition shares across relations; block decomposition sparsifies within each one.

R-GCN for Entity Classification

Task: given a KG with some labelled entities, predict labels for unlabelled entities.

Example: Freebase entity type classification — is this entity a Person, Organisation, or Location?

Setup:

  • Entity features: one-hot or learned embeddings
  • 2-layer R-GCN
  • Final \(h_v^{(K)}\) fed to a softmax classifier
  • Trained with cross-entropy on labelled entities

The R-GCN paper evaluates this on four RDF benchmarks — AIFB, MUTAG, BGS and AM (note that this MUTAG is the RDF entity-classification dataset, not the molecule graph-classification dataset of the same name). R-GCN is competitive with the feature-engineering and kernel baselines used there, such as WL kernels and RDF2Vec, winning on some of the four and not on others; it is a structural encoder rather than a uniformly better method.

Task: predict missing triples (subject, relation, object) — i.e., “does this relation exist between these two entities?”

Setup: R-GCN as an encoder, DistMult as a decoder.

  1. Encoder: run R-GCN to get entity embeddings \(e_s\) and \(e_o\)
  2. Decoder (DistMult): score the triple \((s, r, o)\) with a relation-specific diagonal matrix, i.e. a vector \(w_r \in \mathbb{R}^{d}\):
\[ f(s, r, o) \;=\; e_s^{\top}\, \mathrm{diag}(w_r)\, e_o \;=\; \sum_{i=1}^{d} \bigl(e_s\bigr)_i \bigl(w_r\bigr)_i \bigl(e_o\bigr)_i \]
  1. Training: binary cross-entropy with negative sampling

This encoder–decoder split (GNN encodes structure, shallow decoder scores triples) is a common pattern for KG link prediction. Note the decoder’s relation parameters \(w_r\) are separate from the encoder’s \(W_r\) — the model learns each relation twice, once as a message transform and once as a scoring vector.

R-GCN vs DistMult / TransE

Before R-GCN, KG link prediction used shallow embedding methods:

  • TransE: relations as translations, \(e_s + w_r \approx e_o\)
  • DistMult: the diagonal bilinear score above
  • ComplEx: the same trilinear form over complex-valued embeddings

These learn one vector per entity from the triples that entity appears in, but the vector itself is a free parameter — it is not a function of the neighbourhood. R-GCN changes that: an entity’s embedding is computed from the embeddings of its neighbours and the relations connecting them, so structure enters the representation rather than only the training signal.

Summary

PropertyR-GCN
Handles typed edgesYes — a separate \(W_r\) for each \(r \in \mathcal{R}\)
Handles typed nodesPartial — via features; no type-specific architecture
Parameters per layer\(\lvert\mathcal{R}\rvert d^2\) unconstrained; \(Bd^2 + \lvert\mathcal{R}\rvert B\) with basis decomposition; \(\lvert\mathcal{R}\rvert d^2/B\) with block decomposition
Scales to many relationsVia basis or block-diagonal decomposition
TasksEntity classification, link prediction
Key hyperparameterNumber of bases / blocks \(B\), tuned per dataset
LimitationNo attention — within a relation, all neighbours are weighted equally by \(1/c_{v,r}\)

R-GCN is the foundational model for applying GNNs to knowledge graphs. It introduced the relation-specific weight matrix pattern that nearly all subsequent heterogeneous GNN architectures inherit.

References