Leaner Transformers Can Easily Learn to Cluster
Organizations: MIT · IBM Research
Abstract
Transformers have in-context learning capabilities, where some known learning algorithms can be executed in the forward pass through the model. Recent work shows that transformers can exactly perform Lloyd's algorithm for -means clustering with points in dimensions with an embedding size (thus, requiring attention projection matrices of size ). In this work, we build upon this result in the following ways: First, we present an equally expressive but smaller transformer that executes Lloyd's algorithm with embedding size . Next, we train these transformers to learn the clustering algorithms given a distribution of clustering tasks, and theoretically characterize and empirically validate the factors affecting the convergence and in-distribution generalization of learning algorithms based on stochastic gradients. Finally, we probe the general clustering abilities of these learned algorithms (in the form of transformers), and try to understand situations where they succeed and fail.
Figures & tables
| Forward pass (ms) | Backward pass (ms) | GPU memory usage (MB) | ||
|---|---|---|---|---|
| OH / BN | OH / BN [speedup] | OH / BN [speedup] | OH / BN [reduction] | |
| 6 | 6 / 3 | 4.25 / 4.83 [0.88 ] | 9.53 / 10.66 [0.89 ] | 419.93 / 416.29 [0.9%] |
| 25 | 25 / 5 | 5.24 / 4.99 [1.05 ] | 11.21 / 11.01 [1.02 ] | 441.08 / 423.23 [4.0%] |
| 100 | 100 / 7 | 9.76 / 4.52 [2.16 ] | 20.21 / 9.93 [2.03 ] | 532.96 / 447.04 [16.1%] |
| 400 | 400 / 9 | 38.68 / 7.89 [4.90 ] | 66.13 / 16.47 [4.02 ] | 1095.60 / 531.02 [51.5%] |
| 1000 | 1000 / 10 | 193.07 / 15.90 [12.14 ] | 308.28 / 32.33 [9.54 ] | 3930.34 / 1207.75 [69.3%] |
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
| Term | Description |
|---|---|
| Number of query tokens | |
| Number of key tokens | |
| Upper-bound on the query token norms | |
| Upper-bound on the key token norms | |
| Upper-bound on the spectral norm of the query/key projection matrix | |
| Upper-bound on the spectral norm of the value projection matrix |