Improving the Accuracy of Learning Example Weights for Imbalance Classification

1 INTRODUCTION . Classification is a fundamental task in machine learning , but in practical classification applications , the number of examples among classes may differ greatly , even by several orders of magnitude . Standard learning methods train the classification model on such an imbalanced data set , which makes the trained model biased . This bias is that the model will prefer the majority class and easily misclassify the minority class examples . This class-imbalance problem exists in many domains , such as Twitter spam detection ( Li & Liu , 2018 ) , named entity recognition ( Grancharova et al. , 2020 ) in text classification , and object detection ( Oksuz et al. , 2020 ) , video surveillance ( Wu & Chang , 2003 ) in image classification . There are very rich research lines on using the methods of weighting examples to solve the class imbalance problem . In general , the weight of the minority class is higher than that of the majority class , so that the bias towards the majority class is alleviated . Typically , the example weight value of each class is often set to inverse class frequency ( Wang et al. , 2017 ) or inverse square root of class frequency ( Mahajan et al. , 2018 ) . However , the example weights in these methods are designed empirically , hence they can not be adapted to different datasets and may perform poorly . Recent work has studied the methods of using learning mechanisms to adaptively calculate the example weights . Ren et al . ( 2018 ) propose to use a meta-learning paradigm ( Hospedales et al. , 2020 ) to learn the weights . In this method , the example weights can be regarded as a meta-learner and the classification model is a learner . The meta-learner guides the learner to learn by weighting the example loss in the model optimization objective . More specifically , the model objective is to get the optimal model that minimizes the example-weighted loss of the imbalanced training set . Obviously , different weights will affect the performance of the optimal model . Which weight values make the corresponding optimal model the best ? This method collects a small balanced validation set and evaluates the weight values through the validation performance of the model . Therefore , the meta-learner objective , namely meta-objective , gives the best weights that make the optimal model minimize the loss of the balanced validation set . This optimization problem is challenging . The key is that , in the meta-objective , the weights indirectly affect the loss through the optimal model , so it ∗Corresponding author is necessary to clearly define the dependence of the weights and the optimal model in the model objective for optimizing the weights . However , it is expensive to get this dependence through multiple gradient descent steps in the model objective . Ren et al . ( 2018 ) propose an online approximation method to estimate this dependence , that is , the method trains the model using a gradient descent step in the model objective and then can determine the relationship between the weights and the trained model in this step . Hu et al . ( 2019 ) propose to update the example weights iteratively to replace the re-estimation proposed by Ren et al . ( 2018 ) , but also adopt the local approximation to optimize the weights . However , this approximation only considers the influence of the weights on the trained model in a short term ( in a descent step ) , resulting in inaccurate learning of the weights . In this paper , we firstly propose a novel learning mechanism that can obtain the precise relationship between the weights and the trained model in the model objective , so that the weights and model can be optimized more accurately . In this mechanism , we convert the model objective into an equation of the current model and weights . Then , we derive their relationship from this equation , and then we use this relationship to optimize the weights in the meta-objective and update the corresponding model . Since this optimization process always satisfies this equation , we call it learning with a constraint . However , the mechanism only uses the model objective to calculate the relationship but does not optimize the model for the model objective . To solve this problem , we integrate the method proposed by Hu et al . ( 2019 ) into our learning mechanism and propose a combined algorithm . In this algorithm , the method of Hu et al . can help to further optimize the model in the model objective , and our learning mechanism can make the weights and model learn more accurately . Finally , we conduct a lot of experiments to validate the effectiveness of this algorithm . The experimental settings include ( 1 ) different domains , namely text and image classification ; ( 2 ) different scenarios , namely binary and multi-class classification , ( 3 ) different imbalance ratios . The results show that our algorithm not only outperforms the state-of-the-art ( SOTA ) method in data weighting but also performs best among other comparison methods in varieties of settings . The remainder of this paper is organized as follows . Section 2 introduces preliminaries of the two objectives and the main idea of Hu et al . ( 2019 ) . Section 3 presents our mechanism of learning with a constraint and the combined algorithm . Section 4 presents the experimental settings and evaluation results . Section 5 summarizes the related work and Section 6 concludes this paper . 2 PRELIMINARIES AND NOTATIONS . Let ( x , y ) be the input and target pair . For example , in image classification , x is the image and y is the image label . Let Dtrain denote the train set , and Dtrain = { ( xi , yi ) , 1 6 i 6 N } . Let Dval be a small balanced validation set , andDval = { ( xi , yi ) , 1 6 i 6M } whereM N . We denote neural network model as Φ ( x , θ ) , where θ ∈ RK is the model parameter . The predicted value ŷ = Φ ( x , θ ) . We use loss function f ( ŷ , y ) to measure the difference between predicted value ŷ and target value y , and the loss function of data xi is defined as fi ( θ ) for clarity . Standard training method is to minimize the expected loss on the training set : ∑N i=1 fi ( θ ) , and each example has same weight . However , for an imbalanced data set , the model obtained by this method will be biased towards the majority class . Here , we aim to learn a model parameter θ that is fair to the minority class and the majority class by minimizing the weighted loss of training examples : θ∗ ( w ) = arg minθ N∑ i=1 wifi ( θ ) ( 1 ) where w = ( w1 , ... , wN ) T is the weights of all training examples . We use Ltrain to represent the weighted loss on the training set Dtrain . For a given w , we can obtain the corresponding optimal θ∗ from Eq.1 . Thus , there is a dependence between θ∗ and w and we write it as θ∗ = θ∗ ( w ) . Learning to Weight Examples The recent work ( Ren et al. , 2018 ) proposed a method of learning the weights of training examples . In this method , the optimal w is to make the model parameter θ∗ obtained from Eq.1 minimize the loss on a balanced validation set . It means that this model performs well on a balanced validation set , and it can fairly distinguish examples from different classes . Formally , the optimal w is given as w∗ = arg minw 1 M M∑ i=1 fvi ( θ ∗ ( w ) ) ( 2 ) where the superscript v stands for validation set . Let Lval be the loss on the validation set Dval . Learning the Parameters The recent work ( Hu et al. , 2019 ) introduced an algorithm of solving the model parameter θ∗ and weight w∗ . The algorithm optimizes θ and w alternately until convergence . In each iteration , the algorithm utilizes a gradient descent step in Eq.1 to approximate the relationship between θ and w , and then calculates the gradient ∇wLval and ∇θLtrain to update w and θ respectively . More specifically , at the t-th iteration , the algorithm first calculates the approximate relationship between θ and w through the t-th gradient descent step in Eq.1 . We define a matrix F ( θ ) = ( ∇f1 ( θ ) , ... , ∇fN ( θ ) ) , whose column vector represents the derivative of fi ( θ ) with respect to θ , so we calculate the derivative of ∇θLtrain with respect to θ as ∇θLtrain = F ( θ ) w. Then , the t-th gradient descent step of θ is given as θ̂t+1 = θt − ηθF ( θt ) wt ( 3 ) where ηθ is the descent step size on θ . In order to avoid very expensive calculations , the algorithm ignores the influence ofw on θt . Therefore , in the single gradient descent step , θ̂t+1 linearly depends on w. Then , based on this linear dependence , the algorithm can calculate the gradient ∇wLval and uses gradient descent to update w , and then updates θ again to make it perform better on validation set . Substituting the updated θ̂t+1 into Eq.2 , we have Lval = 1M ∑M i=1 f v i ( θ̂t+1 ( w ) ) . We can observe that the w acts on θ̂t+1 and then affects Lval . Thus , combining Eq.3 , we can calculate the gradient ∇wLval = ( ∇wθ̂t+1 ) T ∇θ̂t+1Lval = −ηθF ( θt ) T∇θ̂t+1Lval , so the update on w at t step is given as wt+1 = wt + ηwηθF ( θt ) T∇θ̂t+1Lval ( 4 ) where ηw is the descent step size on w. According to gradient descent theory , when ηw is appropriately small , Lval ( wt+1 ) ≤ Lval ( wt ) . This means using wt+1 to update θ performs better than wt . Therefore , the algorithm substitutes the updated wt+1 into Eq.3 and obtain the new update on θ θt+1 = θt − ηθF ( θt ) wt+1 ( 5 ) where θt+1 satisfies Lval ( θt+1 ) ≤ Lval ( θ̂t+1 ) , that is , θt+1 have better validation performance than θ̂t+1 . Finally , the algorithm repeatedly calculates Eq.3 , 4 and 5 and alternately optimizes θ and w until convergence . 3 NEW METHOD OF LEARNING THE PARAMETERS . In this section , we introduce a new method to learn the model parameter θ∗ and weight w∗ in Eq.1 and Eq.2 . First , in Section 3.1 , we propose to learn θ and w with a constraint , which can accurately optimize θ and w. Then , in Section 3.2 , we propose a combined method to train θ and w to make the model parameter θ have better performance . 3.1 LEARNING WITH A CONSTRAINT . In the section , we first analyze the difficulty of solving θ∗ and w∗ . Gradient-based optimization is a commonly used method in machine learning . Thus , we first need to calculate the gradient∇θLtrain and ∇wLval . Based on Eq.2 , we have ∇wLval = ( ∇wθ∗ ) T∇θ∗Lval . However , it is difficult to explicitly give the form of function θ∗ ( w ) , resulting in ∇wLval can not be calculated directly . The previous work obtained the relationship between θ and w through the gradient descent process of θ , and only considered the influence of w on θ in a single gradient descent step . Based on this relationship , calculating the gradient and updating the parameter is not precise . Here , we obtain the relationship between θ and w from a new perspective . First , we observe the gradient∇θLtrain , that is , ∇θLtrain = F ( θ ) w = c ( 6 ) Algorithm 1 : Learning to Weight Examples Using a Combination Method Input : The network model parameter θ The weight of training examples w Training set Dtrain ; Validation set Dval The number of iterations of the combination method T The number of iterations of our method T ′ 1 Initialize model parameter θ and weight w 2 for t = 0 ... T − 1 do 3 Calculate the relationship between θ and w on Dtrain though Eq.3 4 Optimize w on Dval though Eq.4 5 Update θ though Eq.5 6 for t′ = 0 ... T ′ − 1 do 7 Calculate the derivative∇wθ on Dtrain though Eq.7 8 Optimize w on Dval though Eq.8 9 Update θ though Eq.9 Output : Trained model parameter θ∗ and weight w∗ where c is the gradient value . We can see that changing the value of w can find corresponding θ to satisfy Eq.6 . It means that there is a functional relationship between θ and w in Eq.6 . Because all θ and w satisfying this equation have the same value of ∇θLtrain , we also call Eq.6 a constraint of θ and w. In particular , the optimal model parameter θ∗ and w satisfy the constraint : F ( θ∗ ) w = 0 . Then , we can make use of the constraint to derive a precise relationship between θ and w. Our network model may be very complex , and we can not explicitly give the functional form of θ and w according to the constraint . However , by applying the implicit function theorem , the derivative of θ with respect to w in Eq.6 can be obtained as follow ∇wθ = − [ ∇θ ( F ( θ ) w ) ] −1F ( θ ) = −H−1F ( θ ) where H ∈ RK × RK is the Hessian matrix , namely , the second derivative of Ltrain with respect to θ . However , calculating an exact Hessian matrix is very expensive . Especially nowadays network models have a huge amount of parameters . In addition , in this case , we require the inverse of H , rather than H itself . Therefore , we adopt diagonal approximation to evaluate H ( Bishop , 2006 ) . In other words , we only need to calculate the diagonal elements of H . Furthermore , it is trivial to calculate the inverse by taking the reciprocal of the diagonal elements . Let h ∈ RK be the reciprocal of the diagonal elements of H . Then , the derivative is evaluated as ∇wθ = −diag ( h ) F ( θ ) ( 7 ) Next , we can make use of the derivative to calculate the gradient∇wLval , and then update w and θ . The update process always satisfies the constraint of Eq.6 , so we call it learning with a constraint . Combining Eq.7 , we have∇wLval = −F ( θ ) T diag ( h ) ∇θLval . Thus , the update of w is w′ = w + η′wF ( θ ) T diag ( h ) ∇θLval ( 8 ) where η′w is the step size . Then , we use the updated w ′ to calculate the corresponding θ′ in the constraint . Since we do not know the explicit functional form of θ and w in Eq.6 , we use the first order derivative to approximate θ′ . Combing Eq.7 , θ′ is evaluated as θ′ ≈ θ +∇wθ ( w′ − w ) = θ − diag ( h ) F ( θ ) ( w′ − w ) ( 9 ) Finally , under the condition of satisfying the constraint , we repeatedly optimize w and θ , corresponding to Eq.8 and Eq.9 , until convergence . The detailed proof of this convergence can be found in Theorem 1 in Appendix A.2 .

Summary: The paper presents a new method for learning example weights together with the parameters of a deep neural network. The difference between the proposed method and previous work is that they use a constraint to tie together the values of the parameters and the weights as they do the joint optimization through gradient descent. They do extensive experiments using both text and image datasets, with different imbalance ratios and show that the proposed method outperforms the state-of-the-art in terms of accuracy on a (balanced) test set.