Module 12 β DeepTab (optional)ΒΆ
π§ β NLP Β· π Course home Β· Production βΆ
Goal: Meet the modern deep-learning toolkit for structured data. Gradient-boosted trees (XGBoost/LightGBM) still win most tabular problems β but DeepTab (OpenTabular/DeepTab) wraps 15 deep architectures (Mamba, FT-Transformer, SAINT, NODE, TabM, ResNetβ¦) behind a clean scikit-learn API, and unlocks things trees canβt: distributional regression, learned embeddings, and end-to-end multimodal models.
Estimated time: 1β2 hours.
Prerequisites: Module 5 (NB 17 sklearn basics, NB 19 feature engineering) and PyTorch basics β either the Module 5 appendices A1βA3 or the full Module 6 (its NB 22 builds this moduleβs entity-embedding architecture by hand). Appendix A5 (conformal prediction) pairs naturally with the uncertainty section.
scikit-learn API βββΊ 15 deep tabular architectures
model.fit(X, y) Mambular Β· FTTransformer Β· SAINT Β· NODE
model.predict(X) TabM Β· ResNet Β· MLP Β· TabTransformer β¦
model.predict_proba each ships as *Classifier / *Regressor / *LSS
model.encode(X)
β
ββββββββββββΌββββββββββββββββββββββ¬βββββββββββββββββββββββββ
βΌ βΌ βΌ βΌ
classify regress distributional (LSS) latent embeddings
predict a whole feed into any
distribution, not downstream model
just a point
Notebook at a glanceΒΆ
# |
Notebook |
β± Time |
Difficulty |
What youβll build |
|---|---|---|---|---|
38 |
|
~60β90 min |
Intermediate β Advanced |
One customer-churn table, many tools through one socket: a churn classifier benchmarked against a |
Notebook guideΒΆ
44 Β· DeepTab: Deep Learning for Tabular Data β 44_deeptab_tabular_deep_learning.ipynbΒΆ
For two decades, tabular data β the spreadsheets, transaction logs and feature stores that run most of a business β has belonged to gradient-boosted trees. The notebook opens by taking that seriously: on the median tabular benchmark, XGBoost/LightGBM are still the thing to beat. But architectures designed specifically for tables β FT-Transformer, SAINT, NODE, TabM, ResNet, and sequence models such as Mamba β now match or beat boosting on large, complex datasets, and they natively do things trees cannot: predict full distributions, learn reusable row embeddings, fuse tables with text/image towers, and transfer-learn across tables. DeepTab (from the OpenTabular project) wraps 15 stable models behind a single scikit-learn BaseEstimator API, each shipping as a matching <Name>Classifier / <Name>Regressor / <Name>LSS trio.
The notebookβs mental model is one socket, many power tools: the sklearn .fit/.predict interface is the wall socket, the gradient-boosted tree is the trusty cordless drill you grab first, and DeepTabβs architectures are specialist tools that plug into the same socket β swapping MambularClassifier for FTTransformerClassifier is a one-word change. A single synthetic customer-churn frame (tenure, monthly charges, support tickets, contract type, region) runs through every section: you predict churn, predict revenue, get an uncertainty band, and pull row embeddings from it.
It also showcases DeepTab v2βs split-config API: instead of one long list of keyword arguments, a model is configured through three small objects β MambularConfig (architecture), PreprocessingConfig (input handling) and TrainerConfig (the training loop) β and because everything is a BaseEstimator, nested params like model_config__d_model drop straight into RandomizedSearchCV.
Learning objectives:
Decide when a tabular deep-learning model is worth it versus a gradient-boosted tree (spoiler: try the trees first)
Train a classifier and a regressor with DeepTabβs sklearn-style
.fit/.predict/.predict_probaAPI, and swap architectures by nameUse distributional regression (LSS) to predict full distributions and reason about uncertainty for risk and pricing
Extract latent embeddings with
.encode()and feed them to a downstream modelTune hyperparameters with both DeepTabβs built-in
optimize_hparamsand sklearnβsRandomizedSearchCV
Sections (the notebookβs arc, group by group):
Setup & the offline gate
π Smoke test: is DeepTab installed? β imports
deeptaband sets the singleHAS_DEEPTABflag every later cell branches onThe offline stand-in β drop-in classes with DeepTab v2βs exact constructors and methods, backed by small sklearn neural nets
One factory, two backends β
make_classifier(...)& friends return real or stand-in models, so the rest of the notebook never needs anotherif HAS_DEEPTAB
Why β and on what data
1 Β· The value proposition β and when not to use it β the βstart with gradient boostingβ discipline: the drill already in your hand
2 Β· A synthetic business dataset (churn) β build and eyeball the mixed-type table (tenure/charges/tickets + contract/payment/region)
The core sklearn-style API
3 Β· Classification with
MambularClassifierβ honestHistGradientBoostingbaseline first, then the deep model, then swapping the architecture by class name (β threshold tuning for churn)4 Β· Regression with
MambularRegressorβ same socket, continuousrevenuetarget
What trees canβt do natively
5 Β· Distributional regression (LSS) with
MambularLSSβ why a distribution beats a point estimate; per-row(mean, Ο)for risk/pricing/inventory (β stock to the 90th percentile)6 Β· Latent embeddings via
model.encode(X)β dense row vectors for similarity search and downstream models (β find the most similar customer)
Making it good
7 Β· Hyperparameter tuning β (a) built-in Bayesian
optimize_hparams, (b) sklearnRandomizedSearchCVwith nestedmodel_config__d_modelparamsπ§ͺ Exercises Β· π§ Key takeaways Β· β Self-assessment Β· π Next step
Models covered: MambularClassifier, MambularRegressor, MambularLSS trained in-notebook, each configured via the v2 split-config trio (MambularConfig + PreprocessingConfig + TrainerConfig); one-line-swap siblings named for every architecture (FTTransformerClassifier, TabTransformerClassifier, ResNetClassifier, MLPClassifier, SAINTClassifier, TabMClassifier, NODEClassifier, β¦); HistGradientBoostingClassifier as the tree baseline to beat.
Practice: 3 β quick exercises (~2 min each, collapsible solutions) β threshold tuning for churn, stock to the 90th percentile, find the most similar customer β plus 6 end-of-notebook π§ͺ exercises (architecture bake-off, bigger data, Poisson vs normal LSS families, embeddings-for-retrieval, real tuning, and a conformal-prediction stretch pairing with NB A5). Reference-style module, so exercises are a numbered list β no β ratings, Debug-me or π mini-project here.
Datasets: one synthetic customer-churn table (400 rows), generated inline with make_classification plus categorical contract / payment / region columns and an engineered churn signal; a continuous revenue target derived from it powers the regression and LSS sections. Nothing is downloaded.
Offline behaviour: the whole notebook branches on a single HAS_DEEPTAB flag. Without deeptab installed, drop-in stand-in classes mimic the v2 estimators β same split-config constructors and methods, backed by sklearn MLPClassifier/MLPRegressor behind an ordinal encoder; .encode() returns last-hidden-layer activations, the LSS stand-in returns per-row (mean, Ο) with a constant residual Ο, and optimize_hparams is a no-op. pip install deeptab (pulls PyTorch + Lightning) swaps in the real Mamba/Transformer models with no other code changes.
Folder artifactsΒΆ
lightning_logs/ (version_0β¦3) and model_checkpoints/ (best_model*.ckpt) are by-products of running the notebook with the real deeptab installed β PyTorch Lightning writes training logs and best-model checkpoints there. Safe to browse or delete; they regenerate on the next real training run.
How this notebook worksΒΆ
Module 12 is optional and written in the reference style of the appendices: it focuses on seeing a library at work, with β checkpoint exercises (collapsible solutions) at the key decision points rather than a drill-heavy exercise block. It runs 100% offline end-to-end β the sklearn stand-in keeps every cell executable so you can study the API shape and the GBMs-first reasoning now, and installing deeptab later upgrades the same code to the genuine deep models:
pip install deeptab # optional β pulls torch + lightning
The disciplines the notebook keeps hammering:
Try gradient boosting first. On small/medium tabular data, a tuned GBM is usually the bar to beat β on the 400-row churn table it holds its own, exactly as the rule predicts. Deep tabular models earn their keep with large data, multimodal inputs, transfer, or distributional needs.
Predict distributions, not just points. For pricing, risk, demand and inventory, the spread matters as much as the mean β thatβs what the
*LSSvariants give you. Pair with conformal prediction (A5) for calibrated intervals.One API, many architectures. Swapping
MambularClassifierβFTTransformerClassifieris a one-word change β so benchmark several, donβt marry the first.
Where nextΒΆ
β This is the end of the optional track. Loop back to Module 5 β Machine Learning (../05_machine_learning/) to compare against tree ensembles, or to Module 7 β Industry Applications (../07_industry_applications/) to put churn/demand/risk models into a business context.