Deep $k$-NN Label Smoothing Improves Reproducibility of Neural Network Predictions

1 INTRODUCTION . Deep neural networks ( DNNs ) have proved to be immensely successful at solving complex classification tasks across a range of problems . Much of the effort has been spent towards improving their predictive performance ( i.e . accuracy ) , while comparatively little has been done towards improving the stability of training these models . Modern DNN training is inherently noisy due to factors such as the random initialization of network parameters , the mini-batch ordering , and effects of various data augmentation or pre-processing tricks , all of which are exacerbated by the non-convexity of the loss surface . This results in local optima corresponding to models that have very different predictions on the same data points . This may seem counter-intuitive , but even when the different runs all produce very high accuracies for the classification task , their predictions can still differ quite drastically as we will show later in the experiments . Thus , even an optimized training procedure can lead to high prediction churn , which refers to the proportion of sample-level disagreements between classifiers caused by different runs of the same training procedure1 . In practice , reducing such predictive churn can be critical . For example , in a production system , models are often continuously improved on by being trained or retrained with new data or better model architectures and training procedures . In such scenarios , a candidate model for release must be compared to the current model serving in production . Oftentimes , this decision is conditioned on more than just overall offline test accuracy– in fact , oftentimes the offline metrics are not completely aligned with actual goal , especially if these models are used as part of a larger system ( e.g . maximizing offline click-through rate vs. maximizing revenue or user satisfaction ) . As a result , these comparisons oftentimes require extensive and costly live experiments , requiring human evaluation in situations where the candidate and the production model disagree ( i.e . in many situations , the true labels are not available without a manual labeler ) . In these cases , it can be highly desirable to lower prediction churn . Despite the practical relevance of lowering predictive churn , there has been surprisingly little work done in this area , which we highlight in the related work section . In this work , we focus on predictive churn reduction under retraining the same model architecture on an identical train and test set . Our main contributions are as follows : • We provide one of the first comprehensive analyses of baselines to lower prediction churn , showing that popular approaches designed for other goals are effective baselines for churn reduction , even compared to methods designed for this goal . 1Concretely , given two classifiers applied to the same test samples , the prediction churn between them is the fraction of test samples with different predicted labels . • We improve label smoothing , a global smoothing method popular for improving model confidence scores , by utilizing the local information leveraged by the k-NN labels thus introducing k-NN label smoothing which we show to often outperform the baselines on a wide range of benchmark datasets and model architectures . • We show new theoretical results for the k-NN labels suggesting the usefulness of the k-NN label . We show under mild nonparametric assumptions that for a wide range of k , the kNN labels uniformly approximates the Bayes-optimal label and when k is tuned optimally , achieves the minimax optimal rate . We also show that when k is linear in n , the distribution implied by the k-NN label approximates the original distribution smoothed with an adaptive kernel . 2 RELATED WORKS . Our work spans multiple sub-areas of machine learning . The main problem this paper tackles is reducing prediction churn . In the process , we show that label smoothing is an effective baseline and we improve upon it in a principled manner using deep k-NN label smoothing . Prediction Churn . There are only a few works which explicitly address prediction churn . Fard et al . ( 2016 ) proposed training a model so that it has small prediction instability with future versions of the model by modifying the data that the future versions are trained on . They furthermore propose turning the classification problem into a regression towards corrected predictions of an older model as well as regularizing the new model towards the older model using example weights . Cotter et al . ( 2019 ) ; Goh et al . ( 2016 ) use constrained optimization to directly lower prediction churn across model versions . Simultaneously training multiple identical models ( apart from initialization ) while tethering their predictions together via regularization has been proposed in the context of distillation ( Anil et al. , 2018 ; Zhang et al. , 2018 ; Zhu et al. , 2018 ; Song & Chai , 2018 ) and robustness to label noise ( Malach & Shalev-Shwartz , 2017 ; Han et al. , 2018 ) . This family of methods was termed “ co-distillation ” by Anil et al . ( 2018 ) , who also noted that it can be used to reduce churn in addition to improving accuracy . In this paper , we show much more extensively that co-distillation is indeed a reasonable baseline for churn reduction . Label smoothing . Label smoothing ( Szegedy et al. , 2016 ) is a simple technique that proposes to train a model the model on the soft labels obtained by a convex combination of the hard true label and the soft uniform distribution across all the labels . It has been shown that it prevents the network from being over-confident and leads to better confidence calibration ( Müller et al. , 2019 ) . Here we show that label smoothing is a reasonable baseline for reducing prediction churn , and we moreover enhance it for this task by smoothing the labels locally via k-NN rather than a the pure global approach mixing with the uniform distribution . k-NN Theory . The theory of k-NN classification has a long history ( e.g . Fix & Hodges Jr ( 1951 ) ; Cover ( 1968 ) ; Stone ( 1977 ) ; Devroye et al . ( 1994 ) ; Chaudhuri & Dasgupta ( 2014 ) ) . To our knowledge , the most relevant k-NN classification result is by Chaudhuri & Dasgupta ( 2014 ) , who show statistical risk bounds under similar assumptions as used in our work . Our analysis shows finitesample L∞ bounds on the k-NN labels , which is a stronger notion of consistency as it provides a uniform guarantee , rather than an average guarantee as is shown in previous works under standard risk measures such asL2 error . We do this by leveraging recent techniques developed in Jiang ( 2019 ) for k-NN regression , which assumes an additive noise model instead of classification . Moreover , we provide to our knowledge the first consistency guarantee for the case where k grows linearly with n. Deep k-NN . k-NN is a classical method in machine learning which has recently been shown to be useful when applied to the intermediate embeddings of a deep neural network ( Papernot & McDaniel , 2018 ) to obtain more calibrated and adversarially robust networks . This is because standard distance measures are often better behaved in these representations leading to better performance of k-NN on these embeddings than on the raw inputs . Jiang et al . ( 2018 ) uses nearest neighbors on the intermediate representations to obtain better uncertainty scores than softmax probabilities and Bahri et al . ( 2020 ) uses the k-NN label disagreement to filter noisy labels for better training . Like these works , we also leverage k-NN on the intermediate representations but we show that utilizing the k-NN labels leads to lower prediction churn . 3 ALGORITHM . Suppose that the task is multi-class classification with L classes and the training datapoints are ( x1 , y1 ) , ... , ( xn , yn ) , where xi ∈ X , and X is a compact subset of RD and yi ∈ RL , where represents the one-hot vector encoding of the label– that is , if the i-th example has label j , then yi has 1 in the j-th entry and 0 everywhere else . Then we give the formal definition of the smoothed labels : Definition 1 ( Label Smoothing ) . Given label smoothing parameter 0 ≤ a ≤ 1 , then the smoothed label y is ( where 1L denotes the vector of all 1 ’ s in RL ) . yLSa : = ( 1− a ) · y + a L · 1L . We next formally define the k-NN label , which is the average label of the example ’ s k-nearest neighbors in the training set . Let us use shorthand X : = { x1 , ... , xn } and yi ∈ RL . Definition 2 ( k-NN label ) . Let the k-NN radius of x ∈ X be rk ( x ) : = inf { r : |B ( x , r ) ∩X| ≥ k } whereB ( x , r ) : = { x′ ∈ X : |x−x′| ≤ r } and the k-NN set of x ∈ X beNk ( x ) : = B ( x , rk ( x ) ) ∩X . Then for all x ∈ X , the k-NN label is defined as ηk ( x ) : = 1 |Nk ( x ) | n∑ i=1 yi · 1 [ xi ∈ Nk ( x ) ] . The label smoothing method can be seen as performing a global smoothing . That is , every label is equally transformed towards the uniform distribution over all labels . While it seems almost deceptively simple , it has only recently been shown to be effective in practice , specifically for better calibrated networks . However , since this smoothing technique is applied equally to all datapoints , it fails to incorporate local information about the datapoint . To this end , we propose using the k-NN label , which smooths the label across its nearest neighbors . We show theoretically that the k-NN label can be a strong proxy for the Bayes-optimal label , that is , the best possible prediction one can make given the uncertainty . In other words , compared to the true label ( or even the label smoothing ) , the k-NN label is robust to variability in the data distribution and provides a more stable estimate of the label than the original hard label which may be noisy . Training on such noisy labels have been shown to hurt model performance ( Bahri et al. , 2020 ) and using the smoothed labels can help mitigate these effects . To this end , we define k-NN label smoothing as follows : Definition 3 ( k-NN label smoothing ) . Let 0 ≤ a , b ≤ 1 be k-NN label smoothing parameters . Then the k-NN smoothed label of datapoint ( x , y ) is defined as : ykNNa , b = ( 1− a ) · y + a · ( b · 1 L · 1L + ( 1− b ) · ηk ( x ) ) . We see that a is used to weight between using the true labels vs. using smoothing , and b is used to weight between the global vs. local smoothing . Algorithm 1 shows how k-NN label smoothing is applied to deep learning models . Like Bahri et al . ( 2020 ) , we perform k-NN on the network ’ s logits layer . Algorithm 1 Deep k-NN label smoothing Inputs : 0 ≤ a , b ≤ 1 , Training data ( x1 , y1 ) , ... , ( xn , yn ) , model training procedureM . Train model M0 on ( x1 , y1 ) , ... , ( xn , yn ) withM . Let z1 , ... , zn ∈ RL be the logits of x1 , ... , xn , respectively , w.r.t . M0 Let ỹi be the k-NN smoothed label of ( zi , yi ) computed w.r.t . dataset ( z1 , y1 ) , ... , ( zn , yn ) . Train model M on ( x1 , ỹ1 ) , ... , ( xn , ỹn ) withM .

Summary: The main objective of this paper is to reduce the model stability, in particular, the prediction churn of neural networks. The prediction churn is defined as the changed prediction w.r.t. model randomness, e.g. multiple runs of networks. The paper proposed to use a interpolated version of global label smoothing and k-NN label smoothing. Theoretically it is shown that k-NN rule converges to the Bayes rule when k is small, and converges to a kernel smoothed version of Bayes rule when k is linear in n. Experiments are conducted that show the proposed method gives highest test accuracy and lowest churn rate in most cases.