Batch API
RelationalBatch is the tensor contract every backend consumes. The
Relational Batches page documents each
field, shape, and convention with examples.
RelationalBatch
- class relational_transformers.RelationalBatch(node_idxs, f2p_nbr_idxs, col_name_idxs, table_name_idxs, is_padding, sem_types, is_targets, number_values, datetime_values, boolean_values, text_values, col_name_values)
A padded batch of relational cells.
This is the shared boundary used by PyTorch, Triton, ONNX, and RelativeDB. Integer tensors describe topology; value tensors contain already encoded model inputs. Boolean masks use
Truefor padding/targets.- Parameters:
- validate()
Check shapes, semantic type range, target placement, and finiteness.
Runs automatically on construction. Raises
ValueErrorwith the offending field name on the first violation.- Return type:
- to(device, dtype=None)
Return a copy on
device, optionally casting floating-point channels.- Parameters:
- Return type:
- as_dict()
Return the canonical fields as a name-to-tensor dictionary.
The keys match
BATCH_FIELDSand round-trip throughfrom_mapping().- Return type:
dict[str, Tensor]
- classmethod from_mapping(values)
Build a batch from a dictionary of arrays or tensors.
Accepts numpy arrays, torch tensors, or nested lists for every field. Integer index fields are cast to
int64,is_paddingandis_targetstobool(uint8inputs work), and value channels to floating point. Short RelativeDB aliases such asf2p,col_idxs,table_idxs,is_target,number_v, andtext_vnormalize to their canonical names. RaisesValueErrorwhen a canonical field is missing.- Parameters:
values (Mapping[str, Any])
- Return type:
- classmethod from_text_cells(cells, *, target, node_idxs=None, parents=None, table_idxs=None)
Build one batch row from
[column_embedding, value_embedding]cells.cellshas shape[S, 2*d_text]. This convenience path is useful for all-text examples; typed production callers should construct the full batch so scalar and datetime channels retain their semantics.- Parameters:
- Return type:
- ablate(cells)
Return a new batch with the same cell positions padded out.
Positions remain stable, so node and parent indices require no remap. Target cells may not be ablated.
- Parameters:
cells (Sequence[int])
- Return type: