Training large-scale classification models—like those used in natural language processing or recommendation engines—often hits a major computational bottleneck: the Softmax function. When a model must choose from millions of classes, calculating the probability for every single one during training becomes computationally ruinous.
In their paper, "Adaptive Sampled Softmax with Kernel Based Sampling," Guy Blanc and Steffen Rendle propose a clever way to speed up this process without sacrificing the model's accuracy. By introducing a kernel-based sampling method, they achieve near-optimal training quality with 10x to 100x fewer samples than standard uniform sampling.
The Problem: The Cost of Softmax and the Bias of Sampling
Standard softmax requires computing a "partition function"—a sum over all possible classes—which scales linearly with the number of classes ($n$). To avoid this $O(n)$ cost, researchers often use Sampled Softmax, which only evaluates the "correct" class alongside a small subset of $m$ "negative" classes.
The catch is that sampled softmax is inherently biased. Unless you sample classes according to their true softmax probabilities, the model won't converge to the same optimal solution as a full softmax. Most practitioners rely on simple sampling strategies (like uniform or popularity-based sampling) because they are fast. However, these require a massive number of samples to sufficiently reduce bias.
The ideal sampler would be adaptive, changing based on the input and the model's current parameters. Unfortunately, computing such an adaptive distribution is usually just as expensive as computing the full softmax itself.
The Solution: Kernel Based Sampling
The authors bridge this gap by introducing a method that is both adaptive to the model's state and computationally efficient.
1. The Kernel Trick for Samplers
They assume the model's output (the logit) is a dot product between a hidden state $h$ and a class embedding $w$. By defining a sampling distribution proportional to a non-negative kernel $K(h, w)$, they can leverage the "kernel trick."
If the kernel can be decomposed into a feature map $\phi$, the sum over all classes (the partition function) becomes a simple dot product between the query's feature map and a precomputed "summary vector" $z$:
$$q_i \propto \langle \phi(h), \phi(w_i) \rangle \implies \sum q_j \propto \langle \phi(h), \sum \phi(w_j) \rangle$$
2. Divide and Conquer Sampling
To actually draw samples in sub-linear time, the authors implement a tree-based divide-and-conquer algorithm. By storing summary vectors at each node of a binary tree, they can sample a class in $O(D \log n)$ time, where $D$ is the dimension of the kernel space.
3. The Quadratic Kernel & Absolute Softmax
The authors specifically suggest using a quadratic kernel ($K(h, w) = \alpha \langle h, w \rangle^2 + 1$) as a Taylor-like approximation of the exponential function used in standard softmax. Because this kernel is symmetric (treating positive and negative logits the same), they propose training with "Absolute Softmax"—taking the absolute value of the logits. They mathematically prove that this adjustment does not reduce the model's overall expressive power.
Key Results and Insights
The researchers evaluated their method on two distinct domains: the Penn Tree Bank (PTB) for language modeling, and YouTube10k/YouTube100k datasets for recommendation systems.
- Adaptivity is Essential: A "good" sampler must depend on the specific input and the current state of the model. Static samplers fail to capture the "hard negatives" that are most informative for training.
- Massive Sample Efficiency: On all datasets, the quadratic kernel sampler required one to two orders of magnitude fewer samples than uniform sampling to reach the same model quality.
- Rapid Bias Reduction: The quadratic sampler's performance closely tracks the "ideal" (but expensive) softmax sampler, achieving low cross-entropy even with very small sample sizes ($m$).
Interestingly, the authors found that once you have enough samples to eliminate the bias, adding even more samples doesn't significantly speed up convergence per epoch. The primary benefit of better sampling is reaching a better final loss, not necessarily getting there in fewer iterations.
Limitations and Future Work
While highly effective, the approach does have some limitations:
- Memory Overhead: Storing summary vectors for every node in a binary tree can be memory-intensive ($O(nD)$). The authors suggest using a larger branching factor for the leaves to mitigate this, reducing the overhead to $O(nd)$.
- Kernel Complexity: The quadratic kernel is only a second-order approximation. Future work could explore higher-order polynomial kernels or Random Fourier Features to better approximate the true exponential curve of softmax.
Ultimately, Kernel Based Sampling offers a highly scalable, mathematically grounded way to train massive classification models without being bottlenecked by the softmax partition function.
Summary updated