Candidates vs. Noises Estimation for Large Multi-Class Classification Problem

Lei Han, Yiheng Huang, Tong Zhang

Overview

When training machine learning models with tens or hundreds of thousands of classes, calculating the standard softmax denominator becomes a massive computational bottleneck. This paper introduces Candidates vs. Noises Estimation (CANE), a novel method that drastically speeds up both training and inference. By focusing on a small subset of highly probable "candidate" classes and sampling the rest as "noise," CANE achieves the high accuracy of an exact softmax in a fraction of the time, outperforming popular approximations like Noise-Contrastive Estimation (NCE).

The Softmax Bottleneck

In extreme multi-class classification—such as predicting the next word in a language model (which can have vocabularies of 100,000+ words) or classifying images into 10,000+ categories—the standard softmax function is impractically slow. To compute the probability of the correct class, softmax requires calculating and summing the scores of every single class in the dataset. This is an $O(K)$ operation, where $K$ is the total number of classes.

To bypass this bottleneck, researchers typically rely on sampling methods like Noise-Contrastive Estimation (NCE) or BlackOut. These methods train the model to distinguish the true class from a handful of randomly sampled "noise" classes. However, NCE suffers from high statistical variance and relies heavily on a pre-defined noise distribution. Alternatively, researchers use Tree Classifiers (like Hierarchical Softmax), which are fast ($O(\log K)$) but often suffer from noticeable drops in predictive accuracy. The authors of this paper sought a middle ground: a method with the speed of tree classifiers and the statistical efficiency of exact softmax.

The CANE Method

The authors propose Candidates vs. Noises Estimation (CANE). Instead of just comparing the true label against random noise (as NCE does), CANE dynamically selects a small subset of highly probable candidate classes for a given input. It then samples a few noise classes from the remaining pool to approximate the massive softmax denominator.

Tree structure illustrating candidate and noise selection

To make this fast in practice, CANE introduces a Beam Tree Algorithm:

  1. Tree-based Routing: The authors build a tree structure over all $K$ classes.
  2. Beam Search: During training and inference, CANE uses a fast beam search down this tree to quickly identify the top $N$ most likely candidate classes in $O(\log K)$ time.
  3. Doubly Stochastic Gradient Descent: The model updates its weights based on this small pool of candidates plus a few randomly sampled noises.

Crucially, CANE uses the tree only to quickly find candidates, not to make the final classification decision. The final gradient updates are applied to a flat classifier, avoiding the cascading errors typical of pure tree classifiers.

Key Theoretical Insights

  • NCE is a Special Case of CANE: The paper mathematically demonstrates that NCE is essentially a restricted version of CANE where the "candidate set" contains exactly one item: the true label.
  • Approaching Exact Maximum Likelihood: The authors prove a powerful theorem: if the selected candidate set successfully includes the true label with high probability, the statistical variance of the CANE estimator shrinks. It effectively approaches the exact Maximum Likelihood Estimator (MLE) of a full softmax. This explains why CANE is significantly more stable and accurate than NCE.
  • Decoupling Search from Classification: By using a tree structure strictly as a heuristic search mechanism to find candidates—rather than as a strict hierarchical decision boundary—CANE secures the $O(\log K)$ speed benefits of trees without sacrificing the accuracy of a flat classifier.

Experimental Results

The authors evaluated CANE on both image classification (Sector, ALOI, ImageNet-2010, and ImageNet-10K) and neural language modeling tasks (Penn TreeBank and Gutenberg corpus).

Test accuracy across multiple datasets comparing CANE, NCE, and BlackOut
  • Massive Speedups: On the massive ImageNet-10K dataset, training a standard Softmax model was estimated to take ~140 days. CANE finished training in just 39 hours. While NCE and BlackOut were faster to train (12-13 hours), they fell short in other areas.
  • Faster Inference: While NCE is fast to train, it is notoriously slow during inference because it still has to evaluate all $K$ classes to make a prediction. Because CANE uses a beam tree, its prediction time is logarithmic, making it vastly faster than NCE at test time.
  • Superior Accuracy: Across all datasets, CANE consistently achieved higher accuracy (in vision) and lower perplexity (in NLP) than NCE, BlackOut, and state-of-the-art tree classifiers. It converged faster and closer to the exact softmax baseline.

Limitations and Future Directions

While highly effective, the current iteration of CANE samples its "noise" classes using a fixed uniform distribution, which the authors acknowledge might not be optimal. Additionally, the tree structures used for the beam search were built using relatively simple heuristics (e.g., hierarchical clustering for images, frequency splitting for words).

Future iterations of CANE could dynamically learn and estimate the noise distribution during training, allowing the model to sample "harder" or more informative noise classes on the fly, potentially pushing performance even closer to exact softmax.

Summary updated

BibTeX
@inproceedings{han2018candidates,
  author = {Lei Han and Yiheng Huang and Tong Zhang},
  title = {{Candidates vs. Noises Estimation for Large Multi-Class Classification Problem}},
  booktitle = {International Conference on Machine Learning},
  year = {2018},
  url = {https://openreview.net/forum?id=S14L-jZ_bH},
}
Figure