Data and model contracts¶
This page defines the runtime contracts expected by the app.
Input data contract¶
The uploaded dataset must be long format.
Minimum logical schema:
- entity column: unique sequence id per entity
- time column: sortable timestep column within each entity
- target column: binary label (
0or1) per row - feature columns: numeric model inputs
The app sorts by [entity_col, time_col] before windowing.
Sequence construction contract¶
build_sequences(...) creates sliding windows with:
- input tensor shape:
(num_windows, seq_len, n_features) - label shape:
(num_windows,) - target used: value at the last timestep in each window
Entities with fewer than seq_len rows are skipped.
Training split contract¶
train_val_split_by_entity(...) splits by entity id, not by window index.
Implications:
- all windows from one entity stay in one split
- prevents entity leakage between train and validation
Scaling contract¶
fit_scaler(...) computes feature-wise mean and std over train windows only.
Runtime scaling:
x_scaled = (x_raw - mean) / std
For uploaded external scaler:
- file type
.npz - must contain arrays
meanandstd - each must have length
n_features
Checkpoint model contract¶
Loaded model must be a torch.nn.Module compatible with:
forward(x)orforward(x, h0)xshape(batch, seq_len, input_dim)
Expected return:
(logits, seq_hidden, hidden_state)or(logits, seq_hidden)
where:
logitsshape(batch,)or(batch, 1)seq_hiddenshape(batch, seq_len, hidden_dim)
TimeSHAP call contract¶
run_local_timeshap(...) adapts to TimeSHAP local methods and passes:
datashape(1, seq_len, n_features)baselineshape(1, n_features)(mean over events)- callable
fthat returns(probabilities, hidden_state)
It resolves and calls:
local_pruninglocal_eventlocal_feat
and converts pruning index semantics to valid forward timestep indices.