IntermediateGraph Neural Networks

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

NameRelational Graph Convolutional Network
Year introduced2018
ResearchersMichael Schlichtkrull, Thomas N. Kipf, Peter Bloem, Rianne van den Berg, Ivan Titov, Max Welling
Original paperModeling relational data with graph convolutional networks DOI arXiv
Data typeGraphs
DomainsLearning 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

  1. 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).

Example: In a knowledge graph about universities, the relations "teaches-at" and "graduated-from" carry different information about a person, so each gets a different transformation.

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

ComponentRole
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$
DecoderAn entity classifier or DistMult for links

Equations

1. R-GCN update

$$h_i^{(l+1)}=\sigma\!\left(W_0^{(l)}h_i^{(l)}+\sum_{r\in\mathcal{R}}\sum_{j\in\mathcal{N}_i^{r}}\frac{1}{c_{i,r}}W_r^{(l)}h_j^{(l)}\right)$$

Symbols
$\mathcal{R}$Set of relations
$\mathcal{N}_i^r$Neighbours of i through relation r
$c_{i,r}$Normalisation constant
Dimensions
$W_r\in\mathbb{R}^{d^{\prime}\times d}$
Numerical example
A node with two neighbours through r1 and one through r2: two messages are computed with $W_{r_1}$ (divided by 2) and one with $W_{r_2}$.
Relation to the architecture
It preserves the meaning of the relation type.

2. Basis decomposition

$$W_r^{(l)}=\sum_{b=1}^{B}a_{rb}^{(l)}V_b^{(l)}$$

Symbols
$V_b$Shared basis matrices
$a_{rb}$Relation-specific coefficients
Dimensions
Parameters: $Bd^{\prime}d+|\mathcal{R}|B$ instead of $|\mathcal{R}|d^{\prime}d$
Numerical example
100 relations, $d=d^{\prime}=64$, $B=4$: about $16.8$ thousand parameters instead of $409.6$ thousand.
Relation to the architecture
It makes the model applicable to graphs with hundreds of relations.

How it works, step by step

  1. Edges are classified by relation type.
  2. The messages of each relation are computed with its weight.
  3. They are normalised and summed with the self-loop.
  4. The activation is applied.
  5. 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

DomainUse
Natural language processingKnowledge graph completion and entity linking.
Learning on graph dataEntity classification in multi-relational graphs.
Medical image analysisBiomedical 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.

Python (PyTorch)
# 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

Related architectures

Basic2017

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 Neural Networks

Intermediate2018

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 Neural Networks

Advanced2020

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…

Graph Neural NetworksSpecialized ArchitecturesTransformer Architectures

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

  1. Concept

    What distinguishes R-GCN from GCN?

  2. Concept

    Why is basis decomposition used?

  3. Concept

    On what kind of data is R-GCN usually used?

References

  1. 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

    DOIarXivAutomatically verified via Crossref – 2026-11-20

  2. 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

    arXivAutomatically verified via OpenAlex/arXiv – 2026-11-20