TabK: Amortized Bayesian Estimation of the Number of Clusters in Tabular Data

Mohammadreza Bakhtyari, Bogdan Mazoure, Renato Cordeiro de Amorim, Guillaume Rabusseau, Vladimir Makarenkov

TL;DR

Clustering algorithms are ubiquitous, yet almost all of them force you to guess the hardest part up front: the number of clusters, $k$. Instead of running painfully slow, brute-force grid searches over candidate values, TabK uses a permutation-invariant Transformer trained purely on synthetic data to look at an entire tabular dataset and predict $k$ in a single, sub-second forward pass. It cuts prediction error in half compared to the closest competitor while running up to $30\times$ faster than classic statistical heuristics.

What Problem Does This Paper Address?

Whether you are using classic $k$-means, Gaussian Mixture Models, or modern deep clustering, partition quality hinges on knowing $k$ in advance. Historically, finding $k$ meant running a clustering algorithm over and over across a grid of guesses and scoring the results with geometric heuristics like the Elbow method, Silhouette scores, or the Gap Statistic. Not only is this computationally expensive, it introduces circular logic: your estimate of $k$ becomes biased by the specific geometric assumptions of whichever clustering algorithm you used to test it.

Recently, Prior-Data Fitted Networks (PFNs) brought fast, zero-shot in-context learning to tabular data. However, existing unsupervised PFNs like TabClustPFN try to assign individual rows to clusters and guess $k$ simultaneously. This couples global structural inference to local point assignments and requires redundant decoder passes for every candidate $k$. The authors ask: what if we decouple the problem, treating $k$ purely as a global property of the data distribution?

Methods

TabK frames $k$-estimation as amortized Bayesian inference—spending heavy compute upfront training a neural network on diverse synthetic datasets so that real-world inference requires just one fast forward pass (using a 5-model ensemble).

Because tabular rows and columns have no natural ordering, TabK introduces a double-invariant Transformer (strictly invariant to both row and column permutations) split into two phases:

Figure 1: Overview of the TabK architecture. The model processes the input matrix X via a double- invariant transformer and a Quantile Feature Encoder (QFE) for zero-shot k estimation.
  1. Feature Identity & Row Compression: Without column positions, how does a Transformer tell features apart? TabK introduces a novel Quantile Feature Encoder (QFE) that extracts evenly spaced quantiles from each column's empirical distribution. This gives every feature a fixed-size, non-parametric "statistical signature." Self-attention runs across these column signatures at a lightweight $\mathcal{O}(m^2)$ cost (for $m$ features), fusing global distribution context with raw scalar cell values before pooling them into row vectors.
  2. Dataset-Level Aggregation: A second Transformer models interactions across rows, followed by Pooling by Multihead Attention (PMA), which uses a learned seed vector to dynamically attend to representative rows—preventing small, rare clusters from being washed out by simple averaging.

Finally, because $k$ is discrete and ordered (guessing 4 when the answer is 5 is much better than guessing 14), TabK uses Deep Label Distribution Learning (DLDL), training against soft, discretized Gaussian target distributions via KL divergence rather than rigid one-hot classification.

Datasets

  • Training (Synthetic Prior): TabK never sees real data during training. The authors generated 200,000 synthetic datasets (180k train, 20k test) across five topological generators: controlled Gaussians, overlapping elliptical distributions, elongated line-supported clusters, concentric shells, and networked manifolds.
  • Evaluation (Real-World): Tested zero-shot on 50 diverse OpenML benchmarks ($n \in [57, 8124]$ rows, $m \in [3, 90]$ features, ground-truth classes $k^* \in [2, 15]$), complete with real-world messiness like missing values and categorical features. An additional 25 larger datasets from OpenML-CC18 were used to test out-of-distribution scaling.

Key Insights and Ideas

  • Decoupling wins: Treating $k$-estimation as a standalone structural precursor—rather than a byproduct of assigning points to clusters—frees model capacity and creates a universal, plug-and-play module for any downstream clustering algorithm.
  • Quantiles beat parametric moments: Replacing the QFE with standard parametric moments (like mean and variance) caused the largest drop in ablation accuracy (MAE jumped from 1.04 to 1.82). Quantiles capture weird tabular artifacts (like one-hot sparsity or median imputation spikes) without making distributional assumptions, and naturally help the model extrapolate to datasets up to $13\times$ larger than its synthetic training tables.
  • Well-calibrated uncertainty: Because TabK outputs a probability distribution over $k$, ensemble agreement acts as a reliable confidence score—when TabK is confident, its error approaches zero.
  • Topology diversity is non-negotiable: Dropping any of the five synthetic generators hurt real-world accuracy, with removing elongated, line-supported clusters causing the worst degradation (MAE spiked to 3.56).

Key Results

Across the 50 OpenML benchmarks against 17 baselines (including classical indices, adaptive algorithms, deep clustering, and self-supervised encoders), TabK dominates both accuracy and speed:

Figure 2: Empirical evaluation on 50 OpenML real-world datasets. (a) MAE distributions. (b) Average Friedman ranks (Nemenyi test, α = 0.05). (c) Cumulative accuracy at varying error tolerances (τ). (d) Efficiency-performance Pareto frontier. TabK demonstrates the highest accuracy and average ranking, the tightest error distribution, and the lowest latency among evaluated methods.
  • Half the Error: TabK achieves a Mean Absolute Error (MAE) of 1.04, beating the closest competitor, SCARF+Calinski–Harabasz (2.14), and TabClustPFN (2.24).
  • Graceful Degradation: It hits an Exact Match rate of 50.0% (vs. 42.0% for the next best) and lands within $\pm 1$ of the true $k$ 80.0% of the time.
  • Downstream Utility: Feeding TabK's predicted $k$ into standard $k$-means recovers 92.18% of the clustering quality (Adjusted Rand Index) you would get if an oracle handed you the true $k^*$.
  • Sub-second Speed: TabK averages 0.67 seconds per dataset on a CPU—over $2\times$ faster than TabClustPFN (1.50s) and $>30\times$ faster than Silhouette (21.3s) or Calinski–Harabasz (20.5s). On CPU, TabK is faster than GPU-accelerated TabClustPFN 96% of the time.

Limitations and Future Work

In the main text, the authors note that TabK is scoped and evaluated within a specific operating window ($n \le 10,000$ objects, $m \le 200$ features, and a discrete candidate range of $k \in [2, 15]$), and highlight that in real-world tabular data, "ground-truth" $k$ is often inherently ambiguous because it relies on human class annotations as a proxy for true geometric structure. While the authors mention a thorough discussion of generative prior constraints and computational complexity, those specifics are deferred to Appendix A (not included in the main paper text), and explicit directions for future work are not discussed in the paper.

Summary updated

Abstract

Estimating the number of clusters, $k$, is a fundamental prerequisite for most clustering algorithms. Traditionally, this estimation has relied on computationally expensive grid searches over internal cluster validity indices (CVIs) or adaptive clustering algorithms, both constrained by specific statistical assumptions. We introduce TabK, a zero-shot, permutation-invariant transformer architecture that frames the estimation of $k$ as an amortized Bayesian inference problem for tabular data. TabK leverages a novel Quantile Feature Encoder (QFE) to extract position-free, content-derived representations from empirical marginal distributions. By learning a generalized structural bias over a diverse synthetic prior, TabK estimates the number of clusters in a single forward pass per ensemble member. Evaluated across 50 diverse real-world benchmarks, TabK outperforms all competing methods, achieving a mean absolute error (MAE) value of 1.04 compared to 2.14 for the closest competitor. TabK also achieves the lowest average inference time, producing estimates in less than one second on average and running $2\times$ faster than TabClustPFN and $30\times$ faster than traditional CVIs such as Silhouette and Calinski–Harabasz. *Code is available at* https://github.com/mrbakhtyari/TabK.
BibTeX
@inproceedings{bakhtyari2026tabk,
  author = {Mohammadreza Bakhtyari and Bogdan Mazoure and Renato Cordeiro de Amorim and Guillaume Rabusseau and Vladimir Makarenkov},
  title = {{TabK: Amortized Bayesian Estimation of the Number of Clusters in Tabular Data}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=vH1EUKvrHt},
}
Figure