Custom models
Checkpoint Resolution
The constructor’s first argument resolves in three ways:
A file path loads those weights directly, reading
config.jsonfrom the same directory when present.A directory loads
<directory>/config.jsonand the weights file it names throughcheckpoint_file, which defaults tomodel.safetensors. When the directory containsclassification/orregression/subfolders,task=picks the subfolder.Anything else is treated as a Hugging Face repository ID and downloaded through
huggingface_hub, with the sametask=subfolder rule and an optionalrevision=.
The configuration declares dimensions either as top-level keys or nested under a
"model" key:
{
"task_type": "clf",
"model": {"num_blocks": 12, "d_model": 512, "d_text": 384, "num_heads": 8, "d_ff": 2048},
"checkpoint_file": "model.safetensors"
}
Missing dimension keys raise ValueError at load time. .pt checkpoints load through
torch.load as a fallback; safetensors is the published format.
Saving Checkpoints
save_pretrained writes model.safetensors and config.json in the layout described
above, so a fine-tuned model reloads with the same constructor:
model.save_pretrained("models/churn-v2")
reloaded = RelationalTransformer("models/churn-v2")
Working with RTJModel Directly
The public RTJModel is an ordinary torch.nn.Module whose state-dict names match
published RelativeDB RT-J checkpoints.
model.model exposes the loaded instance on the torch backend, and the class constructs
standalone for training from scratch:
from relational_transformers import RTJModel
small = RTJModel(num_blocks=2, d_model=64, d_text=16, num_heads=4, d_ff=128)
output = small(batch, output="target_scores")
Advanced users can replace decoder heads, freeze blocks, register hooks, or run their own optimization and mixed-precision setup over it. Use the meta backend when inspecting or transforming a large architecture without allocating weights.
Module layout
enc_dict: value encoders fornumber,text,datetime,boolean, andcol_namedec_dict: decoders back to each semantic channel;numberproduces target scoresnorm_dictandnorm_out: RMS normalization around encoders and the final statemask_embs: one learned target-mask embedding per semantic typeblocks: the stack of relational blocks, each withcol,feat, andnbrattention plus a feed-forward layer
Changing the Embedding Space
Custom input encoders must preserve the checkpoint contract or be trained jointly with
the backbone. A checkpoint trained against all-MiniLM-L12-v2 reads any other 384-wide
embedding space as noise, because two encoders of the same width still place meanings at
unrelated coordinates. Options
that work: fine-tune the full model on data encoded your way, or train an adapter that
maps your encoder’s space into the checkpoint’s.