TL;DR
This paper introduces "r-softmax," a novel probability mapping function that generalizes the standard softmax by allowing for controllable sparsity in its output. This is crucial for tasks like multi-label classification and transformer attention mechanisms, where assigning zero probability to irrelevant outputs can improve interpretability and performance.
What Problem Does This Paper Address?
In many machine learning applications, neural networks output "logits" – raw scores that need to be converted into a probability distribution. The standard way to do this is with the softmax function. However, softmax has a key limitation: it always assigns a non-zero probability to every possible output. This means that even for irrelevant classes or tokens, a small probability is still assigned.
This becomes problematic in scenarios like:
- Multi-label classification: Where an input can belong to multiple categories simultaneously. With softmax, you need to set an arbitrary threshold to decide which probabilities are "high enough" to be considered positive labels, which requires extra tuning and can be suboptimal.
- Transformer attention mechanisms: These mechanisms use softmax to determine how much attention a model should pay to different parts of the input. The standard softmax forces the model to attend to everything, even irrelevant parts, which can be computationally inefficient and less interpretable.
The paper aims to address this by creating a probability mapping function that can output sparse distributions, meaning it can assign zero probability to certain outputs, making the results more interpretable and potentially more efficient.
Methods
The core contribution is the r-softmax function. It's built upon a precursor called t-softmax, which introduces a parameter t. This t controls the sparsity by effectively setting a threshold relative to the maximum logit. If a logit is too far below the maximum (by more than t), its probability is set to zero.
The r-softmax then takes this a step further by introducing a sparsity rate r. This r directly controls the fraction of outputs that should have zero probability. The paper defines r by relating it to quantiles of the input logits, allowing users to specify exactly what percentage of outputs should be zero. This r can either be set manually or learned by the model during training.
The paper also proposes a modified loss function for multi-label classification when using r-softmax, which accounts for the possibility of zero probabilities.
Datasets
The paper evaluates r-softmax on:
- Synthetic datasets: Generated using scikit-learn's
make_multilabel_classificationfunction, with varying numbers of output classes, average positive labels, and document lengths. - Real-world datasets:
- VOC 2007 and COCO for multi-label image classification.
- GLUE benchmark tasks (MRPC, RTE, SST-2, QNLI, QQP) for evaluating its use in transformer self-attention mechanisms.
Key Insights and Ideas
- Intuitive Sparsity Control: The
rparameter in r-softmax provides a direct and interpretable way to control the sparsity of the output distribution, unlike previous methods that might require more complex hyperparameter tuning. - Improved Interpretability: By allowing zero probabilities, r-softmax makes it clearer which outputs are considered irrelevant, leading to more interpretable models, especially in multi-label classification and attention mechanisms.
- Potential for Efficiency: Forcing zero probabilities can potentially reduce computational overhead in downstream tasks by allowing models to ignore irrelevant components.
- Learning Sparsity: The ability to learn the sparsity rate
r(or thetparameter in t-softmax) during training is a significant advantage, as it allows the model to adapt the sparsity to the specific task and data.
Key Results
- Multi-label Classification: r-softmax consistently outperformed other sparse alternatives like sparsemax and sparsehourglass. It was also competitive with the standard softmax, especially when the number of output classes was large. For example, on VOC and COCO datasets, r-softmax achieved an F1 score of 77.90% and 72.56% respectively, outperforming sparse alternatives and being competitive with softmax (which required careful threshold selection).
- Transformer Self-Attention: When applied to the self-attention blocks of a pre-trained BERT model, r-softmax led to improved performance across several GLUE benchmark tasks. For instance, on the MRPC task, r-softmax achieved an accuracy of 85.54%, slightly outperforming the baseline softmax (84.56%). The paper notes that introducing a small sparsity level (
raround 0.1-0.2) generally yielded the best results.
Limitations and Future Work
- Computational Cost: The r-softmax version, particularly when learning
rvia quantiles, introduces a computational overhead due to the need for sorting the input vector. The paper suggests the t-softmax version might be a more suitable option when computational complexity is a primary concern. - Learning Sparsity: While learning sparsity is beneficial, the paper notes that learning the appropriate sparsity rate
rcan sometimes require a bit more training time compared to models where sparsity is fixed or not applicable. - Future Work: The paper suggests that the learned sparsity rate
rcan be a valuable indicator of the model's confidence or the number of relevant outputs. Further exploration of this interpretability aspect could be a fruitful direction.
Summary updated