Tabular, time-series, scientific, and geometric deep learning · Tabular deep learning · SPE003 · Architecture
SAINT
SAINT uses both feature attention and attention across rows, with a contrastive pretraining option for tabular data.
In CodeSplash
A CodeSplash method covers part of this entry; some options or variants aren't built yet. The methods that run it are Experimental.
- FT-Transformer Experimental
Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.
- Availability
- Partly runs in CodeSplash (Experimental)
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through learn.ft_transformer. The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
SAINT uses both feature attention and attention across rows, with a contrastive pretraining option for tabular data. It is useful for examining whether relationships among samples and unlabeled data improve downstream prediction.
Question / hypotheses
The operative question is whether the specified representation, symmetry, likelihood or physical constraint improves held-out behavior for this data domain. This is a learning framework, not a null-hypothesis test; losses, attention weights and predictive confidence are not statistical p-values.
Architecture / computational structure
Mixed feature embeddings feed self-attention over columns and intersample attention over rows. Pretraining creates augmented views for contrastive and denoising objectives; a task head then produces supervised predictions.
Assumptions
Row attention introduces dependence on the supplied context batch. Test labels must never enter context, and target-row grouping can alter evaluation. Arbitrary tabular augmentations may violate real feature relationships; attention weights remain noncausal.
Formula / computational definition
Feature attention uses ; row attention analogously uses row representations . A pretraining loss combines contrastive alignment and reconstruction, followed by supervised .
Parameters and notation
Learned or estimated: Feature embeddings, feature-attention and row-attention projections, feedforward layers, pretraining heads and supervised head.
Hyperparameters and effects: Attention dimensions/depth, row-context or batch construction, augmentation strength, contrastive temperature, reconstruction weighting and optimizer. Row-context choices can change predictions and must be reported.
Fitting, fine-tuning, and adaptation
Pretrain only on permitted data, then fit the supervised head. Freeze embeddings/attention initially for transfer and unfreeze with lower backbone learning rates if validation improves. Preserve a declared row-context inference protocol and schema. Check source retention, calibration and sensitivity to context composition after adaptation.
How to use and calibrate
Define the independent evaluation unit before preprocessing: row/entity, whole set/object, molecule/trajectory, input function or chronological forecasting origin. Keep target construction and normalization within permitted training data. Compare with feature-only transformers and trees; evaluate the same held-out rows under several valid context batches. Separate gains from unlabeled pretraining, row attention and extra compute through ablations.
Example application
Use unlabeled industrial records to pretrain a predictor for a smaller labeled target table. This is a proposed use case, not a claim of validated performance on supplied real data.
Interpretation / pitfalls
Watch out
Assess model error against domain baselines and the stated assumptions. Component-level mathematical correctness does not establish paper reproduction or scientific validity. Use an independent validation design for model selection and a final held-out evaluation for claims; uncertainty and calibration require separate assessment.
Python and R code examples
Scope: SAINT-style row interaction illustrates dependence on companion context rows. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.
Full-model route: Python: authors’ SAINT code. R: custom native torch or labeled Python bridge. The example shows row attention and how changing a companion row changes outputs; it does not implement full SAINT pretraining.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — SAINT-style row interaction illustrates dependence on companion context rows. Use the shared setup.
Shared setup for this chapter
import numpy as np
def sm(x):
x=np.asarray(x); e=np.exp(x-x.max(axis=-1,keepdims=True)); return e/e.sum(axis=-1,keepdims=True)
rows=np.array([[1.,0.],[0.,1.],[.5,.5]])
def row_attention(X): return sm(X@X.T/np.sqrt(2))@X
first=row_attention(rows)[0]
changed=rows.copy(); changed[2]=[3.,-1.]
second=row_attention(changed)[0]
assert not np.allclose(first,second)
print(first,second)
Component demo, not a trained model — SAINT-style row interaction illustrates dependence on companion context rows. Use the shared setup.
Shared setup for this chapter
sm <- function(x) {
if(is.null(dim(x))) { e<-exp(x-max(x)); return(e/sum(e)) }
t(apply(x,1,function(v) { e<-exp(v-max(v)); e/sum(e) }))
}
rows<-matrix(c(1,0,0,1,.5,.5),3,byrow=TRUE)
row_attention<-function(X) sm(X%*%t(X)/sqrt(2))%*%X
first<-row_attention(rows)[1,]; changed<-rows; changed[3,]<-c(3,-1)
second<-row_attention(changed)[1,]
stopifnot(max(abs(first-second))>1e-6); print(rbind(first,second))
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry SPE003.