Lesson 15 of 227 min
Tabular foundation models
A model trained in advance on millions of made-up tables reads your rows and answers at once, with no training: on small tables it often beats boosted trees.
After this lesson you can predict on a small table with a pretrained model and no training (TabPFN, TabICL).
Loading the video…
Refreshers
An idea from an earlier lesson shows up here when the video leans on it.
In real code
What the video left out, as you will meet it in your own code.
Read the rows once
Every predict_proba reads the whole table again. With kv_cache=True, fit does that reading once and keeps it, so each later prediction is faster. It costs memory, and fit takes longer. Put bank-additional-full.csv from UCI Bank Marketing next to your notebook. TabICL on GitHub
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
from tabicl import TabICLClassifiercalls = pd.read_csv("bank-additional-full.csv", sep=";")
words = ["job", "marital", "education", "default", "housing", "loan", "contact", "poutcome"]
X = calls[words + ["age", "campaign", "pdays", "previous"]].astype({c: "category" for c in words})
y = calls["y"].eq("yes")
X_rest, X_test, y_rest, y_test = train_test_split(X, y, test_size=1000, stratify=y, random_state=0)
X_small, _, y_small, _ = train_test_split(X_rest, y_rest, train_size=2000, stratify=y_rest, random_state=0)import time
for cache in [False, True]:
model = TabICLClassifier(kv_cache=cache, random_state=0)
start = time.perf_counter(); model.fit(X_small, y_small); fit = time.perf_counter() - start
start = time.perf_counter(); chances = model.predict_proba(X_test)[:, 1]; pred = time.perf_counter() - start
print(f"kv_cache={cache}: fit {fit:.1f} s, predict {pred:.1f} s, AUC {roc_auc_score(y_test, chances):.3f}")kv_cache=False: fit 2.2 s, predict 3.2 s, AUC 0.733 kv_cache=True: fit 4.3 s, predict 1.1 s, AUC 0.733
A table too big for memory
The more rows it reads, the more memory it needs. Our 20,000-row run filled a 32 GB Mac and was stopped. offload_mode="disk" keeps the biggest part on disk, and a smaller batch_size holds less at once. It is slower, and the score does not change.
big = TabICLClassifier(offload_mode="disk", disk_offload_dir="tabicl-offload",
batch_size=2, random_state=0)
big.fit(X_small, y_small)
print(round(roc_auc_score(y_test, big.predict_proba(X_test)[:, 1]), 3))0.733
Predict a number
For a number, use TabICLRegressor. Here it predicts a penguin's mass from the rest of its row, beside boosted trees with their settings as they come. Put penguins.csv from Palmer Penguins next to the notebook. The first call downloads the regressor's weights.
from tabicl import TabICLRegressor
from sklearn.ensemble import HistGradientBoostingRegressor
from sklearn.metrics import root_mean_squared_error
penguins = pd.read_csv("penguins.csv").dropna()
Xp = penguins[["species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "sex"]]
Xp = Xp.astype({"species": "category", "island": "category", "sex": "category"})yp = penguins["body_mass_g"]
Xp_train, Xp_test, yp_train, yp_test = train_test_split(Xp, yp, test_size=0.25, random_state=0)
reg = TabICLRegressor(random_state=0).fit(Xp_train, yp_train)
trees = HistGradientBoostingRegressor(random_state=0).fit(Xp_train, yp_train)
print("TabICL", round(root_mean_squared_error(yp_test, reg.predict(Xp_test))), "g")
print("trees ", round(root_mean_squared_error(yp_test, trees.predict(Xp_test))), "g")TabICL 295 g trees 327 g
Fine-tune it on your own tables
You can also train a pretrained model a little more, on tables like yours. TabICL ships this as an extra, with FinetunedTabICLClassifier and FinetunedTabICLRegressor. Try it only after the model as it comes, scored on the same validation set. Fine-tuning in TabICL's README
pip install "tabicl[finetune]"TabPFN, and reading a license
TabPFN was the first tabular foundation model. Its code is open (Apache 2.0), but its newest weights, TabPFN-2.5 to 3.5, are for non-commercial use only, and it asks you to sign in at Prior Labs first. TabICL's code and weights are BSD-3: any use. Read the license before you build on a model. TabPFN on GitHub
pip install tabpfnRun on Python 3.13.3, tabicl 2.2.0 (TabICLv2), scikit-learn 1.9.1, pandas 3.1.1, PyTorch 2.15.0, on a Mac. Checked on .
Quiz
Two questions on this lesson, and one from earlier. Answer as often as you like.
1 of 3
From earlier: Gradient boosting
A penguin's guess is the average, 4,203 grams. It really weighs 4,850. The next tree, learned on the misses, answers +875 grams for its pile. The learning rate is a tenth. What is the penguin's new guess?
2 of 3
Table one has 1,500 rows. Table two has 500,000 rows, and each answer must come back at once. Which model do you try first on each?
3 of 3
A pretrained model reads 1,000 training calls and is scored on 5,000 others: 0.732. Then it's given those 5,000 to read as well, and scored on them again: 0.839. Which number do you trust?
The ideas in this lesson
- The rows as its prompt
- It reads your training rows together with the new rows and gives their chances in one pass; nothing inside it changes.
- Tabular foundation model
- A model trained in advance on millions of made-up tables, so it predicts on a new table with no training of its own.
- Boosted trees or a pretrained model
- On a small table, try a pretrained model first and read its licence; on a big table, or for fast cheap answers, boosted trees.
It leans on
- In-context learning
Transcript
What the video says, part by part. Press a time to watch from there.
Is XGBoost still the best?
Here's a question. For years, boosted trees like XGBoost won on tables. Now there's a new kind of model. It never trains on your table. It reads your table, and answers. On small tables, it often wins. So are boosted trees still the best?
A test on a real table
Hold on to your guess. Here's a test on a real table: a bank's phone calls. The job is to say which customers will say yes to an offer. Each model gets the same thousand calls. Then it's scored on five thousand others, by the area under the ROC curve. A coin would get one half. A perfect model gets one. Two of the models are boosted trees, the kind XGBoost makes. One has its settings as they come. The other has its settings tuned on folds of the thousand calls. The third model never trains on these calls at all. In gray, a plain model, for comparison. Which one wins?
It never trained
The model that never trains, TabICL, comes first: about zero point seven three.
The tuned boosted trees: zero point seven.
As they come: lower still.
We drew five tables of a thousand calls, and it won on all five. It never trained on any of them.
It keeps, then reads
So how can it win with no training? It's a model trained in advance on tables, and it never trains on yours. Like every model, it has fit and predict. So when does it do its work? When you call fit, or when you ask for predictions?
When you call fit, it only keeps the rows.
When you ask for predictions, it reads all the training rows, together with the new rows, in one pass.
Out comes each new row's chance of a yes.
Nothing inside the model changes.
The rows are its prompt
So the rows are its prompt. It's like giving a chatbot a few examples in your message. It follows them, and nobody trained it again. This is called in-context learning.
Trained in advance
This model reads a table's rows and predicts, with no training of its own. So where did it learn to read a table?
A program made up millions of tables. Here's a tiny one: four rows, three with their answers shown, and one hidden.
The model guessed the hidden answer, and it was scored. Then the numbers inside the model were changed to do better.
Again and again, on table after table. So it learned how to learn from a table, any table. It's like someone who has filled out hundreds of forms: they understand a new one right away. It has never seen a real table.
A model trained like this is called pretrained. For tables, it's called a tabular foundation model. TabPFN was the first. TabICL is the one we ran.
The trees catch up
A pretrained table model, against boosted trees.
Does it always win?
Let's make the table bigger. What happens?
The tuned trees catch up. With five thousand calls, the two score about the same: zero point seven five. With ten thousand calls, the same again.
Many tables
On one table, that could be luck.
TabArena is a public leaderboard that ranks models on many tables.
Each model gets a rating: higher means it wins more often. A hundred and forty-two tables, by size.
On the bank's calls, the trees caught up by five thousand rows. Across many tables, it's a little later.
Up to ten thousand rows, pretrained models are at the top, and TabICL is still ahead of the tuned boosted trees. On bigger tables, the boosted trees catch up with it. Past a hundred thousand rows, models tuned on the table lead, including boosted trees.
And TabICL falls near the bottom.
The seconds
What does it cost? Every time you ask it for predictions, it reads the whole table again. Five thousand predictions take about four seconds with a thousand rows, on a Mac's graphics chip. With ten thousand rows, they take twenty to thirty seconds. Boosted trees take under a tenth of a second. The bigger the table, the longer it takes.
A leak
No training. So, no checking? Let it read the five thousand calls it's scored on, too. Guess its score.
About zero point eight four. That's too good to be true. It read their answers. It's a leak, just like with any model. The rows you score on have to stay out of the table it reads.
The license
Can you use it for anything?
Read its license: it says what you're allowed to use it for.
TabICL's license is open, for any use. TabPFN's newest models are for non-commercial use only. So is the leader of TabArena's small tables.
In code
In real code, it's the same pattern again: fit, then predict.
It gets two thousand calls.
Then we open the test set, a thousand other calls kept aside, just once.
Guess its area under the curve.
About zero point seven two, on the thousand test calls.
The tuned boosted trees, with the same two thousand calls: zero point seven. The fit took under half a second, and predicting took a few seconds. The trees predicted in a hundredth of a second.
Which one to try
So, which one do you try?
Up to about ten thousand rows, try a pretrained model first, alongside tuned boosted trees.
And read its license. Past a hundred thousand rows, use boosted trees.
Use them too when answers have to come back right away, and cheaply.
In between, try both.
Either way, keep a validation set to choose with, and a test set the model never reads.
The lab
That's the end of this unit. In the lab, you use these two lessons to race boosted trees against a pretrained model, on your own computer.
Small table, try it first
A model trained on many tables can read yours, and answer. Now try it on this lesson's page, and take the quiz. Find where the trees catch up.
You use this lesson in Lab 5: Boosted trees or a pretrained model?, which comes next.
Facts last checked on .
