IT IS LIKELY THAT YOUR LOSS SHOULD
Year: 2020

Abstract:
Many common loss functions such as mean-squared-error, cross-entropy, and reconstruction loss are unnecessarily rigid. Under a probabilistic interpretation, these common losses correspond to distributions with fixed shapes and scales. We instead argue for optimizing full likelihoods that include parameters like the normal variance and softmax temperature. Joint optimization of these “likelihood parameters” with model parameters can adaptively tune the scales and shapes of losses in addition to the strength of regularization. We explore and systematically evaluate how to parameterize and apply likelihood parameters for robust modeling, outlier-detection, and re-calibration. Additionally, we propose adaptively tuning L2 and L1 weights by fitting the scale parameters of normal and Laplace priors and introduce more flexible element-wise regularizers.

heading: 1 INTRODUCTION
text: Choosing the right loss matters. Many common losses arise from likelihoods, such as the squared error loss from the normal distribution , absolute error from the Laplace distribution, and the cross entropy loss from the softmax distribution. The same is true of regularizers, where L2 arises from a normal prior and L1 from a Laplace prior.
Deriving losses from likelihoods recasts the problem as a choice of distribution which allows datadependent adaptation. Standard losses and regularizers implicitly fix key distribution parameters, limiting flexibility. For instance, the squared error corresponds to fixing the normal variance at a constant. The full normal likelihood retains its scale parameter and allows optimization over a parametrized set of distributions. This work examines how to jointly optimize distribution and model parameters to select losses and regularizers that encourage generalization, calibration, and robustness to outliers. We explore three key likelihoods: the normal, softmax, and the robust regression likelihood ρ of Barron (2019). Additionally, we cast adaptive priors in the same light and introduce adaptive regularizers. Our contributions:
1. We systematically survey and evaluate global, data, and predicted likelihood parameters and introduce a new self-tuning variant of the robust adaptive loss ρ
2. We apply likelihood parameters to create new classes of robust models, outlier detectors, and re-calibrators.
3. We propose adaptive versions of L1 and L2 regularization using parameterized normal and Laplace priors on model parameters.

heading: 2 BACKGROUND
text: Notation We consider a dataset D of points xi and targets yi indexed by i ∈ {1, . . . , N}. Targets for regression are real numbers and targets for classification are one-hot vectors. The model f with parameters θ makes predictions ŷi = fθ(x). A loss L(ŷ, y) measures the quality of the prediction given the target. To learn model parameters we solve the following loss optimization:
min θ E (x,y)∼D L(ŷ = fθ(x), y) (1)
A likelihood L(ŷ|y, φ) measures the quality of the prediction as a distribution over ŷ given the target y and likelihood parameters φ. We use the negative log-likelihood ` (NLL), and the likelihood interchangeably since both have the same optima. We define the full likelihood optimization:
min θ,φ E (x,y)∼D `(ŷ = fθ(x)|y, φ) (2)
to jointly learn model and likelihood parameters. “Full” indicates the inclusion of φ, which controls the distribution and induced NLL loss. We focus on full likelihood optimization in this work. We note that the target, y, is the only supervision needed to optimize model and likelihood parameters, θ and φ respectively. Additionally, though the shape and scale varies with φ, reducing the error ŷ−y always reduces the NLL for our distributions.
Distributions Under Investigation This work considers the normal likelihood with variance σ (Bishop et al., 2006; Hastie et al., 2009), the softmax likelihood with temperature τ (Hinton et al., 2015), and the robust likelihood ρ (Barron, 2019) with shape α and scale σ that control the scale and shape of the likelihood. The first two are among the most common losses in machine learning, and the last loss provides an important illustration of a likelihood parameter that affects “shape” instead of “scale”. We note that changing the scale and shape of the likelihood distribution is not “cheating” as there is a trade-off between uncertainty and credit. Figure 1 shows how this trade-off affects the Normal and softmax distributions and their NLLs.
The normal likelihood has terms for the residual ŷ − y and the variance σ as N (ŷ|y, σ) = (2πσ2)− 12 exp ( −1 2 (ŷ − y)2 σ2 ) , (3)
with σ ∈ (0,∞) scaling the distribution. The normal NLL can be written `N = 12σ2 (ŷ−y) 2+log σ, after simplifying and omitting constants that do not affect minimization. We recover the squared error by substituting σ = 1.
The softmax defines a categorical distribution defined by scores z for each class c as
softmax(ŷ = y|z, τ) = e zyτ∑ c e zcτ , (4)
with the temperature, τ ∈ (0,∞), adjusting the entropy of the distribution. We recover the classification cross-entropy loss, − log p(ŷ = y), by substituting τ = 1 in the respective NLL. We state the gradients of these likelihoods with respect to their σ and τ in Section A of the supplement.
The robust loss ρ and its likelihood are
ρ (x, α, σ) = |α− 2| α ( (x/σ)2 |α− 2| + 1 )α/2 − 1  and (5) p (ŷ | y, α, σ) = 1
σZ (α) exp (−ρ (ŷ − y, α, σ)) , (6)
with shape α ∈ [0,∞), scale σ ∈ (0,∞), and normalization function Z (α). This robust loss, ρ, has the interesting property that it generalizes several different loss functions commonly used in robust learning such as the L2 loss (α = 2), pseudo-huber loss (Charbonnier et al., 1997)(α = 1), Cauchy loss (Li et al., 2018) (α = 0), Geman-McClure loss (Ganan & McClure, 1985), (α = −2), and Welsch (Dennis Jr & Welsch, 1978) loss (alpha = −∞). Learning the shape parameter allows models to adapt the shape of their noise distribution.

heading: 3 RELATED WORK
text: Likelihood optimization follows from maximum likelihood estimation (Hastie et al., 2009; Bishop et al., 2006), yet is uncommon in practice for fitting deep regressors and classifiers for discriminative tasks. However Kendall & Gal (2017); Kendall et al. (2018); Barron (2019); Saxena et al. (2019) optimize likelihood parameters to their advantage yet differ in their tasks, likelihoods, and parameterizations. In this work we aim to systematically experiment, clarify usage, and encourage their wider adoption.
Early work on regressing means and variances (Nix & Weigend, 1994) had the key insight that optimizing the full likelihood can fit these parameters and adapt the loss. Some recent works use likelihoods for loss adaptation, and interpret their parameters as the uncertainty (Kendall & Gal, 2017; Kendall et al., 2018), robustness (Kendall & Gal, 2017; Barron, 2019; Saxena et al., 2019), and curricula (Saxena et al., 2019) of losses. MacKay & Mac Kay (2003) uses Bayesian evidence to select hyper-parameters and losses based on proper likelihood normalization. Barron (2019) define a generalized robust regression loss, ρ, to jointly optimize the type and degree of robustness with global, data-independent, parameters. Kendall & Gal (2017) predict variances for regression and classification to handle data-dependent uncertainty. Kendall et al. (2018) balance multi-task loss weights by optimizing variances for regression and temperatures for classification. These global parameters depend on the task but not the data, and are interpreted as inherent task uncertainty. Saxena et al. (2019) define a differentiable curriculum for classification by assigning each training point its own temperature. These data parameters depend on the index of the data but not its value. We compare these different likelihood parameterizations across tasks and distributions.
In the calibration literature, Guo et al. (2017) have found that deep networks are often miscalibrated, but they can be re-calibrated by cross-validating the temperature of the softmax. In this work we explore several generalizations of this concept. Alternatively, Platt scaling (Platt, 1999) fits a sigmoid regressor to model predictions to calibrate probabilities. Kuleshov et al. (2018) re-calibrate regressors by fitting an Isotonic regressor to the empirical cumulative distribution function.

heading: 4 LIKELIHOOD PARAMETER TYPES
text: We explore the space of likelihood parameter representations for model optimization and inference. Though we note that some losses, like adversarial losses, are difficult to represent as likelihoods, many different losses in the community have a natural probabilistic interpretation. Often, these probabilistic interpretations can be parametrized in a variety of ways. We explore two key axes of generality when building these loss functions: conditioning and dimensionality.
Conditioning We represent the likelihood parameters by three functional classes: global, data, and predicted. Global parameters, φ = c, are independent of the data and model and define the same likelihood distribution for all points. Data parameters, φi, are conditioned on the index, i, of the data, xi, but not its value. Every training point is assigned an independent likelihood parameter, φi that define different likelihoods for each training point. Predicted parameters, φ(x) = gη(x), are determined by a model, g, with parameters η (not to be confused with the task model parameters θ). Global and predicted parameters can be used during training and testing, but data parameters are only assigned to each training point and are undefined for testing. We show a simple example of predicted temperature in Figure 4, and an illustration of the parameter types in Figure 2.
We note that for certain global parameters like a learned Normal scale, changing the scale does not affect the optima, but does change the probabilistic interpretation. This invariance has led many authors to drop the scale from their formulations. However, when models can predict these scale parameters they can naturally remain calibrated in the presence of heteroskedasticity and outliers.
conditioning: global, predicted, and data. Each represents a different way to parametrize the model’s temperature.
Each represents a possible way to parametrize the additional scale parameter added to the loss.
Dimensionality The dimensionality, |φ|, of likelihood parameters can vary with the dimension of the task prediction, ŷ. For example, image regressors can use a single likelihood parameter for each image |φ| = 1, RGB image channel |φ| = C, or even every pixel |φ| = W × H × C as in Figure 3. These choices correspond to different likelihood distribution classes. Dimensionality and Conditioning of likelihood parameters can interact. For example, data parameters with |φ| = W × H × C would result in N ×W × H × C additional parameters, where N is the size of the dataset. This can complicate implementations and slow down optimization due to disk I/O when their size exceeds memory. Table 5 in the appendix contrasts the computational requirements of different likelihood parameter types. The work of Barron (2019) explores both scalar and pixel-wise dimensionalities for his robust loss.
5 APPLICATIONS

heading: 5.1 ROBUSTNESS AND OUTLIER DETECTION
text: Table 2: Median outlier detection performance of several methods across 22 benchmark datasets from ODDS.
Method Median AUC LOF .669 FB .702 ABOD .727 AE .737
VAE .792 COPOD .799
PCA .808 OCSVM .814
MCD .820 KNN .822 HBOS .822 IF .823
CBLOF .836 AE+S (Ours) .846 PCA+S (Ours) .868
Figure 6: Distribution of Outlier Detection AUC across the ODDS Benchmark. Our approaches, PCA+S and AE+S, are competitive with other Outlier Detection systems.
an image classifier (trained using the setup of 5.3) correlates strongly with blurry, dark, and difficult examples on the Street View House Number (SVHN) dataset. We use this approach to create simple outlier detection algorithms by considering deep (AE+S) and linear (PCA+S) auto-encoders (Kramer, 1991) with data-conditioned scale parameters as outlier scores. We evaluate this approach on tabular datasets using deep and linear auto-encoders with model-parameterized scales. In Table 2 we quantitatively demonstrate the quality of these simple likelihood parameter approaches across 22 datasets from the Outlier Detection Datasets (ODDS), a standard outlier detection benchmark (Rayana, 2016). The ODDS benchmark supplies ground truth outlier labels for each dataset, which allows one to treat outlier detection as an unsupervised classification problem. We compare against a variety of established outlier detection approaches included in the pyOD (Zhao et al., 2019) framework including: One-Class SVMs (OCSVM) (Schölkopf et al., 2000), Local Outlier Fraction (LOF) (Breunig et al., 2000), Angle Based Outlier Detection (ABOD) (Kriegel et al., 2008), Feature Bagging (FB) (Lazarevic & Kumar, 2005), Auto Encoder Distance (AE) (Aggarwal, 2015), K-Nearest Neighbors (KNN) (Ramaswamy et al., 2000; Angiulli & Pizzuti, 2002), Copula Based Outlier Detection (COPOD) (Li et al., 2020), Variational AutoEncoders (VAE) (Kingma & Welling, 2013), Minimum Covariance Determinants with Mahlanohbis Distance (MCD) (Rousseeuw & Driessen, 1999; Hardin & Rocke, 2004), Histogram-based Outlier Scores (HBOS) (Goldstein & Dengel, 2012), Principal Component Analysis (PCA) (Shyu et al., 2003), Isolation Forests (IF) (Liu et al., 2008; 2012), and the Clustering-Based Local Outlier Factor (CBLOF) (He et al., 2003).
Our predicted scale auto-encoders use PyTorch’s layers API (Paszke et al., 2019) with rectified linear unit (ReLU) activations for deep auto-encoders and Glorot uniform initialization (Dahl et al., 2013; Glorot & Bengio, 2010) for all layers. We use Adam (Kingma & Ba, 2015) with a learning rate of

heading: 5.2 ADAPTIVE REGULARIZATION WITH PRIOR PARAMETERS
text: In addition to optimizing the shape and scale of the likelihood distribution of the model output, we can use the same approach to optimize the prior distribution of the model parameters. More specifically, we propose adaptive regularizers for a model’s parameters, θ. This approach optimizes the distribution parameters of the prior, φprior, to naturally tune the degree of regularization. In particular, the Normal (Ridge, L2) and Laplace (LASSO, L1) priors, with scale parameters σ and b, regularize model parameters for small magnitude and sparsity respectively (Hastie et al., 2009). The degree of regularization, λ ∈ [0,∞), is conventionally a hyperparameter of the regularized loss function:
min θ N∑ i (ŷi := fθ(xi)− yi)2 + λ P∑ j |θj |. (7)
We note that we cannot choose λ by direct minimization because it admits a trivial minimum at λ = 0. In the linear case, one can select this weight efficiently using Least Angle Regression (Efron et al., 2004). However, in general λ is usually learned through expensive cross validation methods. Instead, we retain the prior with its scale parameter, and jointly optimize over the full likelihood:
min θ,σ,b N∑ i ( 1 2σ2 (ŷi − yi)2 + log σ ) + P∑ j ( |θj | b + log b ) (8)
This approach, the Dynamic Lasso (D-LASSO), admits no trivial solution for the prior parameter b, and must balance the effective regularization strength, 1b , with the normalization factor, log b. D-LASSO selects the degree of regularization by gradient descent, rather than expensive black-box search. In Figure 7 (left) and (middle) we show that this approach, and its Ridge equivalent, yield ideal settings of the regularization strength on a suite of synthetic regression problems. Figure 7
(right) shows D-LASSO converges to the best LASSO regularization strength for a variety of truemodel sparsities. As a further extension, we replace the global σ or b with a σj or bj for each model parameter, θj , to locally adapt regularization to each model weight (Multi-Lasso). This consistently outperforms any global setting of the regularization strength and shields important weights from undue shrinkage 7 (middle). For our experiments we use 500 samples of 500 dimensional normal distributions mapped through linear functions with additive gaussian noise. Linear transformations use Uniform[1, 2] weights and LASSO experiments use sparse transformations. We use tensorflow’s Adam optimizer with lr = .0005 for 100000 steps. Our approach of learning regularizer scale parameters can be viewed naturally through the lens of hierarchical priors (Gelman et al., 2013). More specifically this approach is implicitly performing maximum a posteriori (MAP) inference on the prior’s scale with respect to a uniform prior on that parameter. We note that though these methods for hyperparameter selection are common in the Bayesian literature, they are not widely used in practice in the deep learning community. This work aims to bring these parameters back within the scope of deep learning where they can be easily expanded to more flexible forms such as our introduced Multi-Lasso.

heading: 5.3 RE-CALIBRATION
text: The work of (Guo et al., 2017) shows that modern networks are accurate, yet systematically overconfident, a phenomenon called mis-calibration. We investigate the role of optimizing likelihood parameters to re-calibrate models. More specifically, we can fit likelihood parameter regressors on a validation set to modify an existing model’s confidence to better align with the validation set. This approach is a generalization of Guo et al. (2017)’s Temperature Scaling method, which we refer to as Global Scaling (GS) for notational consistency. Global Scaling re-calibrates classifiers with a learned global parameter, τ in the loss function: σ(~x, τ).
Fitting model-conditioned likelihood parameters to a validation set defines a broad class of recalibration strategies. From these we introduce three new re-calibration methods. Linear Scaling (LS) learns a linear mapping, l, to transform logits to a softmax temperature: σ(~x, l(~x)). Linear Feature Scaling (LFS) learns a linear mapping, l, to transform the features prior to the logits, ~f , to a softmax temperature: σ(~x, l(~f)). Finally, we introduce Deep Scaling (DS) for regressors which learns a nonlinear network, N , to transform features, ~f , into a temperature: σ(~x,N(~f)).
In Table 3 we compare our recalibration approaches to the previous state of the art: Global Scaling. We note that (Guo et al., 2017) have already shown that Global Scaling outperform Bayesian Binning into Quantiles (Naeini et al., 2015), Histogram binning (Zadrozny & Elkan, 2001), and Isotonic Regression. We recalibrate both ResNet50 (He et al., 2016) and DenseNet121 (Huang et al., 2017) on a variety of vision datasets. We measure classifier miscalibration using the Expected Calibration Error (ECE) (Guo et al., 2017) to align with prior art. We additionally evaluate Isotonic recalibration, Platt Scaling (Platt, 1999), and Vector Scaling (VS) (Guo et al., 2017), which learns a vector, ~v, to re-weight logits: σ(~v~x, 1). LS and LFS tend to outperform other approaches like GS and VS, which demonstrates that richer likelihood parametrizations can improve calibration akin to how richer models can improve prediction. Our experiments leverage Tensorflow’s Dataset APIs that include the SVHN, (Netzer et al., 2011), ImageNet (Deng et al., 2009), CIFAR-100, CIFAR-10 (Krizhevsky, 2009) datasets. We use Keras implementations of DenseNet-121 (Huang et al., 2017) and ResNet-50 (He et al., 2016) with default initializations. For optimization we use Adam with lr = 0.0001, β1 = .9, β2 = .99 (Kingma & Ba, 2015) and train for 300 epoch with a batch size of 512.
For recalibrating regressors, we compare against the previous state of the art, Kuleshov et al. (2018), who use an Isotonic regressor to correct a regressors’ confidence. We use the same experimental setting as Kuleshov et al. (2018) including the UCI datasets (Dua & Graff, 2017), and regressor calibration metric (CAL). Table 4 shows that our approaches can outperform this baseline as well as the regression equivalent of Global Scaling. Inputs and targets are scaled to unit norm and variance prior to fitting for all regression experiments and missing values are imputed using scikit-learn’s “SimpleImputer” (Pedregosa et al., 2011). Experiments utilize Keras’ layers API with two hidden rectified linear unit (ReLU) layers, Glorot uniform initialization (Dahl et al., 2013; Glorot & Bengio, 2010) and Adam optimization with lr = 0.001 for 3000 steps without minibatching.

heading: 6 EXPERIMENTAL DETAILS

heading: 7 CONCLUSION
text: Optimizing the full likelihood can improve model quality by adapting losses and regularizers. Full likelihoods are agnostic to the architecture, optimizer, and task, which makes them simple substitutes for standard losses. Global, data, and predicted likelihood parameters offer different degrees of expressivity and efficiency. In particular, predicted parameters adapt the likelihood to each data point during training and testing without significant time and space overhead. By including these parameters in a loss function one can improve a model’s robustness and generalization ability and create new classes of outlier detectors and recalibrators that outperform baselines. More generally, we hope this work encourages joint optimization of model and likelihood parameters, and argue it is likely that your loss should be a likelihood.

Review summaries:
The paper proposes the use of complete parametrized likelihoods for providing supervision in place of the commonly used loss functions. The normal distribution, the categorical distribution defined by softmax and the likelihood of the robust rho-estimator are considered. The main idea is that by including the parameters of these likelihoods and optimizing over them, one can increase robustness, detect outliers and achieve re-calibration. In addition, by considering parametric priors and tuning their parameters one can obtain more flexible regularizers over the trainable parameters of a model.

This paper studied loss functions by interpreting them from a likelihood viewpoint and by proposing to optimize "full" likelihoods for robust modeling, outlier-detection, and re-calibration purposes. Many loss functions stem from maximum likelihood estimation (MLE). For instance, the quadratic loss stems from MLE under Gaussianity, the absolute deviation loss stems from MLE under the Laplace noise assumption, and the check loss from MLE under the asymmetry Laplace noise assumption. What is common about these noise assumptions is that they contain scale/location parameters. Traditionally, in the machine learning community, these loss functions are used by ignoring the underlying noise assumptions and so the scale parameters are abandoned. The point of the paper is to take into account these scale parameters when solving the resulting optimization problems in learning.    

This paper's starting point is a probabilistic interpretation of three losses: MSE, cross-entropy, and the loss introduced in reference (Barron 2019). It proposes the minimize the average loss jointly over the predictor's parameters $\theta$, but also the loss' own parameters $\phi$, vary, yielding an adaptive loss. It categorizes ways to define losses according to whether they depend on the data value, on the data index but not its value, or are independent of the data. The jointly optimized loss yields superior performance as re-calibrators (table 2 column CAL for regressors and table 5 for classifiers). It allows a natural definition of outlier detectors (sec  5.2)