Abstract
Many machine learning tasks require sampling a subset of items from a collection based on a parameterized distribution. The Gumbel-softmax trick can be used to sample a single item, and allows for low-variance reparameterized gradients with respect to the parameters of the underlying distribution. However, stochastic optimization involving subset sampling is typically not reparameterizable. To overcome this limitation, we define a continuous relaxation of subset sampling that provides reparameterization gradients by generalizing the Gumbel-max trick. We use this approach to sample subsets of features in an instance-wise feature selection task for model interpretability, subsets of neighbors to implement a deep stochastic k-nearest neighbors model, and sub-sequences of neighbors to implement parametric t-SNE by directly comparing the identities of local neighbors. We improve performance in all these tasks by incorporating subset sampling in end-to-end training.
Introduction
Selecting a specific group of items from a larger set is a fundamental operation in many machine learning tasks. Examples include feature selection (identifying the most influential words in a review), k-nearest neighbors (determining which neighbors should influence a classification), and dimensionality reduction (identifying "true" neighbors in high-dimensional space).
The primary challenge is that "selecting" is a discrete, "hard" operation. In deep learning, discrete operations are non-differentiable, preventing the calculation of gradients necessary for end-to-end training. While the Gumbel-Softmax trick addresses this for single-item selection, subset selection typically faces a combinatorial explosion if every possible combination is treated as a separate category. This paper introduces a framework to make subset sampling completely differentiable.
Methodology: Relaxed Subset Sampling
The authors propose Relaxed Subset Sampling, a framework that generalizes the Gumbel-max trick to subsets. The process involves several key steps:
- Weighted Reservoir Sampling (WRS): The method starts with an algorithm that samples $k$ items without replacement by assigning random "keys" to items based on their weights and selecting the top $k$.
- Gumbel-max Extension: By adding Gumbel noise to the log-weights (logits) of items and then selecting the top $k$, the method effectively samples from various subset distributions.
- Continuous Relaxation: To enable differentiability, the "hard" top-$k$ operation is replaced with a RelaxedTopK function. This function utilizes successive applications of the softmax function to produce "relaxed" $k$-hot vectors, where elements range between 0 and 1 but sum to $k$.
A significant theoretical contribution is the proof that this relaxation is "consistent." At appropriate temperatures, the items with the highest initial weights are indeed those that receive the highest values in the relaxed output.
Experiments and Datasets
The framework was evaluated across several domains and datasets:
- IMDB Dataset: For instance-wise feature selection in movie reviews.
- MNIST & Fashion-MNIST: For testing stochastic k-nearest neighbors and neighbor embeddings.
- CIFAR-10: For evaluating deep stochastic k-NN performance.
- 20 Newsgroups: For testing stochastic neighbor embeddings on text data.
Key Results
The proposed method demonstrates significant improvements in both performance and scalability:
- Feature Selection: On the IMDB word-level task, RelaxSubSample achieved 91.7% post-hoc accuracy, surpassing the previous state-of-the-art L2X (90.7%).
- Scalability: The method is substantially faster than competing relaxations. For selecting 5 neighbors out of 5,000 candidates, RelaxSubSample was over 30x faster than NeuralSort (0.110s vs 3.694s).
- Stochastic k-NN: On CIFAR-10, the method improved classification accuracy by 0.6% over the NeuralSort implementation using the same architecture.
- Visualization (RSS-SNE): The Relaxed Subset Sampling Stochastic Neighbor Embedding (RSS-SNE) method produced embeddings with higher "Trustworthiness" scores compared to standard parametric t-SNE.
Discussion and Key Insights
A major insight from the RSS-SNE experiments is that matching neighbor rankings is often more robust than matching raw distances. This approach allows for effective neighbor embedding without requiring the "Student-t" distribution typically used in t-SNE to mitigate the "crowding problem."
Furthermore, the method enables end-to-end sparsity. It allows models to learn a sparse selection of features while ensuring exactly $k$ features are considered, preventing models from "cheating" by sampling the same feature multiple times.
Limitations and Future Work
- Distribution Family: The method samples from a "restricted family" of subset distributions reachable via WRS, which may not capture all complex dependencies.
- Temperature Sensitivity: The choice of temperature ($t$) is a critical hyperparameter. High temperatures provide stable gradients but "blurry" selections, while low temperatures yield sharp selections but risk vanishing gradients.
- Future Directions: Potential applications include hard-attention mechanisms in computer vision and subset selection for nodes in graph neural networks.
Summary updated