A companion to Top-k Multiclass SVM (NeurIPS 2015), with Matthias Hein and Bernt Schiele.
A multiclass SVM (Crammer and Singer, 2001) learns, for every training example, how hard that example pushes against each wrong class. In the dual problem, these pushes are nonnegative and share a fixed budget r, so for one example they lie in a simplex. Nothing stops a single wrong class from taking the whole budget. That is the right incentive for top-1 error, but not for top-k: an example is still correct if up to k−1 wrong classes beat the true one. The top-k SVM keeps the budget but caps each class at 1/k of the total that the example actually spends:
Δk(r) = { x : 〈1, x〉 ≤ r, 0 ≤ xi ≤ 〈1, x〉 / k }
We call this set the top-k simplex. Every update of the top-k SVM projects a point onto it, so the projection has to be exact and fast. Below, an example has three wrong classes, so its pushes live in 3D. Drop a point v and see where it lands for each k.
(The second view looks straight down the line where all coordinates are equal, so you see v’s position up to its total 〈1, v〉. Clicking keeps the total and moves v sideways. The shading shows, for every point you could click, how many classes the projection pushes.)
| k | Projection x, with the cap dashed | 〈1, x〉 | Cap | ‖v − x‖ | Which case |
|---|
For k = 1 the cap is no constraint at all, and Δ1(r) is the familiar corner of the simplex: one wrong class may take the whole budget. For k = 2 no class may take more than half of the total, so whenever the example pushes at all, at least two classes share the push. The set shrinks to the smaller red pyramid, whose top corners sit halfway along the edges of the blue one. For k = 3 every class gets exactly a third, and the set collapses to the green segment along the diagonal. With m wrong classes, Δk has one vertex at the origin and one for every subset of k classes sharing the budget equally, which is Figure 2 in the paper.
The cap is the dual side of averaging. The multiclass SVM charges an example for its single largest margin violation; the top-k hinge loss charges the average of the k largest, which makes it a tighter upper bound on the top-k error. In the dual, that average becomes the rule that no class may take more than 1/k of the push (Proposition 2).
The projection solves min ‖v − x‖² + ρ〈1, x〉² over x ∈ Δk(r). With ρ = 0 this is the Euclidean projection. The algorithm in Section 4 of the paper splits it into two cases, and the last column of the table shows which one applies:
The whole projection takes O(m log m + km) time for m classes, about as fast as projecting onto the plain simplex. This page runs the same two cases every time v moves, with a simple sort-based solver for the knapsack step.
Both are implemented in libsdca, the library I wrote for these papers.
There is a second natural way to cap: let no class take more than r/k, a fixed share of the budget rather than of the total actually spent. It comes from the ranking losses of Usunier et al. (2009) and gives a looser top-k hinge loss, which we also optimize exactly in Section 5 of the paper. Switch Cap each class at to r / k and pick A weak push: with the fixed cap, one class may still take most of a small total, because the cap only bites when the example pushes near full strength. Capping by the total enforces the share at every strength, which is why that set is smaller and the loss is a tighter bound.
@inproceedings{lapin2015topk,
title = {Top-k Multiclass {SVM}},
author = {Lapin, Maksim and Hein, Matthias and Schiele, Bernt},
booktitle = {NeurIPS},
year = {2015}
}