# Uncertainty-Aware Active Meta-Learning for Few-Shot Text Classification
## 4 Methodology
### USB Loss: Uncertainty-Based Sample-Balanced Loss  
As stated above, Bayesian neural networks provide a way to quantify the uncertainty of deep learning models. The objective function for weight learning of the Bayesian neural network is expressed in Equations (7)-(9) below, where \(N\) is the number of training data, \(M\) is the size of a mini-batch, and \(S\) is the index of the mini-batch. \[\hat{L}_{VI}(\theta)=-\frac{N}{M}\sum_{i\;\epsilon\;S}\int q_{\theta}(w)logp( y_{i}|f^{w}(x_{i}))dw+KL(q_{\theta}(w)\;||\;p(w)) \tag{7}\]  
\[\hat{L}_{VI}(\theta)=-\frac{N}{M}\sum_{i\;\epsilon\;S}\int p(\epsilon)logp \Big{(}y_{i}\Big{|}f^{S(\theta,\;\epsilon)}(x_{i})\Big{)}d\epsilon+KL(q_{ \theta}(w)\;||\;p(w)) \tag{8}\]  
\[\hat{L}_{MC}(\theta):=-\frac{N}{M}\sum_{i\;\epsilon\;S}\int logp\Big{(}y_{i} \Big{|}f^{S(\theta,\;\epsilon)}(x_{i})\Big{)}dw+KL(q_{\theta}(w)\;||\;p(w)) \tag{9}\]  
In order to perform Bayesian backpropagation, the gradient of the \(ELBO\) with respect to \(\theta\), which is a parameter of the estimated distribution, is obtained, and the existing \(\theta\) is updated according to the slope. However, since backpropagation is impossible when sampling is performed, re-parameterization of \(w\) for \(\theta\) and \(\epsilon\) is the same as Equation (8). Since the calculation process of \(ELBO\) also includes integration, it is still difficult to calculate when the neural network has more than two layers. Therefore, techniques such as Equation (9) that approximate \(ELBO\) through Monte Carlo sampling are used [33]. While a class-balanced loss is designed based on class distribution, USB loss has a different design based on model uncertainty for data [38]. In the case of a loss function commonly used in deep learning, the size of the loss value greatly affects the size of the initial gradient. For example, Equations (10)-(12) show the process when differentiation is performed with logits for cross-entropy, which is mainly used for training classification models. Equation (10) is a softmax function that outputs a discrete probability distribution when the logits \(o\) obtained from the output layer of a general neural network are input. At this time, when cross-entropy is used as a loss function, as in Equation (11), the result of differentiating cross-entropy by logits is the same as subtracting the actual label y from the result of softmax, as in Equation (12). Therefore, if an operation of multiplying cross entropy loss by a specific value as a coefficient is performed, the operation plays a role in adjusting the value of gradients. \[p_{j}=softmax\;(o)=\frac{e^{j}}{\sum_{i}e^{i}} \tag{10}\]  
\[CE(p)=-\sum_{i}y_{i}\log(p_{i}) \tag{11}\]  
\[\frac{\partial CE}{\partial o}=p-y \tag{12}\]  
Our hypothesis shows that more efficient learning is possible by focusing on the characteristics between the loss function and the gradients and applying a penalty to increase the loss on data with high uncertainty. This improvement is achieved by reflecting the uncertainty obtained from the data and the model. Algorithm 1 describes the process of calculating USB loss. In order to calculate the USB loss, forward propagation is performed \(T\) times, as in line 3, using the MC dropout technique, and the uncertainty of the model can be quantified by calculating variance based on this trial. First, in line 5, the average value \(\hat{y}_{c,\;s}\) is calculated for the MC dropout trial, and the variance \(variance_{\hat{y}_{c,\;s}}\) for each sample and class is calculated using the average value in line 6. Then, the sample-wise uncertainty \(uncertainty_{\hat{y}_{s}}\) is calculated using the average of the variance of each class in line 7.