Categorical Feature Compression via Submodular Optimization

MohammadHossein Bateni, Lin Chen, Hossein Esfandiari, Thomas Fu, Vahab S. Mirrokni, Afshin Rostamizadeh

In large-scale machine learning applications like product recommendations or ad-click prediction, categorical features are both a blessing and a curse. A single feature, such as "User ID" or "Product ID," can possess tens of millions of unique values. While these high-cardinality features contain rich predictive signals, they create massive vocabularies that lead to bloated, memory-intensive models. For example, the widely used Criteo dataset contains 28 million unique categorical values; a modestly sized embedding layer for this vocabulary would require over a billion parameters, easily dwarfing the rest of the neural network.

This paper introduces a scalable, mathematically principled approach to shrink these massive vocabularies while preserving the critical information needed for accurate prediction.

The Problem with Existing Compression Heuristics

When engineers face high-cardinality categorical features, they typically resort to two heuristic extremes:

  1. Feature Hashing: This is fast and memory-efficient but causes "collisions" that blur distinct predictive signals together.
  2. Frequency Filtering: This involves keeping only the most common values and grouping the long tail into an "Other" bucket. While simple, it ignores the fact that a rare value might be highly predictive of a specific outcome.

The ideal objective is Mutual Information (MI) Maximization: mapping the original $n$ values to a much smaller set of $m$ new values ($m \ll n$) such that minimal information about the target label is lost. While optimal solutions for this exist via dynamic programming, their $O(n^2)$ or $O(n^3)$ complexity makes them entirely impractical for vocabularies in the tens of millions.

A Scalable Solution via Submodularity

The authors bridge the gap between theoretical optimality and production-scale data by framing the compression task as a Submodular Optimization problem.

1. 1D Partitioning via Conditional Probability

The foundational step relies on a known property for binary classification: the optimal way to group categories is to first sort them by their probability of the positive label ($Pr[C=1|X=i]$). Once sorted into a 1D sequence, the optimal compression strategy will always consist of contiguous "blocks" of these sorted values.

2. Proving Submodularity

The core theoretical contribution of the paper is defining a set function $F(S)$, where $S$ represents the set of boundaries between these contiguous blocks. The authors rigorously prove that this function is submodular. In practical terms, submodularity implies "diminishing returns": adding a new boundary to a small set of existing boundaries yields a greater information gain than adding it to a large, already-fragmented set.

3. The Greedy Algorithm

Because the objective function is submodular, a simple greedy algorithm—repeatedly selecting the boundary that provides the maximum information gain—is mathematically guaranteed to achieve a solution within $(1 - 1/e)$, or roughly 63%, of the global optimum.

By utilizing a specialized red-black tree data structure, the authors reduce the time to find the best boundaries to $O(\log n)$ per step, achieving an overall runtime of $O(n \log n)$. They also introduce a distributed version that decomposes the search space across multiple machines, making it highly scalable.

Key Results

The primary evaluation was conducted on the Criteo click prediction dataset, which features 37 million training instances and a combined vocabulary of over 28 million unique values.

Mutual Information Retention

The submodular approach was compared against several baselines, including iterative divisive clustering. As shown below, the submodular method maintains significantly higher mutual information (lower MI loss) across various compression levels. Because the y-axis is on a log scale, this represents an improvement by orders of magnitude.

Average MI loss across different vocabulary sizes

End-to-End Predictive Performance

Information retention is only useful if it translates to better model performance. When the compressed features were used to train a real neural network, the submodular method consistently achieved a lower log-loss (better predictive accuracy) compared to the industry-standard frequency-based filtering heuristic.

Log-loss of a neural network trained with compressed vocabularies

Limitations and Future Directions

While highly effective, the approach has a few notable limitations:

  • Binary Labels Only: The mathematical proof of submodularity relies on the target label being binary. For multiclass problems, the 1D sorting trick does not apply, making the problem NP-hard.
  • Probability Estimation: The algorithm depends on accurate estimates of $Pr[C|X]$. For extremely rare categories, these estimates can be noisy. Future work could explore more robust Bayesian estimation techniques.
  • Static Pre-processing: Currently, this compression is a static pre-processing step. Integrating this optimization directly into the end-to-end training loop of a neural network remains an open challenge.

Summary updated

BibTeX
@inproceedings{bateni2019categorical,
  author = {MohammadHossein Bateni and Lin Chen and Hossein Esfandiari and Thomas Fu and Vahab S. Mirrokni and Afshin Rostamizadeh},
  title = {{Categorical Feature Compression via Submodular Optimization}},
  booktitle = {International Conference on Machine Learning},
  year = {2019},
}
Figure