Skip to main content

Relational Deep Learning: Learning from Relational Databases using GNNs

Relational Deep Learning (RDL) proposes a unified graph-based way to model multi-table databases for end-to-end learning using GNNs. This retains relational semantics, avoids joins, and supports temporal reasoning. It’s a paradigm shift that bridges the gap between ML and databases.


1. Motivation: From Tables to Graphs

Traditional Setup

Relational databases store structured data across multiple normalized tables, each capturing different types of entities (e.g., users, orders, products). These tables are linked by foreign-key (FK) and primary-key (PK) constraints.

To train machine learning models, these databases are typically flattened into a single table using joins, and domain experts manually select and engineer features.

Problems:

  • Joins are expensive and brittle (schema changes break pipelines).

  • Manual feature engineering is time-consuming and lacks relational awareness.

  • Loss of information about cross-entity relationships.


2. Core Idea: Learn Directly on the Schema

This paper proposes Relational Deep Learning (RDL) — a paradigm where:

  • The database is automatically transformed into a graph (called Relational Entity Graph).

  • A Graph Neural Network (GNN) learns over this graph end-to-end.

This means:

  • No need for manual joins or feature crafting.

  • You preserve multi-hop relationships (e.g., customer → transaction → product → vendor).

  • Dynamic predictions (e.g., churn, fraud) are enabled using temporal signals.


3. Relational Entity Graph (REG): The Foundation

How it's Built

Given a relational database:

  • Nodes = rows in tables (e.g., each customer, order, product is a node).

  • Edges = FK–PK links (e.g., order belongs to a customer).

This forms a heterogeneous graph:

  • Different node types: customers, products, transactions.

  • Different edge types: “purchased”, “reviewed”, etc.

Optional Additions

  • Node features: row attributes (e.g., age, price, date).

  • Timestamps: used for dynamic/temporal GNNs.

This graph retains relational and structural information that flat feature vectors would discard.


4. Deep Learning Pipeline

Relational Deep Learning solves predictive tasks on relational data with end-to-end learnable models. There are three main steps. (a) A database of relational tables is given. (b) A predictive task is specified and added to the database by introducing an additional training table. (c) relational data is transformed into its Relational Entity Graph, and a GNN trained on the training table. The task can be node level (as in this illustration), or link-level or higher-order.

Here’s how the full machine learning pipeline works:

(1) Task Definition

  • The user defines a training table with the target label(s).

  • This table typically links to the entities of interest (e.g., users for churn, transactions for fraud).

(2) Graph Construction

  • From the schema + keys, build the REG automatically.

(3) Feature Encoding

  • Convert raw database features into tensor representations:

    • Categorical → embeddings

    • Numeric → normalization

    • Timestamp → time-aware features

(4) Message Passing

  • Apply GNN layers (e.g., GraphSAGE, GAT) over the graph.

  • Each node updates its representation by aggregating messages from neighbors.

  • Enables multi-hop reasoning: a user's node learns from the behavior of purchased products, other users, etc.

(5) Prediction

  • Add MLP layers for classification/regression depending on the task.

  • Backpropagation updates all weights across message passing and embeddings.


5. Related Concepts AI Engineers Should Know

A. Relational Databases

  • Normalization: reduces redundancy; leads to many tables.

  • Foreign keys: links from one table to a related row in another.

  • Joins: SQL operations to combine data from multiple tables.

Ref:

B. Graph Neural Networks

  • Message-passing networks update each node's state by aggregating info from neighbors.

  • Key architectures:

    • GCN (Kipf & Welling): basic spectral approach

    • GraphSAGE: learns aggregators from neighborhood

    • GAT: uses attention over neighbors

Ref:

C. Temporal Graph Learning

  • Tasks where the time of interactions matters.

  • GNNs with time-aware components (e.g., TGAT, TGN) are used for:

    • Dynamic recommendation

    • Fraud detection

    • Churn prediction

Ref:


6. Benchmarks and Tools

The authors introduce RelBench, a benchmark suite of relational datasets + predictive tasks, including:

  • Stack Exchange QA threads

  • Amazon product reviews

  • Online retailers and clickstreams

They also provide:

  • Data conversion tools from SQL → REG graph

  • GNN training pipelines using PyTorch Geometric


References

Comments

Popular

Understanding SentencePiece: A Language-Independent Tokenizer for AI Engineers

In the realm of Natural Language Processing (NLP), tokenization plays a pivotal role in preparing text data for machine learning models. Traditional tokenization methods often rely on language-specific rules and pre-tokenized inputs, which can be limiting when dealing with diverse languages and scripts. Enter SentencePiece—a language-independent tokenizer and detokenizer designed to address these challenges and streamline the preprocessing pipeline for neural text processing systems. What is SentencePiece? SentencePiece is an open-source tokenizer and detokenizer developed by Google, tailored for neural-based text processing tasks such as Neural Machine Translation (NMT). Unlike conventional tokenizers that depend on whitespace and language-specific rules, SentencePiece treats the input text as a raw byte sequence, enabling it to process languages without explicit word boundaries, such as Japanese, Chinese, and Korean. This approach allows SentencePiece to train subword models di...

Mastering the Byte Pair Encoding (BPE) Tokenizer for NLP and LLMs

Byte Pair Encoding (BPE) is one of the most important and widely adopted subword tokenization algorithms in modern Natural Language Processing (NLP), especially in training Large Language Models (LLMs) like GPT. This guide provides a deep technical dive into how BPE works, compares it with other tokenizers like WordPiece and SentencePiece, and explains its practical implementation with Python code. This article is optimized for AI engineers building real-world models and systems. 1. What is Byte Pair Encoding? BPE was originally introduced as a data compression algorithm by Gage in 1994. It replaces the most frequent pair of bytes in a sequence with a single, unused byte. In 2015, Sennrich et al. adapted BPE for NLP to address the out-of-vocabulary (OOV) problem in neural machine translation. Instead of working with full words, BPE decomposes them into subword units that can be recombined to represent rare or unseen words. 2. Why Tokenization Matters in LLMs Tokenization is th...

Using Gemini API in LangChain: Step-by-Step Tutorial

What is LangChain and Why Use It? LangChain  is an open-source framework that simplifies the use of  Large Language Models (LLMs)  like OpenAI, Gemini (Google), and others by adding structure, tools, and memory to help build real-world applications such as chatbots, assistants, agents, or AI-enhanced software. Why Use LangChain for LLM Projects? Chainable Components : Easily build pipelines combining prompts, LLMs, tools, and memory. Multi-Model Support : Work with Gemini, OpenAI, Anthropic, Hugging Face, etc. Built-in Templates : Manage prompts more effectively. Supports Multi-Turn Chat : Manage complex interactions with memory and roles. Tool and API Integration : Let the model interact with external APIs or functions. Let's Walk Through the Code: Gemini + LangChain I will break the code into  4 main parts , each showcasing different features of LangChain and Gemini API. Part 1: Basic Gemini API Call Using LangChain import os from dotenv import load_dotenv load_dot...