Amortized Bayesian inference for clustering models

Ari Pakman, Liam PaninskiarXiv 2018

Abstract

Bayesian clustering typically relies on Markov Chain Monte Carlo (MCMC) or Variational Inference (VI), both of which face significant trade-offs between computational speed and posterior accuracy. We present the Neural Clustering Process (NCP), a novel framework that uses neural networks to perform fast, amortized Bayesian inference. By encoding natural permutation symmetries into the network architecture, NCP transforms the iterative sampling process into a single, GPU-parallelizable forward pass. Our results demonstrate that NCP matches the accuracy of exact analytical methods in low dimensions and scales effectively to high-dimensional, non-conjugate models like MNIST.

Introduction

Clustering is a foundational task in machine learning, but performing it within a Bayesian framework is computationally demanding. In a Bayesian setting, the goal is not just to find a single optimal clustering, but to characterize the posterior distribution—a measure of uncertainty regarding the number of clusters and the assignment of data points.

Traditionally, researchers have relied on MCMC for accuracy, which is sequentially slow, or VI for speed, which often relies on simplifying assumptions that sacrifice posterior richness. The NCP addresses these limitations by learning to approximate the posterior through amortized inference, allowing for independent and identically distributed (iid) samples to be generated instantly for new datasets.

The Neural Clustering Process (NCP)

The core innovation of the NCP is the decomposition of the joint probability of cluster assignments into a sequence of conditional probabilities:

$$p(c_1, \dots, c_N | \mathbf{x}) = \prod_{n=1}^N p(c_n | c_{1:n-1}, \mathbf{x})$$

To implement this using neural networks, the model must respect the fundamental symmetries of clustering. A clustering solution should remain invariant regardless of the input order of data points or the arbitrary labels assigned to clusters. The authors built three specific types of permutation invariance into the NCP architecture:

  1. Within-cluster invariance: The representation of a cluster is invariant to the shuffling of points inside it, achieved via a "Deep Sets" (summation) approach.
  2. Between-cluster invariance: The model state is invariant to swapping cluster labels.
  3. Unassigned data invariance: The prediction for the next point treats the remaining unassigned points as an unordered set.

Amortized Training

Unlike traditional methods that optimize for a specific dataset, the NCP is trained on thousands of synthetic datasets sampled from a generative model. By learning the "logic" of clustering from these known ground truths, the network generalizes to real-world data without requiring further optimization at test time.

Experimental Evaluation

The NCP was evaluated on two primary benchmarks: synthetic 2D Gaussian mixtures and high-dimensional MNIST handwritten digits.

Figure 3: Comparison of NCP and exact posteriors on 2D Gaussian mixtures (top), alongside posterior samples for a 50-point dataset (bottom).

In the 2D experiments, the NCP's predicted conditional probabilities almost perfectly matched the exact analytical posterior (as seen in the top-right of Figure 3). Furthermore, the model successfully generated diverse posterior samples for larger datasets, capturing the inherent uncertainty in cluster counts and assignments.

Non-Conjugate Clustering: MNIST

To test the model on complex, high-dimensional data, the authors applied NCP to MNIST digits. In this non-conjugate setting, the generative model involves selecting a digit class and sampling a random image from that class.

Figure 2: Posterior samples for MNIST clustering. Each row represents a different sample (K clusters, NLL score), showing how the model handles ambiguous digits.

As shown in Figure 2, the NCP correctly identifies ambiguous digits. For instance, if a "4" resembles a "9," the NCP distributes its posterior samples across both possibilities. This ability to quantify label ambiguity is a key advantage of the Bayesian approach over deterministic clustering methods.

Key Results and Discussion

  • Speed and Scalability: In a 1D clustering task, the NCP produced 20,000 samples in 184 seconds, compared to 1,969 seconds for a standard Gibbs sampler. Because the NCP is parallelizable, this gap increases with better hardware.
  • Discovery of K: Unlike K-means, the NCP naturally handles models where the number of clusters ($K$) is unknown, discovering it directly from the data distribution.
  • IID Sampling: Every sample from an NCP is independent, eliminating the need for "burn-in" periods or thinning required by MCMC chains.

Conclusion and Future Work

The Neural Clustering Process provides a powerful alternative to traditional Bayesian inference, offering the speed of variational methods with the flexibility of MCMC. While the model is dependent on the quality of the generative model used during training, its ability to learn global symmetries makes it highly robust. Future work may explore hybrid approaches, using NCP samples as high-quality seeds for MCMC refinement or integrating them into importance sampling frameworks for theoretical guarantees.

Summary updated

BibTeX
@misc{pakman2018amortized,
  author = {Ari Pakman and Liam Paninski},
  title = {{Amortized Bayesian inference for clustering models}},
  year = {2018},
  eprint = {1811.09747},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1811.09747},
}
Figure