Search

Search papers and lessons

TabNet: Attentive Interpretable Tabular Learning

Sercan O. Arik, Tomas Pfister · 2019

TabNet is a deep network for spreadsheet-style data that picks a few input features at each of several steps using sparse attention, which makes its choices readable.

On this page

  • Colour = topic mix
  • Linear algebra
  • Neural network basics
  • Calculus
  • Discrete math
  • Probability
  • Architectures
  • ReadReady to readNot yet

TL;DR

TabNet is a neural network built for tables: rows are examples, columns are features such as age, income or occupation. Tree models such as gradient-boosted trees have long been the default for this kind of data. TabNet tries to match or beat them while staying readable. At each of several decision steps it chooses a small set of features to look at, using a learned mask that is forced to be sparse, so you can see which features it used and how much. The authors also show that the same network can first learn from unlabelled rows by filling in hidden cells, which helps when labels are scarce.

Builds on: Attention Mechanism, Sparsemax, Gated Linear Unit (GLU), Batch Normalization, Decision Tree, Backpropagation · Leads to: the wider line of interpretable tabular deep learning, and self-supervised pre-training for tables

Why it mattered

Tabular data is the most common data type in real-world AI, according to a 2018 McKinsey report the authors cite, yet deep learning had not become the standard tool for it the way it had for images and text. TabNet was one of the first attempts at a single canonical deep architecture for tables that keeps feature-level explanations. It also showed self-supervised pre-training working on tables, a technique that had been proven mainly for text and images. The paper's own experiments cover classification and regression on public benchmarks such as Forest Cover Type, Higgs, Rossmann Store Sales and Sarcos.

History

Ensembles of decision trees were still the dominant tool for tabular data when the paper was written, as its introduction notes. Deep networks had succeeded on images and text but had not matched them on tables. In 2019 Sercan Arik and Tomas Pfister, working at Google Cloud AI, proposed TabNet, combining sequential attention with feature selection and reporting results on public tabular benchmarks. The paper is listed on arXiv under identifier 1908.07442, posted in 2019.

The problem

Before TabNet, a practitioner choosing a model for a table had two options that each gave something up. Gradient-boosted trees (see XGBoost: A Scalable Tree Boosting System and Gradient Boosting) were accurate and fast, but they needed careful feature engineering, and their ensembles of many trees are hard to read as a whole. Standard multi-layer networks could learn end to end, but the authors argue that convolutional layers and MLPs are vastly overparameterised for tables and lack the right Inductive Bias, so they often fail to find good solutions. Trees, by contrast, represent the roughly hyperplane-shaped decision boundaries common in tabular data efficiently. The paper asks for a network that picks the relevant features per row, stays compact, and exposes its choices.

How it works

Take a toy table with three features, one row, and two decision steps. The steps are the core idea, so trace one.

  1. Input. The row is the vector of raw feature values, here f = (2, 4, 6). No scaling or feature engineering is applied; the paper inputs raw numerical features and maps categorical ones to learned embeddings. Check: the vector has one entry per feature.
  2. Score the features. An attentive transformer looks at what the previous step passed on (at step 1, nothing yet) and produces one score per feature: here z = (1.0, 0.5, -1.0). Check: three scores, one per feature.
  3. Turn scores into a sparse mask. Instead of Softmax, which gives every feature some weight, TabNet applies sparsemax. It returns non-negative weights that sum to 1 and can be exactly zero: M[1] = (0.75, 0.25, 0). Check: 0.75 + 0.25 + 0 = 1.
  4. Keep only the chosen features. Multiply the mask by the input elementwise: M[1] · f = (1.5, 1.0, 0). The third feature contributes nothing to this step, so the step's capacity is spent on the first two. Check: the zero in the mask gives a zero in the product.
  5. Process and split. A feature transformer (a stack of fully connected layers with batch normalization and a gated linear unit) turns the masked features into two vectors: d[1], which feeds the decision, and a[1], which goes to the next step. Check: the same input produces both outputs; one is kept for the answer, one is passed on.
  6. Update the prior. A prior P records how much each feature has already been used. It starts at 1 for every feature. After step 1 it becomes P[1] = γ − M[1]. With γ = 1.5 this gives (0.75, 1.25, 1.5). A feature used a lot now has less room left for the next step. Check: a feature with mask 0 keeps its full budget.
  7. Repeat and combine. Steps 2 onward repeat 2–6 with the new prior. The final decision embedding adds up the positive parts of all the d[i] vectors, and a linear layer maps that to the output. Check: the output is a sum over steps, so each step's contribution can be read separately.

The mask at step 1 is the interpretable object. Its zeros say which features that step ignored.

Worked examples

Example
1. Sparsemax on three scores

Scores z=(1.0,0.5,−1.0)z = (1.0, 0.5, -1.0).

  1. Sort: already decreasing.
  2. Test k=1k = 1: 1+1⋅1.0=2.01 + 1 \cdot 1.0 = 2.0 is greater than 1.01.0, so k=1k = 1 passes.
  3. Test k=2k = 2: 1+2⋅0.5=2.01 + 2 \cdot 0.5 = 2.0 is greater than 1.0+0.5=1.51.0 + 0.5 = 1.5, so k=2k = 2 passes.
  4. Test k=3k = 3: 1+3⋅(−1.0)=−2.01 + 3 \cdot (-1.0) = -2.0 is not greater than 0.50.5, so it fails. The support size is k=2k = 2.
  5. Threshold τ=(1.0+0.5−1)/2=0.25\tau = (1.0 + 0.5 - 1)/2 = 0.25.
  6. Output max⁡(z−0.25,0)=(0.75,0.25,0)\max(z - 0.25, 0) = (0.75, 0.25, 0). The entries sum to 1 and the third is exactly 0.

Interpretation: the third feature is dropped entirely, which softmax would not do.

Example
2. Updating the prior with two values of gamma

Mask M[1]=(0.75,0.25,0)M[1] = (0.75, 0.25, 0).

  1. Take γ=1.5\gamma = 1.5. Compute γ−M[1]=(1.5−0.75,1.5−0.25,1.5−0)=(0.75,1.25,1.5)\gamma - M[1] = (1.5 - 0.75, 1.5 - 0.25, 1.5 - 0) = (0.75, 1.25, 1.5).
  2. Take γ=1.0\gamma = 1.0. Compute γ−M[1]=(0.25,0.75,1.0)\gamma - M[1] = (0.25, 0.75, 1.0).
  3. Compare the first feature: with γ=1.0\gamma = 1.0 its remaining budget is 0.25, with γ=1.5\gamma = 1.5 it is 0.75.
  4. Interpretation: a smaller γ\gamma makes the prior stricter, so features used in step 1 are harder to reuse later.
Example
3. A reported benchmark result, read against its baseline

The paper's Table 2 reports test accuracy on Forest Cover Type: XGBoost 89.34%, AutoML Tables 94.95%, TabNet 96.99%. The paper also reports an ablation (Table 11) where removing the sparsity penalty gives 96.50%.

  1. The gap between TabNet and AutoML Tables is 96.99−94.95=2.0496.99 - 94.95 = 2.04 percentage points.
  2. The gap between TabNet and XGBoost is 96.99−89.34=7.6596.99 - 89.34 = 7.65 percentage points.
  3. The gap between the full model and the no-sparsity ablation is 96.99−96.50=0.4996.99 - 96.50 = 0.49 percentage points.
  4. Interpretation: on this dataset the sparsity penalty contributes a modest part of the gain. The large gaps come from the architecture as a whole, although the paper's ablations show that the training choices also matter.

Try it: on the same ablation table, the "High sparsity regularization" row (with λsparse=0.01\lambda_{sparse} = 0.01) gives 93.87%. What is its gap to the full model? Answer: 96.99−93.87=3.1296.99 - 93.87 = 3.12 percentage points, which is the largest drop in that table. Too much sparsity hurts, so the penalty must be tuned.

The math

A <Definition> first, then the steps above written in symbols.

Definition: TabNet step

For a batch of BB rows with DD features, write f∈RB×D\mathbf{f} \in \mathbb{R}^{B \times D} for the input. At step ii the model computes a mask M[i]\mathbf{M}[i], a prior P[i]\mathbf{P}[i], and the pair [d[i],a[i]][\mathbf{d}[i], \mathbf{a}[i]], where d[i]\mathbf{d}[i] has NdN_d columns and a[i]\mathbf{a}[i] has NaN_a columns.

Step 3 in symbols: the sparse mask

M[i]=sparsemax(P[i−1]⋅hi(a[i−1]))\mathbf{M}[i] = \text{sparsemax}\big(\mathbf{P}[i-1] \cdot h_i(\mathbf{a}[i-1])\big)

Here hih_i is a trainable layer (a fully connected layer followed by batch normalization). Sparsemax maps each row to a point on the probability simplex, so each row of M[i]\mathbf{M}[i] sums to 1. Softmax would give every entry a positive weight; sparsemax can set entries to exactly 0. For a score vector zz sorted in decreasing order, with kk the largest index where 1+kzk>∑j≤kzj1 + k z_k > \sum_{j \le k} z_j, the output is pj=max⁡(zj−τ,0)p_j = \max(z_j - \tau, 0) with τ=(∑j≤kzj−1)/k\tau = (\sum_{j \le k} z_j - 1)/k.

Step 4 in symbols: masking

M[i]⋅f\mathbf{M}[i] \cdot \mathbf{f}

The product is elementwise. Entries where the mask is 0 are removed from this step.

Step 6 in symbols: the prior

P[i]=∏j=1i(γ−M[j]),P[0]=1\mathbf{P}[i] = \prod_{j=1}^{i} (\gamma - \mathbf{M}[j]), \qquad \mathbf{P}[0] = \mathbf{1}

The relaxation parameter γ\gamma controls how many steps one feature may be used in. With γ=1\gamma = 1, a feature the mask has fully used can never be chosen again. Larger γ\gamma allows reuse.

Step 7 in symbols: the output

dout=∑i=1NstepsReLU(d[i]),output=Wfinal dout\mathbf{d}_{out} = \sum_{i=1}^{N_{steps}} \text{ReLU}(\mathbf{d}[i]), \qquad \text{output} = \mathbf{W}_{final}\,\mathbf{d}_{out}

For classification a softmax is applied to the output during training. The paper's sparsity penalty on the masks is the entropy of each mask, summed over steps, rows and features, scaled by λsparse\lambda_{sparse}:

Lsparse=∑i=1Nsteps∑b=1B∑j=1D−Mb,j[i]log⁡(Mb,j[i]+ϵ)Nsteps⋅BL_{sparse} = \sum_{i=1}^{N_{steps}} \sum_{b=1}^{B} \sum_{j=1}^{D} \frac{-\mathbf{M}_{b,j}[i] \log(\mathbf{M}_{b,j}[i] + \epsilon)}{N_{steps} \cdot B}

Low entropy means a mask that puts its weight on few features, so minimising this term pushes toward sparsity. For the step-1 mask of the walkthrough, (0.75,0.25,0)(0.75, 0.25, 0), the sum is about 0.560.56 nats before the ϵ\epsilon correction.

Results

The main results, copied from the paper's tables:

  • Forest Cover Type (accuracy %): TabNet 96.99, AutoML Tables 94.95, XGBoost 89.34, LightGBM 89.28, CatBoost 85.14.
  • Higgs Boson (accuracy %): TabNet-M 78.84 with 0.66M parameters; gradient-boosted tree-L 76.98 with 6.96M.
  • Sarcos (test MSE, lower is better): TabNet-S 1.25 with 6.3K parameters; TabNet-L 0.14 with 1.75M parameters.
  • Synthetic feature selection (test AUC): TabNet is the best (bold) on Syn2, Syn5 and Syn6; INVASE is best on Syn1, Syn3 and Syn4.
  • Self-supervised pre-training on Higgs (accuracy %): with 1k labelled rows, 57.47 supervised versus 61.37 with pre-training; with 10k, 66.66 versus 68.06; with 100k, 72.92 versus 73.19.
  • Interpretability: on the mushroom dataset TabNet reaches 100% test accuracy and assigns the "Odor" feature an importance ratio of 43%.

The limits are the authors' own. The paper reports that TabNet is not best on every dataset, and the KDD appendix results are close to XGBoost and CatBoost rather than clearly above them. The importance rankings are consistent with SHAP and other methods on Adult Census Income, but the paper reports agreement, not ground truth.

Common mistakes and tradeoffs

It is tempting to think that a sparse mask means the model "only uses" the features it highlights. In fact the masks are soft weights on one step, and the decision combines all steps and all features through the feature transformers, so an importance reading comes from aggregating masks over steps, which the paper does with a weighted sum. Use the per-step masks for step-level questions and the aggregate for global questions.

It is also tempting to think that more steps or wider layers always help. In fact the paper's guidelines say that increasing NstepsN_{steps} beyond some value may hurt training dynamics, because the network gets deeper along some paths, and that very high NdN_d and NaN_a may overfit. Its guideline is NstepsN_{steps} between 3 and 10, with Nd=NaN_d = N_a as a reasonable default.

When to use TabNet: the table is large, the features interact in ways a tree struggles to express, and you need a per-row account of which features mattered. When not to: small tables where gradient-boosted trees are already strong and fast to tune, or when training cost matters more than an explanation. The paper's Higgs experiment, with about 10.5 million rows, is the large-data case where it reports DNNs outperforming tree ensembles.

Reading guide

Recap

  • Tabular data is common, and trees have dominated it because they are efficient on hyperplane-like boundaries and fast to train.
  • TabNet selects features per row with a sparse mask (sparsemax), so zeros are exact.
  • The prior P[i]\mathbf{P}[i] tracks feature use across steps, controlled by γ\gamma.
  • Each step's decision is summed into one output, and the masks can be aggregated into a feature importance.
  • Unlabelled rows can pre-train the encoder by hiding features and predicting them, which helps when labels are scarce.

Read next: Attention Mechanism for the general idea of weighting inputs, and Sparsemax for the normaliser the mask uses.

Check yourself

QuestionRecall: what is the main difference between softmax and sparsemax as TabNet uses them?Show answer

Softmax gives every feature a positive weight. Sparsemax projects the scores onto the probability simplex and can set some weights to exactly 0, so TabNet can ignore a feature completely at a given step.

QuestionFor scores z=(2.0,1.0,0.0)z = (2.0, 1.0, 0.0), what is the sparsemax output?Show answer

Sorted, the scores are already decreasing. Test k=1k = 1: 1+2=3>21 + 2 = 3 > 2, passes. Test k=2k = 2: 1+2⋅1=3>31 + 2 \cdot 1 = 3 > 3 is false, so the support is k=1k = 1. Threshold τ=2−1=1\tau = 2 - 1 = 1. Output max⁡(z−1,0)=(1,0,0)\max(z - 1, 0) = (1, 0, 0). The answer is (1,0,0)(1, 0, 0).

QuestionWhy does a smaller relaxation parameter γ\gamma make a feature harder to reuse across steps?Show answer

The prior after step ii is multiplied by (γ−M[j])(\gamma - \mathbf{M}[j]) at each step. With a smaller γ\gamma the factor for a feature that already has a large mask is smaller, so less budget remains for later steps. At γ=1\gamma = 1 a feature fully used at one step has factor 0 afterward.

QuestionOn Forest Cover Type the paper reports TabNet 96.99% and AutoML Tables 94.95%. What is the gap in percentage points, and what does it say about the sparsity penalty?Show answer

The gap is 96.99−94.95=2.0496.99 - 94.95 = 2.04 percentage points. The sparsity penalty is a separate ablation: removing it gives 96.50%, a drop of 0.49 points, so most of the margin over AutoML Tables does not depend on the penalty alone.

QuestionA team wants a per-row explanation of a loan decision made from a 40-column table. Would per-step TabNet masks help, and what caution applies?Show answer

Yes, the masks show which features each step attended to for that row, and they can be aggregated into a feature importance. The caution is that masks are soft weights inside a network, not causal effects, and the explanation describes the model's behaviour rather than the real-world cause. Validate the explanation against the model before relying on it.

Sources

Read the full paper

Sercan O. Arik, Tomas Pfister, 2019. arXiv:1908.07442