NGAME: Negative mining-aware mini-batching for extreme classification

Kunal Dahiya, Nilesh Gupta, Deepak Saini, Akshay Soni, Yajun Wang, Kushal S. Dave, Jian Jiao, Gururaj K, Prasenjit Dey, Amit S, Deepesh Hada, Vidit Jain, Bhawna Paliwal, Anshul Mittal, Sonu Mehta, Ramachandran Ramjee, Sumeet Agarwal, Purushottam Kar, Manik Varma

Introduction

Extreme Classification (XC) is the task of tagging data points with the most relevant subset of labels from a massive pool, often reaching millions of candidates. Applications range from matching search queries to advertisements to categorizing products in massive e-commerce catalogs. While deep learning models, particularly Transformers, have become the gold standard for dense representations in XC, they face a significant bottleneck: negative mining.

Training against every incorrect label is computationally impossible. Researchers typically choose between "oblivious sampling" (fast but ineffective "easy" negatives) or "task-aware sampling" (accurate but slow "hard" negatives). The latter requires frequent, expensive recomputation of massive indices, often consuming over 200% of training time and limiting model scalability.

The NGAME Framework

NGAME (Negative Mining-aware Mini-batching) addresses this bottleneck by redefining how mini-batches are constructed. Instead of random sampling, NGAME periodically clusters data points in the embedding space using balanced hierarchical k-means.

Negative Mining-aware Mini-batching

The core innovation lies in the "Aha" moment: when a mini-batch is composed of similar items, the positive labels for one item serve as naturally "hard" negatives for others in the same batch. This allows "in-batch" negative sampling—which is computationally "free"—to achieve the effectiveness of expensive external search methods.

Visualization of negative mining-aware mini-batching logic.

The authors provide a theoretical foundation for this approach using the Triangle Inequality. Specifically, if data points $i$ and $j$ are close (within the same cluster) and label $l$ is a positive match for $j$, then $l$ is a provably "hard" negative for $i$. This justification underpins the transition from random to clustering-based batching, ensuring that the model is always challenged by informative negatives.

Modular Architecture

NGAME utilizes a two-stage modular training process to refine classification accuracy:

  1. Module M1 (Siamese Encoder): A DistilBERT-based Siamese architecture maps both data points and labels into a shared embedding space using a triplet loss.
  2. Module M2 (Classifier Refinement): The encoder is frozen, and a specific "refinement" vector $\Delta \mathbf{w}_l$ is learned for each label to fine-tune the final classification scores.
The NGAME architecture featuring two modules: M1 for Siamese encoding and M2 for classifier refinement.

To stabilize early training, NGAME employs curriculum learning. Initially, the model uses smaller clusters, which provide "easier" negatives. As the encoder improves and embeddings become more discriminative, the cluster size is increased. This progressively introduces "harder" negatives, preventing the model from collapsing or failing to converge during the volatile early stages of training.

Experimental Results

NGAME was evaluated across several standard XC benchmarks and a massive real-world dataset, PR-85M, containing 85 million labels.

  • Accuracy: NGAME demonstrated up to a 16% improvement in Precision@1 over previous state-of-the-art Siamese methods like SiameseXML. On full-text datasets, it outperformed Transformer-based methods like XR-Transformers by up to 13%.
  • Efficiency and Scale: By reducing negative mining overhead from 210% to just 1%, NGAME trained on the 85-million-label PR-85M dataset in under 50 hours using 6x A100 GPUs.
  • Tail Label Performance: The Siamese setup, which incorporates label text metadata, allows NGAME to excel at "tail labels"—rare labels with few training examples—by understanding their semantic meaning even when data is scarce.

Conclusion and Impact

NGAME represents a significant step forward in scaling Extreme Classification. In live A/B tests on a major search engine, the framework delivered a 23% gain in click-through rates (CTR) for personalized ads. By making hard-negative mining a byproduct of mini-batch construction rather than a separate, costly step, NGAME enables the training of more powerful models on larger datasets than ever before.

Summary updated

BibTeX
@misc{dahiya2022ngame,
  author = {Kunal Dahiya and Nilesh Gupta and Deepak Saini and Akshay Soni and Yajun Wang and Kushal S. Dave and Jian Jiao and Gururaj K and PRASENJIT DEY and Amit S and Deepesh Hada and Vidit Jain and Bhawna Paliwal and Anshul Mittal and SONU MEHTA and Ramachandran Ramjee and Sumeet Agarwal and Purushottam Kar and Manik Varma},
  title = {{NGAME: Negative mining-aware mini-batching for extreme classification}},
  year = {2022},
  eprint = {2207.04452},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2207.04452},
}
Figure