Learning Classifiers with Fenchel-Young Losses: Generalized Entropies, Margins, and Algorithms
Mathieu Blondel, André F. T. Martins, Vlad Niculae
Introduction
Loss functions are a cornerstone of statistics and machine learning: They measure the difference, or “loss,” between a ground-truth label and a prediction. Some loss functions, such as the hinge loss of support vector machines, are intimately connected to the notion of separation margin—a prevalent concept in statistical learning theory, which has been used to prove the famous perceptron mistake bound (Rosenblatt, 1958) and many other generalization bounds (Vapnik, 1998; Schölkopf and Smola, 2002). For probabilistic classification, the most popular loss is arguably the (multinomial) logistic loss. It is smooth, enabling fast convergence rates, and the softmax operator provides a consistent mapping to probability distributions. However, the logistic loss does not enjoy a margin, and the generated probability distributions have dense support, which is undesirable in some applications for interpretability or computational efficiency reasons.
To address these shortcomings, Martins and Astudillo (2016) proposed a new loss based on the projection onto the simplex. Unlike the logistic loss, this “sparsemax” loss has a natural separation margin and induces a sparse probability distribution. However, the sparsemax loss was derived in a relatively ad-hoc manner and it is still relatively poorly understood. Thorough understanding of the core principles underpinning these losses, enabling the creation of new losses combining their strengths, is still lacking.
This paper studies and extends Fenchel-Young (F-Y) losses, recently proposed for structured prediction (Niculae et al., 2018). We show that F-Y losses provide a generic and principled way to construct a loss with an associated probability distribution. We uncover a fundamental connection between generalized entropies, margins, and sparse probability distributions. In sum, we make the following contributions.
We introduce regularized prediction functions to generalize the softmax and sparsemax transformations, possibly beyond the probability simplex (§2).
We study F-Y losses and their properties, showing that they unify many existing losses, including the hinge, logistic, and sparsemax losses (§3).
We then show how to seamlessly create entire new families of losses from generalized entropies. We derive efficient algorithms to compute the associated probability distributions, making such losses appealing both in theory and in practice (§4).
We characterize which entropies yield sparse distributions and losses with a separation margin, notions we prove to be intimately connected (§5).
Finally, we demonstrate F-Y losses on the task of sparse label proportion estimation (§6).
Regularized prediction functions
We emphasize that the regularization is w.r.t. the output and not w.r.t. the model parameters , as is usually the case in the literature. The optimization problem in (1) balances between two terms: an “affinity” term , and a “confidence” term which should be low if is “uncertain”. Two important classes of convex are (squared) norms and, when is the probability simplex, generalized negative entropies. However, our framework does not require to be convex in general. Allowing extended-real further permits general domain constraints in (1) via indicator functions, as we now illustrate.
When , is a one-hot representation of the argmax prediction
We can see that output as a probability distribution that assigns all probability mass on the same class. When , where is Shannon’s entropy, is the well-known softmax
See Boyd and Vandenberghe (2004, Ex. 3.25) for a derivation. The resulting distribution always has dense support. When , is the Euclidean projection onto the probability simplex
a.k.a. the sparsemax transformation (Martins and Astudillo, 2016). The distribution has sparse support (it may assign exactly zero probability to low-scoring classes) and can be computed exactly in time (Brucker, 1984; Duchi et al., 2008; Condat, 2016). This paradigm is not limited to the probability simplex: When , we get
i.e., the sigmoid function evaluated coordinate-wise. We can think of its output as a positive measure (unnormalized probability distribution).
We now discuss simple properties of regularized prediction functions. The first two assume that is a symmetric function, i.e., that it satisfies
where is the set of permutation matrices.
Properties of
Effect of a permutation. If is symmetric, then : .
Order preservation. Let . If is symmetric, then the coordinates of and are sorted the same way, i.e., and .
Gradient mapping. is a subgradient of at , i.e., . If is strictly convex, is the gradient of , i.e., .
Temperature scaling. For any constant , . If is strictly convex, .
The proof is given in §C.1. For classification, the order-preservation property ensures that the highest-scoring class according to and agree with each other:
Temperature scaling is useful to control how close we are to unregularized prediction functions.
Fenchel-Young losses
In this section, we introduce Fenchel-Young losses as a natural way to learn models whose output layer is a regularized prediction function. {definition}Fenchel-Young loss generated by
Fenchel-Young losses can also be written as , where , highlighting the relation with the regularized prediction function . Therefore, as long as we can compute , we can evaluate the associated Fenchel-Young loss . Examples of Fenchel-Young losses are given in Table 1. In addition to the aforementioned multinomial logistic and sparsemax losses, we recover the squared, hinge and one-vs-all logistic losses, for suitable choices of and .
As the name indicates, this family of loss functions is grounded in the Fenchel-Young inequality (Borwein and Lewis, 2010, Proposition 3.3.4)
The inequality, together with well-known properties of convex conjugates, imply the following results. {proposition}Properties of F-Y losses
Zero loss. If is a lower semi-continuous proper convex function, then and iff . If is strictly convex, then iff .
Convexity & subgradients. is convex in and the residual vectors are its subgradients: .
Differentiability & smoothness. If is strictly convex, then is differentiable and . If is strongly convex, then is smooth, i.e., is Lipschitz continuous.
Temperature scaling. For any constant , .
Remarkably, the non-negativity and convexity properties hold even if is not convex. The zero loss property follows from the fact that, if is l.s.c. proper convex, then (9) becomes an equality (i.e., the duality gap is zero) if and only if . It suggests that minimizing a Fenchel-Young loss requires adjusting to produce predictions that are close to the target , reducing the duality gap.
with equality when the loss is . If , i.e., , then . As an example, applying (11) with and , we get that the sparsemax loss is a convex upper-bound for the non-convex . This suggests that the sparsemax loss can be useful for sparse label proportion estimation, as we confirm in §6.
New loss functions for sparse probabilistic classification
In the previous section, we presented Fenchel-Young losses in a broad setting. We now restrict to classification over the probability simplex and show how to easily create several entire new families of losses.
A natural choice of regularization function over the probability simplex is , where is a generalized entropy (DeGroot, 1962; Grünwald and Dawid, 2004): a concave function over , used to measure the “uncertainty” in a distribution .
Assumptions: We will make the following assumptions about .
Zero entropy: if is a delta distribution, i.e., .
Strict concavity: \mathsf{H}\big{(}(1-\alpha){\bm{p}}+\alpha{\bm{p}}^{\prime}\big{)}>{(1-\alpha)}\mathsf{H}({\bm{p}})+\alpha\mathsf{H}({\bm{p}}^{\prime}), for , .
Symmetry: for any .
If the ground truth is and assumption A.1. holds, (8) becomes
This expression shows that Fenchel-Young losses over can be written solely in terms of the generalized “cumulant function” . Indeed, when is Shannon’s entropy, we recover the cumulant (a.k.a. log-partition) function . When is strongly concave over , we can also see as a smoothed max operator (Niculae and Blondel, 2017; Mensch and Blondel, 2018) and hence can be seen as a smoothed upper-bound of the perceptron loss .
We now give two examples of generalized entropies. The resulting families of prediction and loss functions, new to our knowledge, are illustrated in Figure 1. We provide more examples in §A.
Defined as \mathsf{H}^{\textsc{t}}_{\alpha}({\bm{p}})\coloneqq k(\alpha-1)^{-1}\big{(}1-\|\cdot\|^{\alpha}_{\alpha}\big{)}, where and is an arbitrary positive constant, these entropies arise as a generalization of the Shannon-Khinchin axioms to non-extensive systems (Suyari, 2004) and have numerous scientific applications (Gell-Mann and Tsallis, 2004; Martins et al., 2009). For convenience, we set for the rest of this paper. Tsallis entropies satisfy assumptions A.1–A.3 and can also be written in uniformly separable form:
The limit case corresponds to the Shannon entropy. When , we recover the Gini index (Gini, 1912), a popular “impurity measure” for decision trees:
It is easy to check that recovers the sparsemax loss (Martins and Astudillo, 2016) (cf. Table 1). Another interesting case is , which gives , hence is the perceptron loss in Table 1. The resulting “” distribution puts all probability mass on the top-scoring classes. In summary, for is , , and , and is the logistic, sparsemax and perceptron loss, respectively. Tsallis entropies induce a continuous parametric family subsuming these important cases. Since the best surrogate loss often depends on the data (Nock and Nielsen, 2009), tuning typically improves accuracy, as we confirm in §6.
An interesting class of non-separable entropies are entropies generated by a -norm, defined as . We call them norm entropies. From the Minkowski inequality, -norms with are strictly convex on the simplex, so satisfies assumptions A.1–A.3 for . The limit case is particularly interesting: in this case, we obtain , recovering the Berger-Parker dominance index (Berger and Parker, 1970), widely used in ecology to measure species diversity. We surprisingly encounter again in §5, as a limit case for the existence of separation margins.
For non-separable entropies , the regularized prediction function does not generally enjoy a closed-form expression and one must resort to projected gradient methods to compute it. Fortunately, for uniformly separable entropies, which we saw to be the case of Tsallis entropies, we now show that can be computed in linear time. {proposition}Reduction to root finding
where is a root of , in the tight search interval , where and . An approximate such that can be found in time by, e.g., bisection. The related problem of Bregman projection onto the probability simplex was recently studied by Krichene et al. (2015) but our derivation is different and more direct (cf. §C.4).
Separation margin of F-Y losses
In this section, we are going to see that the simple assumptions A.1–A.3 about a generalized entropy are enough to obtain results about the separation margin associated with . The notion of margin is well-known in machine learning, lying at the heart of support vector machines and leading to generalization error bounds (Vapnik, 1998; Schölkopf and Smola, 2002; Guermeur, 2007). We provide a definition and will see that many other Fenchel-Young losses also have a “margin,” for suitable conditions on . Then, we take a step further, and connect the existence of a margin with the sparsity of the regularized prediction function, providing necessary and sufficient conditions for Fenchel-Young losses to have a margin. Finally, we show how this margin can be computed analytically. {definition}Separation margin
The most famous example of a loss with a separation margin is the multi-class hinge loss, , which we saw in Table 1 to be a Fenchel-Young loss: it is immediate from the definition that its margin is . Less trivially, Martins and Astudillo (2016, Prop. 3.5) showed that the sparsemax loss also has the separation margin property. On the negative side, the logistic loss does not have a margin, as it is strictly positive. Characterizing which Fenchel-Young losses have a margin is an open question which we address next.
The loss has a separation margin iff there is a such that .
If the above holds, then the margin of is given by the smallest such or, equivalently,
Reassuringly, the first part confirms that the logistic loss does not have a margin, since . A second interesting fact is that the denominator of (18) is the generalized entropy introduced in §4: the -norm entropy. As Figure 1 suggests, this entropy provides an upper bound for convex losses with unit margin. This provides some intuition to the formula (18), which seeks a distribution maximizing the entropy ratio between and .
The next result, proved in §C.6, characterizes more precisely the image of . In doing so, it establishes a key result in this paper: a sufficient condition for the existence of a separation margin in is the sparsity of the regularized prediction function , i.e., its ability to reach the entire simplex, including the boundary points. If is uniformly separable, this is also a necessary condition. {proposition}Equivalence between sparse probability distribution and loss enjoying a margin
Let satisfy A.1–A.3 and be uniformly separable, i.e., . Then the following statements are all equivalent:
for any ;
has the separation margin property.
For a general (not necessarily separable) satisfying A.1–A.3, we have (1) (2) (3).
Let us reflect for a moment on the three conditions stated in Proposition 5. The first two conditions involve the subdifferential and gradient of and its conjugate; the third condition is the margin property of . To provide some intuition, consider the case where is separable with and is differentiable in . Then, from the concavity of , its derivative is decreasing, hence the first condition is met if and . This is the case with Tsallis entropies for , but not Shannon entropy, since explodes at . Functions whose gradient “explodes” in the boundary of their domain (hence failing to meet the first condition in Proposition 5) are called “essentially smooth” (Rockafellar, 1970). For those functions, maps only to the relative interior of , never attaining boundary points (Wainwright and Jordan, 2008); this is expressed in the second condition. This prevents essentially smooth functions from generating a sparse or (if they are separable) a loss with a margin, as asserted by the third condition. Since Legendre-type functions (§3) are strictly convex and essentially smooth, by Proposition 3, loss functions for which the composite form holds, which is the case of the logistic loss but not of the sparsemax loss, do not enjoy a margin and cannot induce a sparse probability distribution. This is geometrically visible in Figure 1.
For Fenchel-Young losses that have the separation margin property, Proposition 5 provided a formula for determining the margin. While informative, formula (18) is not very practical, as it involves a generally non-convex optimization problem. The next proposition, proved in §C.7, takes a step further and provides a remarkably simple closed-form expression for generalized entropies that are twice-differentiable. To simplify notation, we denote by the component of . {proposition} Assume satisfies the conditions in Proposition 5 and is twice-differentiable on the simplex. Then, for arbitrary :
The compact formula (19) provides a geometric characterization of separable entropies and their margins: (20) tells us that only the slopes of at the two extremities of $$ are relevant in determining the margin.
As seen in §4, Tsallis entropies are separable with . For , , hence and . Proposition 5 then yields
Norm entropies, while not separable, have gradient , giving , so
as confirmed visually in Figure 1, in the binary case.
Experimental results
As we saw, -Tsallis entropies generate a family of losses, with the logistic () and sparsemax losses () as important special cases. In addition, they are twice differentiable for , produce sparse probability distributions for and are computationally efficient for any , thanks to Proposition 4. In this section, we demonstrate their usefulness on the task of label proportion estimation and compare different solvers for computing .
We use L-BFGS (Liu and Nocedal, 1989) for simplicity. From Proposition 9 and using the chain rule, we obtain the gradient expression , where , and are matrices whose rows gather , and , for . At test time, we predict label proportions by .
We ran experiments on standard multi-label benchmark datasets — see §B for dataset characteristics. For all datasets, we removed samples with no label, normalized samples to have zero mean unit variance, and normalized labels to lie in the probability simplex. We chose and against the validation set. We report the test set mean Jensen-Shannon divergence, , and the mean squared error in Table 3. As can be seen, the loss with tuned achieves the best averaged rank overall. Tuning allows to choose the best loss in the family in a data-driven fashion. Additional experiments confirm these findings — see §B.
Related work
recovering the well-known relation between Bregman divergences and proper scoring rules. For example, using the Gini index generates the Brier score (Brier, 1950) , showing that the sparsemax loss and the Brier score share the same generating function. More generally, while a scoring rule is related to a primal-space Bregman divergence, a Fenchel-Young loss can be seen as a mixed-space Bregman divergence (§3). This difference has a number of important consequences. First, is not necessarily convex in (Williamson et al. (2016, Proposition 17) show that it is in fact quasi-convex). In contrast, is always convex in . Second, the first argument is constrained to for , while unconstrained for .
Thus, in this case, Fenchel-Young losses and proper composite losses coincide up to the constant term (which vanishes if and satisfies assumption A.1), with the canonical inverse link function. Fenchel-Young losses, however, require neither invertible link nor Legendre type assumptions, allowing to express losses (e.g., hinge or sparsemax) that are not expressible in composite form. Moreover, as seen in §5, a Legendre-type precisely precludes sparse probability distributions and losses enjoying a margin.
Nock and Nielsen (2009) proposed binary classification losses based on the Legendre transformation but require invertible mappings. Masnadi-Shirazi (2011) studied the Bayes consistency of related binary classification loss functions. Duchi et al. (2018, Proposition 3) derived the multi-class loss (12), a special case of Fenchel-Young loss over the probability simplex, and showed (Proposition 4) that any strictly concave generalized entropy generates a classification-calibrated loss. Amid and Warmuth (2017) proposed a different family of losses based on the Tsallis divergence, to interpolate between convex and non-convex losses, for robustness to label noise.
Fenchel duality also plays a key role in smoothing techniques (Nesterov, 2005; Beck and Teboulle, 2012), which have been used extensively to create smoothed losses (Shalev-Shwartz and Zhang, 2016). However, these techniques were applied on a per-loss basis and were not connected to the induced probability distribution. In contrast, we propose a generic construction, with clear links between smoothing and the distribution induced by .
Conclusion
We showed that regularization and Fenchel duality provide simple core principles, unifying many existing loss functions, and allowing to create useful new ones easily. In particular, we derived a new family of loss functions based on Tsallis entropies, which includes the logistic, sparsemax and perceptron losses as special cases. With the unique exception of the logistic loss, losses in this family induce sparse probability distributions. We also showed a close and fundamental relationship between generalized entropies, losses enjoying a margin and sparse probability distributions. Remarkably, Fenchel-Young losses can be defined over arbitrary domains, allowing to construct loss functions for a large variety of applications (Blondel et al., 2019).
MB thanks Arthur Mensch and Gabriel Peyré for numerous fruitful discussions and Tim Vieira for introducing him to generalized exponential families. AM and VN were partially supported by the European Research Council (ERC StG DeepSPIN 758969) and by the Fundação para a Ciência e Tecnologia through contracts UID/EEA/50008/2013 and CMUPERI/TIC/0046/2014 (GoLocal).
References
Appendix A More examples of generalized entropies
In this section, we give two more examples of generalized entropies: squared norm entropies and Rényi entropies.
Inspired by Niculae and Blondel (2017), as a simple extension of the Gini index (15), we consider the following generalized entropy based on squared -norms:
The constant term , omitted by Niculae and Blondel (2017), ensures satisfaction of A.1. For , it is known that the squared -norm is strongly convex w.r.t. (Ball et al., 1994), implying that , and therefore , is smooth. Although cannot be solved in closed form for , it can be solved efficiently using projected gradient descent methods.
Rényi entropies (Rényi, 1961) are defined for any as:
Unlike Shannon and Tsallis entropies, Rényi entropies are not separable, with the exception of , which also recovers Shannon entropy as a limit case. The case gives . For , Rényi entropies satisfy assumptions A.1–A.3; for , Rényi entropies fail to be concave. They are however pseudo-concave (Mangasarian, 1965), meaning that, for all , implies . This implies, among other things, that points with zero gradient are maximizers of , which allows us to compute the predictive distribution with gradient-based methods.
Appendix B Experiment details and additional empirical results
The datasets we used in §6 are summarized below.
The datasets can be downloaded from http://mulan.sourceforge.net/datasets-mlc.html and https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/.
Appendix C Proofs
In this section, we give proofs omitted from the main text.
Let be symmetric. We first prove that is symmetric as well. Indeed, we have
The last equality was obtained by a change of variable , from which is recovered as , which proves .
Since is convex, the gradient operator is monotone, i.e.,
which implies and . To fully prove the claim, we need to show that the last inequality is strict: to do this, we simply invoke with a matrix that permutes and , from which we must have .
This follows directly from Danskin’s theorem (Danskin, 1966). See also Bertsekas (1999, Proposition B.25).
This immediately follows from properties of the operator.
C.2 Proof of Proposition 3
We set .
The last two terms are independent of and therefore
where . The r.h.s. is the Bregman projection of onto .
Let . Using (31), we obtain
where we assumed and , implying .
If (i.e., ), then and . We thus get the composite form of Fenchel-Young losses
Let . Since is the Bregman projection of onto , we can use the well-known Pythagorean theorem for Bregman divergences (see, e.g., Banerjee et al. (2005, Appendix A)) to obtain for all :
Using (35), we obtain for all :
Since is a l.s.c. proper convex function, from Proposition 9, we immediately get
C.3 Proof of Proposition 4
The two facts stated in Proposition 4 ( is always non-negative and maximized by the uniform distribution) follow directly from Jensen’s inequality. Indeed, for all :
;
,
where is the set of permutation matrices. Strict concavity ensures that is the unique maximizer.
C.4 Proof of Proposition 4
From strict convexity and the definition of the convex conjugate,
The constrained optimization problem above has Lagrangian
A solution must satisfy the KKT conditions
Since is strictly convex, is increasing and so . For any , we construct as
By construction, , satisfying dual feasability. Injecting into (42) and combining the two cases, we obtain
We show that i) the stationarity conditions have a unique solution given , and ii) forms a sign-changing bracketing interval, and thus contains , which can then be found by one-dimensional search. The solution verifies all KKT conditions, thus is globally optimal.
Since is strictly convex, its derivative is continuous and strictly increasing, and is thus a one-to-one mapping between $[g^{\prime}(0),g^{\prime}(1)](g^{\prime})^{-1}\colon[g^{\prime}(0),g^{\prime}(1)]\rightarrow\theta_{j}-\tau\geq g^{\prime}(0)$, we have
Otherwise, . This verifies that the r.h.s. of (45) is always within the domain of . We can thus apply the inverse to both sides to solve for , obtaining
Strict convexity implies the optimal is unique; it can be seen that is also unique. Indeed, assume optimal . Then, , so . This implies either , or , in which case , which is a contradiction.
Consider the primal infeasability function ; is primal feasible iff We show that is decreasing on , and that it has opposite signs at the two extremities. From the intermediate value theorem, the unique root must satisfy .
Since is increasing, so is . Therefore, for all , is decreasing, and so is the sum . It remains to check the signs at the boundaries.
where we upper-bounded each term of the sum by the largest one. At the other end,
using that a sum of non-negative terms is no less than its largest term. Therefore, and . This implies that there must exist in satisfying . The corresponding triplet thus satisfies all of the KKT conditions, confirming that it is the global solution.
Algorithm 1 is an example of a bisection algorithm for finding an approximate solution; more advanced root finding methods can also be used. We note that the resulting algorithm resembles the method provided in Krichene et al. (2015), with a non-trivial difference being the order of the thresholding and in Eq. (47).
C.5 Proof of Proposition 5
We start by proving the following lemma. {lemma} Let satisfy assumptions A.1–A.3. Then:
We have iff . That is:
If , then, we also have for any such that and , for all .
Let . From Proposition 2 (order preservation), we can consider without loss of generality, in which case any satisfies . We have iff . Since , we must have , which proves part 1. To see 2, note that we have , for all , from which the result follows.
We now proceed to the proof of Proposition 5. Let , and suppose that has the separation margin property. Then, satisfies the margin condition , hence . From the first part of Proposition 9, this implies .
Conversely, let us assume that . From the second part of Lemma C.5, this implies that for any such that and for all ; and more generally we have . That is, any with satisfies . From Proposition 9, this is equivalent to .
Let us now determine the margin of , i.e., the smallest such that . From Lemma C.5, this is equivalent to for any , i.e., . Note that by Proposition 2 the “most competitive” ’s are sorted as , so we may write without loss of generality. The margin of is the smallest possible such margin, given by (18).
C.6 Proof of Proposition 5
Furthermore, since upper bounds the separation margin of , we have from Proposition 5 that for any . Hence, we have
Summing all inequalities in Eqs. (57)–(58), we obtain the expression in Eq. (56), which finishes the proof.
C.7 Proof of Proposition 5
Define . Let us start by writing the margin expression (18) as a unidimensional optimization problem. This is done by noticing that the max-generalized entropy problem constrained to gives , for by a similar argument as the one used in Proposition 4. We obtain:
We write the argument above as , where . We will first prove that is decreasing in , which implies that the supremum (and the margin) equals . Note that we have the following expression for the derivative of any function :
Using this fact, we can write the derivative as:
In turn, the derivative is:
where we denote by the Hessian of , and used the fact that it is positive semi-definite, due to the convexity of . This implies that is decreasing, hence for any , , where we used the fact , assumed as a condition of Proposition 5. Therefore, we must also have for any , hence is decreasing, and . By L’Hôpital’s rule: