On the Consistency of Top-k Surrogate Losses

Forest Yang, Sanmi Koyejo

Abstract

In many classification tasks, the top-$k$ error is a more relevant metric than the standard top-1 error. However, optimizing this discontinuous metric directly is infeasible, necessitating the use of surrogate losses. This paper provides the first rigorous theoretical framework for "top-$k$ consistency," determining whether minimizing a surrogate loss function leads to the optimal top-$k$ classifier. We demonstrate that most existing convex hinge-like top-$k$ losses are theoretically inconsistent and propose a new consistent non-convex hinge loss. Furthermore, we reveal a trade-off where the popular cross-entropy loss, despite being consistent, can fail when restricted to linear models.

Introduction

In large-scale classification tasks like ImageNet, label ambiguity is common. Top-$k$ error—where a prediction is considered correct if the true label is among the top $k$ predicted classes—is often used to evaluate models. Since top-$k$ error is non-differentiable, practitioners rely on surrogate losses like cross-entropy or hinge loss. The fundamental question addressed here is consistency: if a surrogate loss is perfectly minimized with infinite data, does it yield the Bayes optimal top-$k$ classifier? While well-understood for $k=1$, the theoretical landscape for $k > 1$ has previously been characterized by incorrect assumptions.

Theoretical Framework

The analysis is built upon two theoretical pillars:

  1. Top-$k$ Preserving Property: A condition on a score vector ensuring its $k$ largest entries correspond to the $k$ most probable classes.
  2. Top-$k$ Calibration: A mathematical requirement for a loss function to be consistent. A top-$k$ calibrated loss guarantees a top-$k$ preserving result upon minimization.

Analysis of Loss Functions

We analyze two major families of losses: Bregman Divergences and Hinge-like Losses. We prove that any Bregman divergence (including standard Softmax Cross-Entropy) composed with an "inverse top-$k$ preserving" function is consistent.

In contrast, the analysis of hinge-like losses reveals a "Hinge Loss Paradox." Most popular convex top-$k$ hinge losses ($\psi_1, \psi_2, \psi_3$) are proven to be inconsistent. We propose two new losses: $\psi_4$ (a tighter convex bound) and $\psi_5$ (a non-convex version).

Table 1: Definitions and calibration status of various top-k hinge-like loss functions.

As shown in Figure 1, only the non-convex $\psi_5$ is top-$k$ calibrated. This suggests that for a hinge loss to be consistent, it must likely be non-convex, a significant departure from the $k=1$ case where the convex hinge loss is the gold standard.

Experimental Results

We validated these theoretical findings using synthetic datasets designed to probe consistency boundaries.

Inconsistency Probe

Using a 2D dataset with 8 classes, we tested whether various losses could identify the top-2 most likely classes. The consistent loss $\psi_5$ achieved the theoretical Bayes optimal top-2 accuracy of 0.2941, while the inconsistent losses $\psi_1$ through $\psi_4$ failed to reach this threshold.

Table 2: Top-2 accuracy results on the Inconsistency Probe dataset, showing psi_5 achieving the Bayes optimal performance.

Linear Setting Performance

We also investigated "restricted consistency" using linear models on overlapping Gaussian distributions. While cross-entropy is "rank consistent" (aiming to order all classes correctly), this global objective can be a liability when model capacity is limited. In these experiments, $\psi_5$ and even the inconsistent $\psi_1$ significantly outperformed standard Cross-Entropy in top-5 accuracy (e.g., 0.896 vs 0.763), as cross-entropy wastes modeling effort on the distribution's tail rather than the top-$k$ boundary.

Conclusion

This work establishes that popular convex top-$k$ hinge losses lack theoretical consistency and introduces $\psi_5$ as a consistent alternative. Our findings also highlight a critical trade-off: while rank-consistent losses like cross-entropy are theoretically sound in the infinite-capacity regime, they may be suboptimal under model restrictions compared to losses specifically targeting the top-$k$ boundary. Future work includes extending these proofs to deep neural networks and large-scale empirical benchmarking.

Summary updated

BibTeX
@inproceedings{yang2020consistency,
  author = {Forest Yang and Sanmi Koyejo},
  title = {{On the Consistency of Top-k Surrogate Losses}},
  booktitle = {International Conference on Machine Learning},
  year = {2020},
  url = {https://openreview.net/forum?id=rqmpJqzIXx},
}
Figure