Skip to main content

HF Models GitHub - License PyPI - Python Version PyPI - Package Version Docs

Relational Transformers: Prediction and Fine-Tuning over Related Data

This framework provides an easy method to run and train relational transformer models over user-provided embeddings. It can be used to make predictions from sets of related cells (quickstart), measure which parts of a context affect those predictions (ablation), fit lightweight task heads (training overview), or fine-tune a complete model (training overview). This supports binary and multiclass classification, regression, forecasting, multilabel ranking, and other prediction tasks over related data.

Unlike frameworks that start with raw text or tables, Relational Transformers starts with embeddings that you have already created. You choose how strings, numbers, timestamps, images, categories, and domain objects become vectors. The framework handles typed relations, batching, relational attention, training, evaluation, and model checkpoints. It never silently downloads an encoding model or couples your model to a particular database.

your data → your encoders → embeddings + relations → RelationalTransformer → predictions

Pretrained models, fitted task heads, and fine-tuned checkpoints can be shared through the Hugging Face Hub. Each model declares its required embedding space, input dimension, and relation vocabulary in its model card. You can use a model as published, fit a small head over its frozen cell states, or fine-tune the complete relational transformer for your own feature pipeline.

For the full documentation, see Relational Transformers Documentation.

Installation

We recommend Python 3.10+ and PyTorch 2.2+.

pip install -U relational-transformers sentence-transformers

See Installation in the docs for source and editable installs and the ONNX, Triton, documentation, and development extras.

Getting Started

See Quickstart in our documentation.

Relational Prediction Models

First load a pretrained Relational Transformer and the encoder your application uses for text-valued cells.

from sentence_transformers import SentenceTransformer
from relational_transformers import RelationalTransformer

text_encoder = SentenceTransformer("sentence-transformers/all-MiniLM-L12-v2")
model = RelationalTransformer()

Suppose your application needs to classify whether a GitHub issue is a bug. RT-J text cells have two separately encoded channels: the column and its value. Concatenate those two embeddings to build each model-ready cell vector. The masked target has a column embedding and a zero value channel.

import numpy as np

issue = {
    "title": "Database connections time out after 30 seconds",
    "body": "The pool stops returning connections after the service has been idle.",
    "latest_comment": "Restarting the process temporarily fixes it.",
}

def text_cell_vector(column, value):
    column_vector = text_encoder.encode(column)
    value_vector = text_encoder.encode(value)
    return np.concatenate([column_vector, value_vector])

def target_cell_vector(column):
    column_vector = text_encoder.encode(column)
    masked_value_vector = np.zeros(384, dtype=np.float32)
    return np.concatenate([column_vector, masked_value_vector])

bug_target_vector = target_cell_vector("is bug")
title_vector = text_cell_vector("title", issue["title"])
body_vector = text_cell_vector("body", issue["body"])
comment_vector = text_cell_vector("latest comment", issue["latest_comment"])

cell_vectors = np.stack([
    bug_target_vector,
    title_vector,
    body_vector,
    comment_vector,
])

probability = float(model.predict(cell_vectors, target=0))
print(f"P(issue is a bug) = {probability:.1%}")

And that's already it. RT-J receives only the [column_embedding, value_embedding] vectors; it never receives the issue dictionary or its strings. target=0 marks bug_target_vector as the masked prediction target. RelativeDB will construct this same model-ready representation from its schema and retrieved context before calling this library. Pass a list of vector arrays to batch several issues. See Encoding Cells for the full typed-cell contract.

Ablation

Ablation is just the same prediction with context deliberately removed. Here we remove the comment vector, then run the full and ablated contexts together.

without_comment = np.delete(cell_vectors, 3, axis=0)
full, ablated = model.predict(
    [cell_vectors, without_comment],
    target=0,
)

print(f"with latest comment:    {full:.1%}")
print(f"without latest comment: {ablated:.1%}")
print(f"change:                 {ablated - full:+.1%}")

A large change means the removed cell was load-bearing context; a change near zero means it was not affecting this prediction. Nothing automatically decides what to remove—you define the ablation that answers your question and compare its prediction with the original.

Pre-Trained Models

Pretrained RT-J models and deployment artifacts are available from RelativeDB on the Hugging Face Hub. Each weight repository contains both classification/ and regression/ checkpoints. Classification is loaded by default; select the regression checkpoint with RelationalTransformer(..., task="regression").

The published configs specify RT-J's 384-wide text input, 512-wide hidden states, 12 transformer blocks, 8 attention heads, and expected all-MiniLM-L12-v2 embedding space. Matching d_text=384 alone is not an interoperability guarantee: inputs must use the embedding model, normalization, semantic conventions, and relational structure documented by the checkpoint. For a different embedding space, train an input adapter or fine-tune a checkpoint with appropriate data.

Backends

The same constructor selects portable PyTorch, optimized Triton CUDA, ONNX Runtime, or a zero-allocation meta model.

# CPU, MPS, or CUDA; supports inference and training
model = RelationalTransformer("RelativeDB/rt-j-fp16", backend="torch")

# CUDA inference through the optimized relational-attention kernels
model = RelationalTransformer("RelativeDB/rt-j-fp16", backend="triton")

# Inspect dimensions and modules without allocating 85 million parameters
model = RelationalTransformer("RelativeDB/rt-j-fp16", backend="meta")
print(model.get_model_kwargs())

The published ONNX model downloads automatically from Hugging Face:

onnx_model = RelationalTransformer("RelativeDB/rt-j-onnx", backend="onnx")
predictions = onnx_model.predict(batch)

RelativeDB/rt-j-onnx is also the default when you omit the model name and select backend="onnx".

You can also export a loaded PyTorch checkpoint and open the local result:

torch_model = RelationalTransformer(device="cpu")
torch_model.export_onnx("rt-j.onnx", example_batch)
onnx_model = RelationalTransformer("rt-j.onnx", backend="onnx")

The release pipeline exports the published RelativeDB/rt-j-fp16 checkpoint—not a reduced test model—and checks dynamic batch and context lengths for numerical parity before attaching the ONNX file to the GitHub release. The fast test suite separately exercises the same path with a small deterministic checkpoint.

See Backends for supported devices, ONNX dynamic axes, and Triton limitations.

Training

This framework allows you to adapt relational transformer models to your own feature pipeline and task. You can fit a small multiclass or multilabel-ranking head over a frozen backbone, fine-tune the complete model for scalar binary or regression tasks with RelationalTrainer, or use the model in an ordinary PyTorch loop.

A frozen-backbone head is the fastest adaptation path. Each training input is encoded once, then only the selected task head is optimized.

from relational_transformers import RelationalExample

head_dataset = [
    RelationalExample(input=issue_a_batch, label=2),
    RelationalExample(input=issue_b_batch, label=0),
]

model = RelationalTransformer("RelativeDB/rt-j-fp16")
head = model.fit_head(
    head_dataset,
    task="issue_label",
    num_labels=5,
    problem_type="multiclass",
    epochs=100,
    learning_rate=1e-3,
)
head.save_pretrained("models/issue-label-head")

Use full-model fine-tuning when the relational backbone itself must adapt:

from relational_transformers import (
    RelationalExample,
    RelationalTrainer,
    RelationalTrainingArguments,
)

train_dataset = [
    RelationalExample(input=customer_a_batch, label=1.0),
    RelationalExample(input=customer_b_batch, label=0.0),
]

model = RelationalTransformer("RelativeDB/rt-j-fp16")
args = RelationalTrainingArguments(
    output_dir="models/customer-churn",
    num_train_epochs=3,
    per_device_train_batch_size=32,
    learning_rate=2e-5,
)

trainer = RelationalTrainer(
    model=model,
    args=args,
    train_dataset=train_dataset,
    task="churn",
)
trainer.train()

On CUDA, set training_backend="triton" in RelationalTrainingArguments to compile the trainable PyTorch graph through TorchInductor's Triton code generation. The optimized backend="triton" constructor remains the lower-latency inference path.

Some highlights across the different types of training are:

  • User-provided embeddings for text, numbers, categories, images, and other modalities
  • Typed sparse relations and variable-length relational inputs
  • Frozen-backbone multiclass and multilabel-ranking head tuning
  • Full-model fine-tuning for scalar binary and regression tasks
  • Binary, multiclass, multilabel, regression, forecasting, and ranking objectives
  • Multi-task adaptation through named prediction heads
  • Ordinary PyTorch modules and optimizers for custom training loops

Application Examples

The examples directory contains complete, runnable workflows:

RelativeDB is the first real-world integration: it retrieves related rows, constructs typed RelationalBatch inputs, and selects a supported serving path.

Companion Resources

Development setup

After cloning the repository (or a fork), install it in editable mode with the development dependencies:

python -m pip install -e ".[dev]"

To test your changes, run:

pytest

This runs deterministic, offline tests over typed customer, order, and support contexts. To validate the published Hugging Face checkpoints or compare Triton with PyTorch on CUDA, see the Testing guide.

To build the documentation, run:

make docs

Citing & Authors

If you find Relational Transformers useful in your research or application, you can cite the software:

@software{relational_transformers_2026,
    title = {Relational Transformers: Prediction and Fine-Tuning over Related Data},
    author = {{RelativeDB}},
    year = {2026},
    url = {https://github.com/RelativeDB/relational-transformers},
}

Don't hesitate to open an issue if something is broken or if you have questions about using your own embedding pipeline.

Maintainers

Relational Transformers is maintained by RelativeDB.

License

Relational Transformers is licensed under the Apache License 2.0.

Download files

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

Source Distribution

relational_transformers-0.1.0.tar.gz (50.2 kB view details)

Uploaded Source

Built Distribution

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

relational_transformers-0.1.0-py3-none-any.whl (38.2 kB view details)

Uploaded Python 3

File details

Details for the file relational_transformers-0.1.0.tar.gz.

File metadata

  • Download URL: relational_transformers-0.1.0.tar.gz
  • Upload date:
  • Size: 50.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for relational_transformers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 27c036bb81ba015cbba1ca1dcad3e6173df7ca5a263c2cb408d5bf71e5b06551
MD5 5470ad7a3bee83b17e9d35745a92329f
BLAKE2b-256 765234a600f0bbdf3c1c9ec8bae1baf36ed61b850c2e8c31c7e94b5056cae48d

See more details on using hashes here.

Provenance

The following attestation bundles were made for relational_transformers-0.1.0.tar.gz:

Publisher: release.yml on RelativeDB/relational-transformers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file relational_transformers-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for relational_transformers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a5f4ee1b7d68e66e760e87fe24d1a74d1aa6d5518e2e53412fe7e29e94525f9
MD5 3ddcae28a087ba99403cc0c398912ef4
BLAKE2b-256 e3e0fa51c33b69f3c6732144f41d70aaeb9abc8a093d9f900aa26c15c7a53626

See more details on using hashes here.

Provenance

The following attestation bundles were made for relational_transformers-0.1.0-py3-none-any.whl:

Publisher: release.yml on RelativeDB/relational-transformers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page