Relational Graph Convolutional Network (R-GCN)
An extension of GCN for multi-relational graphs (such as knowledge graphs) that uses a different weight for each relation type, with a weight decomposition to reduce parameters.
Overview
| Name | Relational Graph Convolutional Network |
|---|---|
| Year introduced | 2018 |
| Researchers | Michael Schlichtkrull, Thomas N. Kipf, Peter Bloem, Rianne van den Berg, Ivan Titov, Max Welling |
| Original paper | Modeling relational data with graph convolutional networks DOI arXiv |
| Data type | Graphs |
| Domains | Learning on graph data, Natural language processing |
Problem it solves
Knowledge graphs have different edge types (works-at, born-in...), and treating them as identical edges loses meaning.
Background and evolution
What came before: Graph Convolutional Network
- 2018
It was introduced at ESWC 2018 for entity classification and link prediction in knowledge graphs. [ref]
Core idea
Each relation $r$ has a weight matrix $W_r$, and the node gathers its neighbours' messages across each relation separately, with normalisation. To avoid an explosion of parameters as relations multiply, $W_r$ is written as a linear combination of a small number of basis matrices (basis decomposition).
Interactive diagram
A simplified illustrative diagram with the dimensions of a small example, not a drawing matching every detail of the original implementation. Click any layer to see its role, dimensions and mathematical operation.
Select a layer in the diagram.
Components
| Component | Role |
|---|---|
| Relation-specific weights | $W_r$ for each relation |
| Self-loop weight | $W_0$ |
| Normalization | $1/c_{i,r}$, such as the number of neighbours through r |
| Basis decomposition | $W_r=\sum_b a_{rb}V_b$ |
| Decoder | An entity classifier or DistMult for links |
Equations
1. R-GCN update
| $\mathcal{R}$ | Set of relations |
| $\mathcal{N}_i^r$ | Neighbours of i through relation r |
| $c_{i,r}$ | Normalisation constant |
2. Basis decomposition
| $V_b$ | Shared basis matrices |
| $a_{rb}$ | Relation-specific coefficients |
How it works, step by step
- Edges are classified by relation type.
- The messages of each relation are computed with its weight.
- They are normalised and summed with the self-loop.
- The activation is applied.
- The output is used for entity classification or link prediction.
Strengths and limitations
Strengths
- It represents relation types explicitly.
- Basis decomposition reduces parameters.
Limitations
- It still suffers from over-smoothing.
- Rare relations may not be learned well.
When to use it, and when not?
Good for
- Knowledge graphs and heterogeneous graphs.
Not suited for
- Graphs with a single edge type, where GCN is enough.
Applications
| Domain | Use |
|---|---|
| Natural language processing | Knowledge graph completion and entity linking. |
| Learning on graph data | Entity classification in multi-relational graphs. |
| Medical image analysis | Biomedical knowledge graphs (drugs, diseases, genes). |
PyTorch code
A simplified teaching code sample that runs on small synthetic data, covering: imports, model definition, data, forward pass, loss, optimizer, training loop, evaluation and inference. It is not the paper's full implementation.
# Relational GCN (R-GCN) with basis decomposition
# A simplified educational example in PyTorch (not the paper's full original implementation): small synthetic data,
# runs on the CPU in seconds. The numbers it prints belong to this example only.
# 1) Import the libraries
import torch
import torch.nn as nn
import torch.nn.functional as F
torch.manual_seed(0)
# 2) Define the model
class RGCNLayer(nn.Module):
def __init__(self, d_in, d_out, n_rel, n_basis=2):
super().__init__()
self.V = nn.Parameter(torch.randn(n_basis, d_in, d_out) * 0.1) # shared basis
self.a = nn.Parameter(torch.ones(n_rel, n_basis)) # relation coefficients
self.W0 = nn.Linear(d_in, d_out)
def forward(self, h, A_rel): # A_rel: R×N×N
W = torch.einsum('rb,bio->rio', self.a, self.V) # W_r = Σ a_rb V_b
out = self.W0(h)
for r in range(A_rel.shape[0]):
deg = A_rel[r].sum(1, keepdim=True).clamp(min=1) # c_{i,r}
out = out + (A_rel[r] @ (h @ W[r])) / deg
return out
class RGCN(nn.Module):
def __init__(self, d_in, n_rel, d=16, n_classes=3):
super().__init__()
self.l1, self.l2 = RGCNLayer(d_in, d, n_rel), RGCNLayer(d, n_classes, n_rel)
def forward(self, X, A_rel):
return self.l2(F.relu(self.l1(X, A_rel)), A_rel)
# 3) Prepare the data
# A synthetic graph from a stochastic block model (SBM): 3 communities, more links inside than between
N, C, D = 150, 3, 8
y = torch.arange(N) % C
P = torch.where(y[:, None] == y[None, :], 0.12, 0.01)
A = (torch.rand(N, N) < P).float().triu(1); A = A + A.T # a symmetric adjacency matrix without loops
X = torch.randn(N, D) + 0.6 * F.one_hot(y, D).float() # weak-signal features; the structure helps
idx = torch.randperm(N); train_idx, test_idx = idx[:45], idx[45:] # only 30% labelled (semi-supervised)
# Two relations (such as "follows" and "messages"): each edge's type is random, so node labels do not leak into the relation type
rtype = (torch.rand(N, N) < 0.5).float().triu(1); rtype = rtype + rtype.T
A_rel = torch.stack([A * rtype, A * (1 - rtype)])
model = RGCN(D, n_rel=2)
# 4) Loss function and optimizer
loss_fn = nn.CrossEntropyLoss()
opt = torch.optim.Adam(model.parameters(), lr=1e-2, weight_decay=5e-4)
# 5) Training loop (full-batch: the whole graph at each step, with the loss on the labelled nodes only)
for epoch in range(100):
model.train()
out = model(X, A_rel) # forward pass for all nodes
loss = loss_fn(out[train_idx], y[train_idx])
opt.zero_grad(); loss.backward(); opt.step()
if epoch % 25 == 0:
print(f"epoch {epoch:3d} loss={loss.item():.4f}")
# 6) Evaluation on the unlabelled nodes
model.eval()
with torch.no_grad():
pred = model(X, A_rel).argmax(1)
print(f"test accuracy = {(pred[test_idx] == y[test_idx]).float().mean().item():.3f}")
# 7) Inference: the class of node 0
print("node 0 predicted community:", pred[0].item(), " true:", y[0].item())
This code was run on 2026-11-20 in 3.1 seconds (PyTorch (CPU), Python 3 – local build machine).
Sample output:
test accuracy = 0.895
Trainable parameters in the example: model = 555.
These results are for small synthetic data and few epochs, and only prove that the code runs; do not compare them with published results.
Try it and go deeper
- Graph Network Explorer
- Graph Neural Networks Lab Another section of the site
Related architectures
Graph Convolutional Network
Graph Convolutional Network (GCN)
A simple graph layer that takes a normalised average of the representations of a node and its neighbours and then applies a shared linear transformation; it is a first-o…
Graph Attention Network
Graph Attention Network (GAT)
It replaces GCN's fixed weights with learned attention coefficients for each edge, so each node decides how important each neighbour is, with multiple attention heads.
Graph Transformer
Graph Transformer (GT)
Applying self-attention to the nodes of a graph with positional or structural encodings (such as Laplacian eigenvectors) so the model knows the graph's structure, going…
No results match the filters.
Research ideas
- Apply R-GCN to an Arabic medical knowledge graph to discover drug interactions.
Starting suggestions, not confirmed research gaps; review the recent literature before adopting them.
Test your understanding
What distinguishes R-GCN from GCN?
Why? Messages through each relation are transformed with that relation's own matrix.
Why is basis decomposition used?
Why? The parameters become shared through a few basis matrices.
On what kind of data is R-GCN usually used?
Why? It was designed for entity classification and link prediction in knowledge graphs.
References
Schlichtkrull, M., Kipf, T. N., Bloem, P., van den Berg, R., Titov, I., & Welling, M. (2018). Modeling relational data with graph convolutional networks. The Semantic Web (ESWC 2018), LNCS 10843, 593–607. https://doi.org/10.1007/978-3-319-93417-4_38
Kipf, T. N., & Welling, M. (2017). Semi-supervised classification with graph convolutional networks. International Conference on Learning Representations (ICLR). https://arxiv.org/abs/1609.02907
