Skip to main content

RDBLearn 🚀

Relational Database Learning with Foundation Models.


📑 Table of Contents


🎯 Introduction

RDBLearn is a framework designed to apply single-table foundation models to multi-table relational database tasks. It automates the process of flattening relational data into a single feature-rich table using Deep Feature Synthesis (DFS) and then leverages powerful single-table estimators (like TabPFN) for prediction.

Core Components

  • 🔧 FastDFS - Efficient Deep Feature Synthesis for automated multi-table flattening.
  • 🤖 RDBLearn Estimators - Scikit-learn compatible RDBLearnClassifier and RDBLearnRegressor that integrate DFS and single-table models.
  • Foundation Models - Seamless integration with TabPFN and other foundation models for single table prediction tasks.

⚙️ Installation

Requires Python 3.12.

pip install rdblearn

This installs fastdfs and other PyPI dependencies. For flash-attn (CUDA / LimiX-style GPU workloads), install separately — PyPI packages cannot declare direct URL dependencies:

pip install -r requirements-gpu.txt

Or install from source:

git clone https://github.com/HKUSHXLab/rdblearn.git
cd rdblearn
git checkout v1.1
pip install -e .
# optional GPU wheel:
pip install -r requirements-gpu.txt

🚀 Usage

Basic Example (RelBench rel-avito)

RDBLearn includes two features enabled by default that improve prediction quality:

  • Target History Augmentation (enable_target_augmentation): Injects the full training data (X and y) as a history table into the RDB before downsampling, allowing DFS to derive entity-level aggregate features from historical target values (e.g., mean past CTR per ad). Temporal cutoffs are respected to prevent data leakage. Requires cutoff_time_column to be provided.
  • Temporal Difference Features (temporal_diff): Converts absolute epoch-time columns produced by DFS into relative temporal differences from the cutoff time (i.e., cutoff_time - epochtime), so the model sees how recently events occurred rather than raw timestamps.
from rdblearn.datasets import RDBDataset
from rdblearn.estimator import RDBLearnRegressor
from tabpfn import TabPFNRegressor

# 1. Load RelBench dataset and task
dataset = RDBDataset.from_relbench("rel-avito")
task = dataset.tasks["ad-ctr"]

# 2. Initialize the estimator with a base model (e.g., TabPFN)
#    Both enable_target_augmentation and temporal_diff are enabled by default.
reg = RDBLearnRegressor(
    base_estimator=TabPFNRegressor(device="cpu"), # or "cuda"
    config={
        "dfs": {"max_depth": 2},
        "enable_target_augmentation": True,
        "temporal_diff": {"enabled": True},
        "max_train_samples": 1000
    }
)

# 3. Fit on relational data
X_train = task.train_df.drop(columns=[task.metadata.target_col])
y_train = task.train_df[task.metadata.target_col]

reg.fit(
    X=X_train,
    y=y_train,
    rdb=dataset.rdb,
    key_mappings=task.metadata.key_mappings,
    cutoff_time_column=task.metadata.time_col
)

# 4. Predict
X_test = task.test_df.drop(columns=[task.metadata.target_col])
predictions = reg.predict(X=X_test)

See examples/ for more detailed usage.


Core API Reference

RDBDataset

The central class for managing relational data and task-specific tables.

  • from_relbench(dataset_name: str) -> RDBDataset: Load a dataset from the RelBench benchmark.
  • from_hf_salt(for_task: Optional[str] = None) -> RDBDataset: Load Hugging Face SALT with eight classification tasks. All task label columns are stripped from the shared RDB so DFS cannot leak labels across tasks; labels remain in each task's train_df / test_df.
  • from_4dbinfer(dataset_name: str) -> RDBDataset: Load a dataset from the 4DBInfer benchmark.
  • save(path: str): Save the RDB and all associated tasks to disk.
  • load(path: str) -> RDBDataset: Load a previously saved dataset from disk.

RDBLearnClassifier / RDBLearnRegressor

Scikit-learn compatible estimators for relational learning.

  • __init__(base_estimator, config: Optional[dict] = None):
    • base_estimator: A single-table estimator (e.g., TabPFNClassifier, AutoGluonClassifier).
    • config: Optional dictionary to override default DFS or sampling settings. Key options:
      • dfs: DFS configuration (e.g., {"max_depth": 2}).
      • max_train_samples (int, default 10000): Maximum training samples before downsampling.
      • stratified_sampling (bool, default False): Use stratified sampling for classification tasks.
      • enable_target_augmentation (bool, default True): Augment the RDB with the full training target history table, enabling DFS to derive entity-level target aggregate features (e.g., entity mean). Requires cutoff_time_column to be set during fit.
      • temporal_diff (dict or TemporalDiffConfig, default {"enabled": True}): Convert DFS-generated epoch-time columns into temporal difference features relative to the cutoff time. Supports enabled (bool) and exclude_columns (list of column names to skip).
      • predict_batch_size (int, default 5000): Batch size for prediction.
  • fit(X, y, rdb, key_mappings, cutoff_time_column=None, **kwargs):
    • X: Training features (DataFrame).
    • y: Training labels (Series).
    • rdb: The relational database context (fastdfs.RDB).
    • key_mappings: Dictionary mapping columns in X to table.primary_key in the RDB.
    • cutoff_time_column: Optional column name in X representing the time of the observation.
  • predict(X, rdb=None, **kwargs):
    • X: Test features.
    • rdb: Optional RDB context (uses the one from fit if not provided).
  • predict_proba(X, rdb=None, **kwargs): (Classifier only) Predict class probabilities.

Multiclass (>10 classes): For classification tasks with more than 10 training classes, RDBLearnClassifier automatically uses base-10-hierarchical inference: the label space is decomposed into decimal digit heads (each head has at most 10 classes, compatible with TabPFN), then digit probabilities are fused into a full (n_samples, C) matrix. No extra configuration is required. Tasks with C ≤ 10 use a single model on the original target.

TaskMetadata

Data structure containing task-specific information.

  • key_mappings: Dict[str, str]
  • target_col: str
  • time_col: Optional[str]
  • task_type: Optional[str]
  • evaluation_metric: Optional[str]

LimiX Integration

rdblearn.utils provides wrappers to adapt LimiX predictors into scikit-learn compatible estimators.

  • LimiXWrapperClassifier(predictor): Wrapper for classification tasks.

    • predictor: An initialized LimiXPredictor instance.
    • fit(X, y): Stores training data for in-context inference.
    • predict(X): Returns class labels.
    • predict_proba(X): Returns class probabilities.
  • LimiXWrapperRegressor(predictor): Wrapper for regression tasks.

    • predictor: An initialized LimiXPredictor instance.
    • fit(X, y): Stores training data.
    • predict(X): Returns predicted values.

Note: You must install LimiX separately and provide an initialized LimiXPredictor to these wrappers.


📜 License

This project is licensed under the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rdblearn-1.1.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rdblearn-1.1-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file rdblearn-1.1.tar.gz.

File metadata

  • Download URL: rdblearn-1.1.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rdblearn-1.1.tar.gz
Algorithm Hash digest
SHA256 249c3c91efb1de0b4cc09733f49dc8f457f30d48f72c38dbe71be97eeec1419a
MD5 29fc00c0948e39935031287b2b722256
BLAKE2b-256 41305352ef3fc0167bb9bf3bd0eb3470f58f5fe9587bac989ea254f8687a1181

See more details on using hashes here.

File details

Details for the file rdblearn-1.1-py3-none-any.whl.

File metadata

  • Download URL: rdblearn-1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rdblearn-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef9ec1c7553d7c1b2954c12acc91531de6821b26a0bb9511e4d9860146ed699a
MD5 81fd42b12a01a7156cb89ab965c58069
BLAKE2b-256 0161f462f745ed039998823cf1bf141cfd6ab08c723ea3012ee5f34ac47b62eb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1 This release

2 files

0.1.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page