Conditional Set Generation with Transformers

Adam R. Kosiorek, Hyunjik Kim, Danilo J. RezendearXiv 2020

Introduction

Predicting sets of unordered items—such as bounding boxes in an image or point clouds representing 3D objects—is a fundamental challenge in machine learning. Unlike sequences or vectors, sets are unordered collections. Standard neural networks, which typically output ordered data, face the "responsibility problem": small changes in the target set can necessitate large, discontinuous changes in the model's ordered output, hindering convergence and performance.

Previous approaches like the Deep Set Prediction Network (DSPN) addressed this by using an internal gradient-descent loop to iteratively refine a set. However, DSPN is computationally expensive due to multiple backward passes during inference and often fails to accurately predict the number of elements in a set (cardinality).

Methods: The Transformer Set Prediction Network

The authors propose the Transformer Set Prediction Network (TSPN) to overcome these limitations. TSPN replaces the slow iterative optimization of DSPN with a fast, expressive Transformer architecture.

Comparison between the iterative gradient-based DSPN (left) and the proposed Transformer-based TSPN (right).

The TSPN generation process follows four main steps:

  1. Encoding: An input (e.g., an image) is mapped to a latent embedding.
  2. Size Prediction: A dedicated Multi-Layer Perceptron (MLP) predicts the set size ($N$) directly from the embedding.
  3. Initialization: $N$ points are sampled from a Gaussian distribution.
  4. Refinement: These points, concatenated with the input embedding, are processed by a Transformer. The Transformer's self-attention mechanism ensures permutation equivariance, refining the initial noise into the final set in a single forward pass.

Key Insights

Solving the Cardinality Problem

A major contribution of this work is identifying why previous models like DSPN struggled with set size. DSPN typically uses zero-padding to handle varying set sizes during training. Under standard losses like Chamfer distance, predicting extra zeros is not penalized, leading to ambiguity in the learned cardinality. TSPN avoids this by explicitly predicting the set size $N$ and generating exactly that many elements.

Extrapolation Capabilities

Because TSPN decouples size prediction from element generation, it exhibits remarkable extrapolation. For instance, on the SET-MNIST task, a model trained on sets with a maximum of 342 points successfully generated coherent point clouds with up to 1,000 points at test time.

Experimental Results

TSPN was evaluated on SET-MNIST (2D point cloud reconstruction) and CLEVR (object detection).

Reconstruction results on SET-MNIST. TSPN accurately predicts the set size (cardinality), whereas DSPN variants struggle significantly.

On SET-MNIST, TSPN achieved a Chamfer loss of $5.42 \times 10^{-5}$, significantly lower than DSPN's $8.2 \times 10^{-5}$. Most notably, the Set Size Root Mean Square Error (RMSE) improved from 165 for DSPN to just 0.8 for TSPN, demonstrating near-perfect cardinality prediction.

On CLEVR, TSPN outperformed DSPN in object detection, achieving an AP50 of 81.2 compared to 67.7. The set size RMSE also saw a dramatic improvement (0.58 vs. 2.53), confirming the model's robustness in identifying the correct number of objects in a scene.

Conclusion

TSPN provides a computationally efficient and accurate framework for conditional set generation. By leveraging the permutation-equivariant properties of Transformers and explicitly modeling set cardinality, it resolves the bottlenecks of previous gradient-based methods. Future work includes scaling to large-scale real-world point clouds and integrating TSPN into fully generative frameworks like VAEs or GANs.

Summary updated

BibTeX
@misc{kosiorek2020conditional,
  author = {Adam R. Kosiorek and Hyunjik Kim and Danilo J. Rezende},
  title = {{Conditional Set Generation with Transformers}},
  year = {2020},
  eprint = {2006.16841},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2006.16841},
}
Figure