Skip navigation
Introducing e-means, an algorithm beating k-means in 10x fewer epochs.
0:00 / 1:23

Introducing e-means, an algorithm beating k-means in 10x fewer epochs.

Swann Bessa

@swann_bessa2.6K followers

Visit on X
10,231 likesDownloadOriginal post

909,950 views

Introducing e-means, an algorithm beating k-means in 10x fewer epochs. With order of magnitude wall-clock speedups, e-means is released in FAISS and needs no hyperparameter tuning beyond k. It is robust to various scales and datasets. Still skeptical ? Just try e-means [1/10]🧵

72 Comments

Comments from the original post on X (Twitter)

  • Swann Bessa's profile picture

    @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's profile picture

    @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's profile picture

    @swann_bessa

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

    82 likes

  • Swann Bessa's profile picture

    @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's profile picture

    @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's profile picture

    @swann_bessa

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

    57 likes

  • Swann Bessa's profile picture

    @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's profile picture

    @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's profile picture

    @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's profile picture

    @swann_bessa

    Woke up to e-means trending in HackerNews (Number 6) !

    84 likes

  • Makkie's profile picture

    @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's profile picture

    @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 ∿ 𝜏ENE𝜏's profile picture

    @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 🫪

  • Makkie's profile picture

    @Mrmakkie

    @swann_bessa grokfast 😅

  • Ashish Raj's profile picture

    @adven_raj

    In the era of llms ... Good to see some good old classical ML 😀

    24 likes

  • Swann Bessa's profile picture

    @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's profile picture

    @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's profile picture

    @swann_bessa

    I really appreciate it Emre, thank you so much !

    5 likes

  • Swann Bessa's profile picture

    @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

  • Luke Hutchison's profile picture

    @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