Provably Robust Metric Learning

Lu Wang, Xuanqing Liu, Jinfeng Yi, Yuan Jiang, Cho-Jui Hsieh

Abstract

Metric learning is essential for optimizing $K$-Nearest Neighbor ($K$-NN) classifiers and similarity searches by finding a distance measurement—typically a Mahalanobis distance—that clusters similar items together. However, existing metric learning algorithms often produce models that are significantly more fragile than simple Euclidean distance. We present Adversarially Robust Metric Learning (ARML), the first framework designed to learn a Mahalanobis distance that is provably robust against adversarial attacks. By optimizing a differentiable lower bound of the minimal adversarial perturbation, ARML improves robustness without the typical trade-off in clean data accuracy.

Introduction

The goal of metric learning is to find a transformation of the input space where items of the same class are "close" and items of different classes are "far." While effective for accuracy, these learned metrics are often highly susceptible to adversarial perturbations—tiny, human-imperceptible changes that can flip a $K$-NN prediction. Defending $K$-NN is inherently more difficult than defending neural networks because $K$-NN functions as a discrete "step function," making gradient-based defenses and robustness verification computationally expensive or intractable.

Methodology

ARML addresses these challenges by maximizing the minimal adversarial perturbation—the smallest change required to fool the model. The framework relies on several key innovations:

  1. Differentiable Lower Bound: Since calculating the exact minimal perturbation for $K$-NN is NP-hard, the authors derived a mathematical lower bound based on a "triplet" problem: the distance from a point to the decision bisection between a "friend" (same class) and a "foe" (different class).
  2. The ARML Algorithm: This lower bound serves as a loss function. By minimizing it, the algorithm forces the Mahalanobis matrix $M$ to create wider, more stable margins around data points.
  3. Efficiency via Sampling: To overcome the $O(N^2)$ bottleneck of comparing all pairs of points, the authors introduced randnear+ and randnear- sampling. This focuses training on the most critical neighbors, allowing the algorithm to scale to larger datasets.
Comparison of decision boundaries for Euclidean, NCA, and ARML. ARML produces smoother, wider margins that are less susceptible to small perturbations.

Experimental Setup

The authors evaluated ARML against standard baselines (Euclidean, NCA, LMNN, ITML, LFDA) across six diverse datasets:

  • Image Data: MNIST and Fashion-MNIST.
  • Tabular/UCI Data: Splice, Pendigits, Satimage, and USPS.

These benchmarks range from low-dimensional feature vectors (16 features) to high-dimensional images (784 features), testing the metric's versatility across different data types.

Key Results and Insights

Breaking the Robustness Trade-off

In deep learning, increasing robustness usually results in a "no free lunch" scenario where clean accuracy suffers. ARML breaks this trend, often matching or exceeding the accuracy of standard methods on clean data while providing significantly higher safety guarantees.

Geometry and Fragility

The research confirms that popular methods like NCA and LMNN focus so heavily on class separation that they create extremely thin, jagged decision boundaries. This makes them far more vulnerable than the baseline Euclidean distance. ARML solves this by geometrically "stretching" the space to push decision bisections further from the data points.

Certified robust errors across various datasets and perturbation radii. ARML (bottom row of each section) consistently achieves the lowest error rates as the perturbation radius increases.

Certified and Empirical Strength

In 1-NN tests, ARML achieved the lowest "certified robust error" across nearly all perturbation radii. For example, on the MNIST dataset at a radius of 2.0, ARML maintained a robust error of ~0.75, whereas standard methods like NCA and LMNN reached total failure (1.0). When subjected to actual adversarial attacks, such as the Boundary Attack, ARML-trained models remained remarkably stable compared to all baselines.

Conclusion and Future Work

ARML provides a robust foundation for linear metric learning, demonstrating that provable safety does not have to come at the cost of performance. While the current framework focuses on linear Mahalanobis distances, future research may extend these provable bounds to non-linear "Deep Metric Learning" and explore optimizations for billion-scale similarity search engines. ARML represents a significant step toward making $K$-NN classifiers viable for safety-critical real-world applications.

Summary updated

BibTeX
@inproceedings{wang2020provably,
  author = {Lu Wang and Xuanqing Liu and Jinfeng Yi and Yuan Jiang and Cho-Jui Hsieh},
  title = {{Provably Robust Metric Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2020},
}
Figure