In machine learning, we rarely train models on the metrics we actually care about. Instead of optimizing for Average Precision (AP), BLEU scores, or the Area Under the ROC Curve (AUC), we typically use "surrogate" losses like cross-entropy or mean squared error. We do this because these surrogates are smooth and differentiable, making them easy to optimize with gradient descent.
However, this creates a metric mismatch. A model might improve its cross-entropy loss while its actual task performance—like its ability to rank relevant search results at the top—stagnates or even declines. A growing body of research suggests that we can achieve superior performance by bridging this gap and optimizing the final evaluation metrics directly.
The Problem with Surrogate Proxies
Standard losses treat every mistake with roughly equal weight. But in real-world tasks, some mistakes are more costly than others. In object detection, for instance, Kean Chen and colleagues point out in AP-Loss for Accurate One-Stage Object Detection that one-stage detectors face an extreme class imbalance. For every actual object, there are thousands of background "anchors." A standard classification loss gets overwhelmed by these easy background samples, whereas a metric like Average Precision naturally ignores them to focus on the ranking of positive detections.
Similarly, in machine translation, Franz Josef Och demonstrated in Minimum Error Rate Training in Statistical Machine Translation that maximizing the likelihood of a translation doesn't always lead to the highest BLEU score. By navigating the "messy" landscape of the error rate directly, models can find parameter settings that mathematical proxies simply overlook.
Smoothing the Non-Differentiable
The primary hurdle to direct optimization is that most evaluation metrics are combinatorial or step-functions—they change only when the relative order of predictions changes, making their gradients zero almost everywhere.
To solve this, researchers have developed several clever workarounds:
- Loss-Augmented Inference: In Optimizing for Measure of Performance in Max-Margin Parsing, Alexander Bauer and his team use a max-margin framework where the "margin" is scaled by the actual $F_1$ error. This forces the model to push incorrect structures further away if they result in a worse evaluation score.
- Direct Gradient Estimation: Alex Schwing and Raquel Urtasun in Training Deep Neural Networks via Direct Loss Minimization show that it is possible to backpropagate through non-decomposable metrics by defining a "direct loss" that approximates the metric's behavior in the local neighborhood of the current weights.
- Smart Sampling: Instead of smoothing the whole metric, Jing Lü suggests in Sampling Wisely: Deep Image Embedding by Top-K Precision Optimization that we should only sample pairs that are near the "decision boundary" of the metric (e.g., the top-$k$ cutoff). This focuses the gradient updates on the specific samples that actually impact the final score.
Ranking as a Training Objective
Many of the most important metrics, such as Mean Average Precision (MAP) or Normalized Discounted Cumulative Gain (NDCG), are based on ranking. Yisong Yue and Thorsten Joachims pioneered this in A support vector method for optimizing average precision, showing that ranking metrics can be integrated into Structural SVMs.
This shift from "classification" to "ranking" during training is crucial for systems where the user only sees the top few results. For example, in Counterfactual Learning-to-Rank for Additive Metrics and Deep Models, Aman Agarwal and colleagues demonstrate that when training on biased click data, optimizing for the intended additive metric (like DCG) is significantly more effective than using simpler proxies.
Learning the Loss Function
Perhaps the most flexible approach is to let the model learn its own surrogate loss. In Relational Surrogate Loss Learning, Tao Huang and his co-authors introduced ReLoss. Instead of trying to predict the exact value of a metric, ReLoss trains a neural network to act as a loss function by maximizing the rank correlation between the loss and the target metric. If the metric says Model A is better than Model B, the learned loss function must also produce a lower value for Model A.
This "meta-learning" of the objective ensures that the gradient descent process is always aligned with the final evaluation, even for complex, non-linear metrics that are otherwise impossible to differentiate.
Why it Works: Intuition
The success of direct metric optimization boils down to alignment. Standard training assumes that if you get the individual labels right, the aggregate metric will take care of itself. But metrics like AUC or AP are multivariate and non-decomposable—they depend on the relationship between all samples at once.
By incorporating the metric into the loss, we allow the model to:
- Prioritize hard cases: Focus on the "sweet spot" of the curve, such as the high-precision/low-recall region in medical diagnosis (Linli Zhou et al., Stochastic Primal-Dual Double Block-Coordinate for Two-way Partial AUC Maximization).
- Reduce Representation Bias: Avoid optimizing for artifacts of the training setup (like binarized trees in parsing) and focus on the actual test-time structure (Alexander Bauer).
- Handle Imbalance Naturally: Metrics like AP inherently handle class imbalance by focusing on the precision of the positive class, removing the need for manual loss weighting or complex sampling heuristics.