Introducing e-means, an algorithm beating k-means in 10x fewer epochs.
@swann_bessa2.6K followers
909,950 views
72 Comments
Comments from the original post on X (Twitter)

@swann_bessa
e-means is a drop-in replacement for k-means. Included in the latest FAISS 1.16.0 release: Try e-means in your browser at: Blog: ArXiV: [2/10]🧵
178 likes

@swann_bessa
e-means better escapes local minima than Lloyd, introducing stochasticity with mini-batch updates. It leverages optimization advances in deep learning and specializes them for the k-means problem. [3/10]🧵
127 likes

@swann_bessa
On embeddings datasets, e-means often beats k-means++ when starting from a random initialisation. [4/10]🧵
82 likes

@swann_bessa
No additional hyperparameters, we got you covered,. Scaling laws fitted on 75k runs, and validated on 4 different datasets, automatically pick the right batch size and step for your run. [5/10]🧵
70 likes

@swann_bessa
26 datasets, 100k to 10B points, it’s fair to say we stress-tested e-means. Check out our extensive experimentation at : [6/10]🧵
53 likes

@swann_bessa
e-means translates its epochs speedup into wall-clock speedups, both on CPU and GPU. [7/10]🧵
57 likes

@swann_bessa
For billion-scale clustering, we pair e-means with an IVF which provides another order of magnitude speedup. [8/10]🧵
58 likes

@swann_bessa
Reproduction code for the figures in our paper is available at : More insights on our blog post : [9/10]🧵
43 likes

@swann_bessa
Bonus animation for the brave readers who made it to the end. Dead-cluster revival is a key component of e-means, inspired from codebook learning in VQ-VAEs. Mini-batch clustering is sensitive to dead-clusters so it’s a key mitigation. [10/10]✅
108 likes

@swann_bessa
Woke up to e-means trending in HackerNews (Number 6) !
84 likes

@Mrmakkie
tldr; "we applied a modern deep-learning training recipe—mini-batch sampling, exponential moving averages (fading memory), cosine learning-rate schedules, and scaling laws—to k-means."
52 likes

@swann_bessa
But that training recipe had to be specialized to k-means. For example, gradient descent optimizers do not perform as well as EMA, as you can see in appendix "E Comparison with gradient-based optimizers" on our arxiv paper (
32 likes

@Clybius
@Mrmakkie Do you think second-order gradient descent optimization techniques may also be translatable to k-means optimization? inb4 people start applying approximated hessian inverses

@Mrmakkie
@swann_bessa grokfast 😅

@adven_raj
In the era of llms ... Good to see some good old classical ML 😀
24 likes

@swann_bessa
That was the intent of this project, back to basics in a way. But at the same time we are leveraging optimization components from the modern deep learning literature to achieve the best performance.
15 likes

@emre_kuru_
Great work! This is also one of the best visualizations of a paper i think i've ever seen !
11 likes

@swann_bessa
I really appreciate it Emre, thank you so much !
5 likes

@swann_bessa
Video made with Manim from the great @3blue1brown. Special thanks to @_Shaamallow @Theo_Vincent_ @loiccabannes and @hector_grhv for their feedback on the animations !
9 likes

@LH
This is a very big deal... I have implemented k-means by hand more times than I can count, and its quirks and instability were always frustrating. Great work -- what a breakthrough!
6 likes


























