TabNet, set models and TabPFN
Three Experimental learners for special shapes of tables. TabNet shows which columns each step read; a set model learns from groups of rows whose order doesn't matter; TabPFN predicts a small table without training on it.
What runs in CodeSplash
- TabNet (attentive feature selection) Experimental
- Set model (Deep Sets, Set Transformer) Experimental
- TabPFN v2 (pretrained tabular model) Experimental
You will be able to
- Read TabNet's masks as "what the network used", and say why they aren't causes
- Decide when rows belong together as a set, and pick a pooling and a prediction level
- Say what TabPFN does instead of training, where its pretraining limits are, and what its saved model keeps
Three shapes of problem
ReadMost learners treat every row alone and every column alike. These three Experimental learners each fit a different shape:
| Learner | Use it when | What you get |
|---|---|---|
| TabNet | You want a network that shows which columns it read | A sparse mask per step, summed into a column share |
| Set model | Rows come in groups whose order doesn't matter (a basket's items, a team's players) | One prediction per group, or per row in its group |
| TabPFN v2 | The table is small (up to 10,000 rows) and you want a strong first answer fast | Predictions with no training on your data |
Which engines run them
ReadTabNet and the set model train in Python and R from the same random stream, so both engines give the same model. TabPFN runs in Python only, because no R package loads its pretrained weights.
TabNet reads a few columns at a time
ReadTabNet reads a row in a few decision steps. At each step an attentive transformerAttentive transformerTabNet's step that scores the columns, scales them by a prior of what is still unused, and picks a sparse mask. scores the columns and turns the scores into a mask with sparsemaxSparsemaxLike softmax, turns scores into weights that sum to 1, but sets small scores to exactly zero.. Unlike softmax, sparsemax gives exactly zero weight to low scores, so each step reads only a few columns. A prior shrinks columns already used, and Mask reuse (γ) sets how strongly: at 1 a column can be used once, and larger values allow reuse.
The steps' outputs add up to the prediction. Weighting each step's mask by how much that step contributed gives the Columns the masks chose chart.
Predict: how many columns?
PredictPredict first
On Pima, TabNet with 2 steps reached a cross-validated AUC of 0.796. What share of its mask weights were above zero?
Reveal
Well below 100%: 0.344. Sparsemax sets most weights to exactly zero, so each step reads only a few columns. Raise Sparsity penalty (λ) and the share drops further.
When rows belong together: set models
ReadSome tables have a natural group per row: the items of one basket, the players of one team, the visits of one patient, the measurements of one chick. When the group, not the row, is the unit you want to predict, and the order inside a group doesn't matter, use a set modelSet modelA model for groups of rows whose order doesn't matter (a basket's items, a team's players), one set id per group..
Setting up a set model
ReadChoose the Set id column. Rows that share it form one set, and they always stay in the same cross-validation fold. Then:
- Encoder: Deep SetsDeep SetsEncode every row of a set alone, pool the encodings (mean, sum or max), and predict from the pooled vector. reads every row alone; the Set TransformerSet TransformerA set model whose rows attend to each other before pooling; inducing points make large sets affordable. lets the rows of a set attend to each other first.
- Pooling: mean ignores set size, sum keeps it, max picks the most extreme row (PointNet's pooling), and attention lets a learned query weigh the rows.
- Predict for: Each set gives one value per set (the target must be the same on every row of a set). Each row in its set predicts every row from its own encoding next to its set's summary.
Predict: one value per set
PredictPredict first
Each chick in ChickWeight got one of four diets and was weighed up to 12 times. A Deep Sets model sees only each chick's (time, weight) points. How well does it tell the diet?
Reveal
It names the right diet for 0.355 of held-out chicks, where guessing gets 25%. But its log loss, 1.42, is no better than guessing's : each fold trains on only about 26 chicks, so the probabilities are overconfident. With sets, count the sets, not the rows, when you judge how much data you have.
Shuffling must not matter
ReadEvery set model is built for permutation invariancePermutation invarianceShuffling the rows inside a set leaves the prediction unchanged; every set model is built to have it.: shuffling a set's rows must not change its prediction. Each run checks this by reversing every set and reports the largest change as Invariance gap, which is 2.22e-16 here, zero up to rounding.
One more thing to read in the scores: with one prediction per set, cross-validation scores rows by default, so a set of ten rows counts ten times. Compare models on the same sets, or turn on Scores per set to also see every score with each set counted once.
The Explanations tab offers only permutation importance and partial dependence, both on whole sets.
TabPFN predicts without training
ReadTabPFNTabPFNA transformer pretrained on synthetic tables that predicts small tables in context, without training on them. is a transformer pretrained on millions of synthetic tables drawn from a prior over causal structures. It doesn't train on your data. "Fitting" stores the training rows, and each prediction reads them in context (in-context learningIn-context learningPredicting from examples given with the question, with no weights changed; TabPFN reads the training rows this way.). That makes it a strong first answer for small tables.
On Pima, two ensemble members reach a cross-validated AUC of 0.858, against 0.796 for TabNet.
Before you use TabPFN
ReadWhat to know before you use it:
- Limits. The v2 weights were pretrained on tables up to 10,000 rows, 500 columns and 10 classes. Beyond them the run stops unless you turn on Ignore pretraining limits, and its accuracy is then not promised.
- Download and license. The weights (29 MB for classification, 44 MB for regression) download only after you agree. Their license (
LicenseRef-PriorLabs-1.1) is the Apache License plus an attribution clause, so its results and model cards say Built with PriorLabs-TabPFN. Later TabPFN versions are non-commercial, and the app never uses them. - The saved model keeps your rows. Because TabPFN predicts by reading the training rows, a registered TabPFN model contains them. Treat the model file like the data.
Check your understanding
CheckpointCheck yourself
In a TabNet run, Income has the largest share of mask weight. What can you conclude?
Show the answer
Answer: a
Masks show what the network read. Causes need a design or a causal method, and correlated columns can share or swap mask weight between fits.
Check yourself
Why do TabNet's masks have many exact zeros?
Show the answer
Answer: a
Softmax keeps every weight above zero; sparsemax doesn't. The sparsity penalty pushes the masks further toward few columns, but the zeros come from sparsemax.
Check yourself
Which data set suits a set model?
Show the answer
Answer: a
A basket's items have no order and the basket is the unit. Daily sales are ordered (use a forecaster), and one row per customer needs no grouping.
Check yourself
You want each player's points predicted from the player's own stats and who else is on the team. Which setting?
Show the answer
Answer: a
Each row in its set predicts every row from its own encoding next to the set's summary. Each set would give every player on a team the same prediction.
Check yourself
What happens to TabPFN's weights when you fit it on your table?
Show the answer
Answer: a
TabPFN learns in context. That's why fitting is instant, prediction cost grows with the training rows, and a saved model keeps them.
Check yourself
Your table has 40,000 rows. What's the sensible first step with TabPFN?
Show the answer
Answer: a
Above 10,000 rows its accuracy is not promised. A sample keeps it within its pretraining sizes, and a gradient-boosting baseline on all rows tells you what the sample costs.
Train them
In the appIn the Learners step, add TabNet (attentive feature selection) and open a run's Overview for the Columns the masks chose chart. For a set model, pick Set model (Deep Sets, Set Transformer) and set Set id in Setup. For TabPFN, switch the engine to Python; the first run asks before it downloads the weights.
import numpy as np
from sklearn.datasets import load_breast_cancer
from codesplash.deep import tabnet # the app's helper package: the same TabNet as the R twin
X, y = load_breast_cancer(return_X_y=True)
X = (X - X.mean(axis=0)) / X.std(axis=0)
fit = tabnet.fit_tabnet(X, y.astype(float), None, "binary", 1, n_d=8, n_a=8, n_steps=3, epochs=20,
batch_size=128, virtual_batch_size=32, early_stopping=False, seed=1)
ex = tabnet.tabnet_explain(fit, X)
print("mask density", round(ex["density"], 2))
print("top columns", np.argsort(-ex["importance"])[:5])library(codesplashr) # the app's helper package: the same TabNet as the Python twin
X <- scale(as.matrix(mtcars[, c("mpg", "hp", "wt", "qsec", "drat", "disp")]))
fit <- cs_deep_fit_tabnet(X, mtcars$am, NULL, "binary", 1L, n_d = 4L, n_a = 4L, n_steps = 2L, epochs = 30L,
batch_size = NULL, virtual_batch_size = 16L, early_stopping = FALSE, seed = 1L)
ex <- cs_deep_tabnet_explain(fit, X)
round(setNames(ex$importance, colnames(X)), 2)Recap
Recap- TabNet's sparsemax masks show which columns each step read; read them as use, not cause.
- A set model needs a Set id; it ignores the order inside a set, and its Invariance gap checks that.
- TabPFN predicts small tables without training. It runs in Python only, within 10,000 rows, 500 columns and 10 classes, and its saved model keeps the training rows. Built with PriorLabs-TabPFN.
Concepts in this lesson