Extreme Classification in Log Memory using Count-Min Sketch: A Case Study of Amazon Search with 50M Products

Tharun Medini, Qixuan Huang, Yiqiu Wang, Vijai Mohan, Anshumali ShrivastavaarXiv 2019

Abstract

Extreme classification (XC) tasks, such as product recommendation or language modeling with millions of labels, often encounter a "memory wall" where model weights exceed available hardware capacity. This paper introduces MACH (Merged-Average Classifiers via Hashing), a framework that reduces the memory footprint of XC from linear to logarithmic ($O(\log K)$) relative to the number of classes. By treating classification as a Count-Min Sketch problem, MACH allows for embarrassingly parallel, zero-communication training. Experimental results on a massive Amazon search dataset with 50 million products demonstrate that MACH can train a 6.4-billion parameter model on a single machine in under 35 hours, outperforming state-of-the-art baselines in both speed and memory efficiency.

Introduction

Extreme classification involves predicting a label from a massive set of possibilities, often reaching tens of millions in industrial applications like search engines. Standard approaches, such as a softmax layer for 50 million classes, can require over 400 GB of memory just for the weights, hitting a prohibitive "memory wall." Existing solutions like embedding-based models or tree-based structures (e.g., Parabel) often suffer from expensive pairwise loss functions or heavy communication bottlenecks during distributed training.

MACH addresses these challenges by providing a way to train massive models without the prohibitive memory cost or the "communication tax" of traditional distributed systems. It achieves this by reducing the classification problem into a series of smaller, independent sub-problems.

Methods: Merged-Average Classifiers via Hashing

The core of the MACH framework is a "divide-and-conquer" strategy rooted in randomized hashing. Instead of training one massive classifier for $K$ classes, MACH employs the following steps:

  1. Hashing into Meta-Classes: A 2-universal hash function randomly assigns the $K$ classes into $B$ "buckets" (meta-classes), where $B \ll K$.
  2. Independent Repetitions: This process is repeated $R$ times (where $R \approx \log K$) using different independent hash functions.
  3. Embarrassingly Parallel Training: Each of the $R$ classifiers is trained independently to predict the meta-class. Because no information is shared during training, this enables zero-communication model parallelism across GPUs or nodes.
  4. Count-Min Sketch Inference: During prediction, the model aggregates probabilities from all $R$ classifiers. Statistically, it is unlikely for the same two classes to collide in the same bucket across all $R$ repetitions, allowing the model to "untangle" the meta-classes and identify the correct original class.
The MACH architecture: hashing $K$ classes into $B$ buckets across $R$ independent classifiers.

Key Insights and Results

MACH's most profound insight is viewing the output layer as a data stream summary. By applying Count-Min Sketch principles, the authors prove that only $O(\log K)$ memory is required to distinguish between any pair of classes with high probability. This breaks the traditional precision-memory tradeoff.

Performance on Industrial Datasets

The authors evaluated MACH on public benchmarks (ODP-105K, ImageNet-22K) and a massive private Amazon Search dataset containing 49.46 million products.

  • Scaling and Speed: On the 50M product dataset, a 6.4-billion parameter MACH model trained in just 34.2 hours on a single AWS p3.16x machine—7-10x faster than state-of-the-art baselines.
  • Accuracy: MACH outperformed Parabel and DSSM by 6% to 21% on weighted recall metrics for the Amazon dataset.
  • Efficiency: On the ODP dataset, MACH achieved a 125x reduction in model size while significantly improving accuracy over one-vs-all (OAA) baselines.
Quantitative comparison of MACH performance across ODP and ImageNet datasets.

Conclusion and Future Work

MACH demonstrates that extreme classification can be scaled to tens of millions of classes on modest hardware by leveraging randomized hashing. While training is exceptionally fast and memory-efficient, the inference step currently requires computing scores for all $K$ classes to find the argmax, which may be a bottleneck for real-time applications at even larger scales. Future work includes integrating MACH with more complex deep learning backbones, such as Transformers, and further optimizing the inference pipeline for sub-linear latency.

Summary updated

BibTeX
@misc{medini2019extreme,
  author = {Tharun Medini and Qixuan Huang and Yiqiu Wang and Vijai Mohan and Anshumali Shrivastava},
  title = {{Extreme Classification in Log Memory using Count-Min Sketch: A Case Study of Amazon Search with 50M Products}},
  year = {2019},
  eprint = {1910.13830},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1910.13830},
}
Figure