Introduction
Log-linear models, such as Softmax regression and Conditional Random Fields (CRFs), are fundamental components in modern machine learning, particularly within Natural Language Processing (NLP) and Computer Vision. A significant computational challenge in these models is the calculation of the partition function—the normalization constant required to convert raw scores into probabilities. This function involves a summation over all possible states, which becomes an intractable bottleneck when dealing with vocabularies or categories numbering in the millions.
The Partition Function Problem
The standard approach to training log-linear models requires computing the sum of exponentiated scores across the entire state space for every training step. Existing mitigation strategies have notable drawbacks:
- Importance Sampling (IS): Highly dependent on a high-quality proposal distribution, which is difficult to obtain a priori.
- Gumbel-Max Trick: While mathematically elegant, exact computation is slow, and fast approximations (like MIPS-Gumbel) often suffer from high variance or inaccuracy.
- Architectural Heuristics: Methods like Hierarchical Softmax modify the model structure to improve speed, potentially compromising final performance.
Methodology: LSH as an Informative Sampler
This research introduces a novel perspective: Locality Sensitive Hashing (LSH) can be utilized as a high-quality, informative sampler. Traditionally used for sub-linear nearest neighbor search, LSH groups similar items into "buckets." The key insight is that the probability of an item being hashed into a specific bucket is a predictable, monotonic function of its similarity to the query.
The LSH Sampling Algorithm
The proposed method involves three main stages:
- Pre-processing: All possible states (e.g., word weight vectors) are organized into hash tables using an LSH family like SimHash.
- Sampling: For a given input feature vector, a single LSH query is performed. The items retrieved from the resulting buckets constitute the sample set. Note that while the resulting sample size is stochastic, sub-sampling techniques can be employed to maintain fixed sizes for hardware efficiency on GPUs.
- Estimation: An unbiased estimator is applied to calculate the partition function. By weighting each sampled item by the inverse of its inclusion probability, the method provides a mathematically rigorous estimate of the total sum.
Unlike previous Gumbel-Max-based approaches that require individual queries for every sample, this method retrieves an entire set of informative samples with a single query, achieving sub-linear complexity $O(N^\rho)$.
Experimental Evaluation
The performance of the LSH-based sampler was evaluated on two standard NLP benchmarks:
- Penn Tree Bank (PTB): A vocabulary of 10,000 words.
- Text8: A larger Wikipedia-derived dataset with a vocabulary of 44,000 words.
These datasets provide a realistic testing ground for scenarios where brute-force summation is computationally expensive.
Results and Discussion
The LSH-based estimator demonstrates superior efficiency and stability compared to existing methods. Key findings include:
- Accuracy and Stability: As shown in the Mean Absolute Error (MAE) plots, the LSH sampler consistently outperforms uniform sampling. While Exact Gumbel sampling provides the lowest error, it is computationally prohibitive for large-scale training. The LSH-based method offers a practical middle ground, providing significantly lower error than uniform sampling while maintaining sub-linear time complexity. Notably, MIPS-Gumbel approximations often exhibit higher error or instability.
- Training Efficiency: LSTMs trained using this estimator achieved perplexity scores nearly identical to brute-force methods while processing only 1-2% of the total states.
- Negative Covariance: A unique benefit of LSH sampling is that samples are negatively correlated. Due to geometric properties (the triangle inequality), if one item is sampled, highly similar items are less likely to be redundant in the same set, reducing the overall variance of the estimate.
Conclusion
By reframing LSH as a sampling mechanism rather than just a search tool, this work provides a robust and unbiased solution to the partition function bottleneck. The method's sub-linear efficiency and high accuracy make it a viable alternative for scaling log-linear models to massive state spaces without the need for architectural compromises. Future research may explore different LSH families to further optimize estimates for diverse data geometries.
Summary updated