Abstract
Softmax activation is commonly used to output the probability distribution over categories based on certain distance metric. In scenarios like one-shot learning, the distance metric is often chosen to be squared Euclidean distance between the query sample and the category prototype. This practice works well in most time. However, we find that choosing squared Euclidean distance may cause distance explosion leading gradients to be extremely sparse in the early stage of back propagation. We term this phenomena as the early sparse gradients problem. Though it doesn't deteriorate the convergence of the model, it may set up a barrier to further model improvement. To tackle this problem, we propose to use leaky squared Euclidean distance to impose a restriction on distances. In this way, we can avoid distance explosion and increase the magnitude of gradients. Extensive experiments are conducted on Omniglot and miniImageNet datasets. We show that using leaky squared Euclidean distance can improve one-shot classification accuracy on both datasets.
Introduction
In modern few-shot learning, models like Prototypical Networks classify images by calculating the distance between a query sample and a "prototype" (the mean vector) of a category. To turn these distances into probabilities, researchers typically apply a Softmax function over the negative distances. While squared Euclidean distance is a standard choice, it introduces a significant training bottleneck in high-dimensional feature spaces.
The Early Sparse Gradients Problem
The authors identify a hidden side effect of using squared Euclidean distance: The Early Sparse Gradients Problem.
When feature vectors have very high dimensions (e.g., 1600 dimensions in miniImageNet), the squared Euclidean distance can "explode" to very large values. When these massive distances are fed into a Softmax, the resulting log-probabilities fall into either a "saturation area" (where the gradient is nearly 0) or a "linear area" (where the gradient is nearly -1).
In both cases, the gradients become sparse and uninformative. This prevents the model from learning efficiently from the diversity of the training data, effectively setting a "barrier" to further performance gains. The "distance explosion" isn't just about the values of the features, but the sheer number of them. Summing squared differences across 1,600 dimensions makes it very easy for distances to reach the thousands, triggering Softmax saturation.
Proposed Method: Leaky Squared Euclidean Distance (LSED)
To mitigate this, the authors propose Leaky Squared Euclidean Distance (LSED). Inspired by the Leaky ReLU activation function, LSED modifies the standard squared Euclidean distance ($d_{EUC}$) to prevent it from growing too large. It uses a piecewise function defined by two hyperparameters: a threshold $s$ and a "leakage" rate $r$.
The formula is defined as:
- If $d_{EUC} \le s$: The distance remains the standard squared Euclidean distance.
- If $d_{EUC} > s$: The distance becomes $s + (d_{EUC} - s)r$.
By setting $r$ to a small value (e.g., 0.01), the distance metric becomes linear rather than squared after it passes the threshold $s$. This "squashes" the distances, pushing the log-softmax activation back into its non-linear range where gradients are non-zero and more diverse. This allows the network to distinguish between "far" and "very far" prototypes rather than treating them all as equally irrelevant.
Experimental Results
The researchers evaluated their method on two standard benchmarks for few-shot classification: Omniglot and miniImageNet.
- miniImageNet (1-shot, 5-way): Accuracy improved significantly from 48.34% to 51.74%.
- Omniglot (1-shot, 20-way): Accuracy improved from 95.14% to 95.65%.
Training curves showed that ProtoNet(LSED) achieved higher validation accuracy much earlier in the training process compared to the baseline. The problem is most acute at the start of training when the network is initialized randomly. LSED acts as a stabilizer that helps the model find a good direction before the embeddings become more "semantic" and naturally closer together.
Conclusion
LSED addresses the gradient sparsity issue inherent in high-dimensional distance-based classification. By preventing distance explosion, it ensures that gradients remain informative throughout training, particularly in the early stages. While it introduces new hyperparameters, the performance gains on standard benchmarks suggest it is a valuable modification for Prototypical Networks and potentially other distance-based architectures.
Summary updated