Extreme Classification in Log Memory.

Qixuan Huang, Yiqiu Wang, Tharun Medini, Anshumali ShrivastavaarXiv 2018

TL;DR

MACH (Merged-Averaged Classifiers via Hashing) is a novel algorithm that slashes the memory requirements of extreme multi-class classification from linear to logarithmic scales. By using universal hashing to map thousands of classes into a few "meta-classes," MACH allows researchers to train models with over 100,000 classes on a single consumer GPU, achieving state-of-the-art accuracy with up to a 480x reduction in model size.

What Problem Does This Paper Address?

In the world of "extreme" classification—think predicting the next word in a billion-word vocabulary or categorizing products into hundreds of thousands of labels—the primary bottleneck isn't just compute; it's memory.

Traditional "one-vs-all" (OAA) classifiers require storing a weight vector for every single class. If you have $K$ classes and $d$ features, your memory footprint is $O(Kd)$. For a dataset like ODP (100,000 classes and 400,000 features), a simple linear model requires roughly 160 GB of RAM. This far exceeds the capacity of even high-end GPUs, forcing researchers to rely on massive, expensive distributed clusters. While tree-based methods exist to speed up inference, they often double the memory requirements, making the deployment of these models a logistical nightmare.

Methods

The authors introduce MACH (Merged-Averaged Classifiers via Hashing), a divide-and-conquer approach rooted in randomized algorithms.

  1. Hashing into Buckets: Instead of training $K$ separate classifiers, MACH uses a 2-universal hash function to map the $K$ classes into $B$ small buckets (meta-classes), where $B$ is a small constant (e.g., 32 or 512).
  2. Independent Repetitions: This process is repeated $R$ times using different, independent hash functions.
  3. Parallel Training: $R$ independent classifiers are trained on these meta-classes. Because each classifier only deals with $B$ outputs, the memory footprint per model is tiny ($O(Bd)$).
  4. Probability Estimation: During inference, MACH doesn't just pick a bucket. It uses an unbiased estimator to reconstruct the probability of an original class $i$ by aggregating the predicted probabilities of the meta-classes that $i$ was hashed into across all $R$ models.

The theoretical magic lies in the fact that with $R = O(\log K)$ repetitions, the probability of two distinct classes being "indistinguishable" (hashed into the same bucket in all $R$ models) becomes vanishingly small.

Datasets

The authors evaluated MACH on two massive, publicly available benchmarks:

  • ODP (Open Directory Project): A text dataset with 105,033 classes and 422,713 features.
  • Fine-grained ImageNet: An image feature dataset with 21,841 classes and 6,144 features.

These datasets were chosen specifically because they represent the "extreme" scale where traditional methods struggle or fail on single-node hardware.

Key Insights and Ideas

  • The Logarithmic Leap: The most significant insight is that we don't need linear memory to distinguish between $K$ classes. By moving to $O(d \log K)$ memory, the authors bring massive problems down to the scale of a single GPU.
  • Sketching Connection: The authors bridge the gap between "heavy hitters" in data stream literature and machine learning. They show that MACH is essentially a Count-Min Sketch in disguise, applied to probability vectors.
  • Embarrassing Parallelism: Because the $R$ classifiers are completely independent, training is "embarrassingly parallelizable." You can train them sequentially on one GPU or simultaneously across $R$ GPUs with zero communication overhead during the training phase.
  • No Structural Assumptions: Unlike many extreme classification methods that assume a hierarchy or relationship between classes, MACH makes no such assumptions, making it a generic "drop-in" algorithm for any $K$-class problem.

Key Results

  • State-of-the-Art Accuracy: On the ODP dataset, MACH achieved 19.28% accuracy, more than doubling the previous best-reported accuracy of 9% (held by a one-vs-all classifier).
  • Massive Compression: To match the 9% accuracy of the baseline, MACH required a model size of only 0.3 GB—a 480x reduction from the baseline's 160 GB.
  • Hardware Efficiency: MACH is the first algorithm to demonstrate complete training of these 100k-class datasets on a single Nvidia Titan X GPU.
  • Training Speed: Sequential training on ODP took 7 hours on one GPU. When parallelized across 25 GPUs, this time dropped to just 17 minutes.

Limitations and Future Work

  • Inference Overhead: While memory is logarithmic, the inference step still involves a $K \log K$ summation to find the argmax across all classes. While faster than $O(Kd)$, it still scales with $K$.
  • Hyperparameter Sensitivity: The performance depends on the choice of $B$ (buckets) and $R$ (repetitions). Finding the optimal "sweet spot" for the memory-accuracy tradeoff requires some tuning.
  • Deep Learning Integration: While the paper uses logistic regression as a proof of concept, the authors note the technique naturally extends to deep networks. However, the practical nuances of training deep "meta-classifiers" remain an area for further empirical study.

Summary updated

BibTeX
@misc{huang2018extreme,
  author = {Qixuan Huang and Yiqiu Wang and Tharun Medini and Anshumali Shrivastava},
  title = {{Extreme Classification in Log Memory.}},
  year = {2018},
  eprint = {1810.04254},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1810.04254},
}
Figure