# Weighted Cluster-Range Loss and Criticality-Enhancement Loss for Speaker Recognition
## 3 Proposed Approaches
### Weighted Cluster-Range Loss  
As discussed in [38], the terms in triplet loss may contribute differently to the performance, In this work, we borrow the idea from Weighted Triplet Loss (WTL) [38] into cluster-range loss and propose a comprehensive loss function: Weighted Cluster-Range Loss (WCRL). The only difference between cluster-range loss and weighted cluster-range loss is the weighting factors imposed on the terms of the loss function. Different from WTL, the weighting factors in WCRL are hyperparameters. Like cluster-range loss, the weighted cluster-range loss also consists of two parts, i.e., the hard loss (\(L_{\text{WCRL}}^{\text{hard}}\)) and the normal loss (\(L_{\text{WCRL}}^{\text{normal}}\)). For speaker identification, the weighting factor \(\omega_{1}\) is a hyperparameter that is slightly larger than one, and \(\omega_{2}\) is designed to keep one, which we will discuss later. If we set both \(\omega_{1}\) and \(\omega_{2}\) to one, then the weighted cluster-range loss degrades into the standard cluster-range loss. \[ \begin{split} L_{\text{WCRL}}^{\text{hard}}&=\frac{1 }{K\times M}\sum_{i=1}^{K}\sum_{j=1}^{M}\left[\varepsilon_{i}^{n}-\omega_{2}h _{i,j}^{p}+\alpha\right]_{+}\\ &+\frac{1}{K\times M}\sum_{i=1}^{K}\sum_{j=1}^{M}\left[\omega_{1 }h_{i,j}^{n}-\varepsilon_{i}^{p}+\alpha\right]_{+}\end{split}  \tag{21}\]  
Figure 4: Diagram of the employed self-attention module. \[L_{\text{WCRL}}^{\text{normal}}=\frac{1}{K\times(K-1)\times M^{2}\times(M-1)} \tag{22}\] \[\times\sum_{i=1}^{K}\sum_{a=1}^{M}\sum_{p=1}^{M-1}\sum_{n=1}^{(K-1 )\times M}\left[\omega_{1}s_{i,a,n}-\omega_{2}s_{i,a,p}+\mathbf{\alpha}\right]_{+}\] \[L_{\text{WCRL}}=L_{\text{WCRL}}^{\text{hard}}+m\times L_{\text{ WCRL}}^{\text{normal}} \tag{23}\]  
Figure 5 illustrates the learning process of weighted cluster-range loss. As mentioned before, the speaker identification task could be treated as a multi-class classification process. As shown in Figure 5, the embeddings of Class 1 (C1) and Class 3 (C3) are already correctly classified, and thus, it is unnecessary to pay more attention to them. Besides, for embeddings in Class 2 (C2) and Class 4 (C4), \(\mathbf{a}\) is the representative of those close to the center of the cluster, while \(\mathbf{b}\) and \(\mathbf{c}\) are the representatives of those far away from the center of the corresponding cluster. Intuitively, it is quite easy to correctly classify \(\mathbf{a}\) into C1, while \(\mathbf{b}\) and \(\mathbf{c}\) tend to be misclassified into the class of the other. For the classification task, the final output category is the one with the highest score, even if the highest score is actually not that high. Suppose that \(S_{2}=S_{1}+e(\mathbf{e}\) is small and \(\mathbf{e}>0)\); to correctly classify \(\mathbf{b}\), we just need to slightly diminish \(S_{2}\), while it does not matter whether \(S_{1}\) increases greatly. We argue that \(\mathbf{b}\) and \(\mathbf{c}\) will stand a good chance of being correctly classified as long as they get rid of such a critical state. Furthermore, \(\mathbf{a}\), \(\mathbf{b}\), and \(\mathbf{c}\) are essentially different embeddings, and thus, it might be easier to diminish the similarity between \(\mathbf{b}\) and \(\mathbf{c}\) than to enlarge the similarity between \(\mathbf{b}\) and \(\mathbf{a}\). Thus, we hope to reduce \(s_{b,\mathbf{c}}\) (namely \(S_{2}\) in Figure 5) in priority. To this end, a weighting factor \(\omega_{1}\), which is slightly larger than one, is imposed on the loss function. As is shown in Formulas (21) and (22), \(\omega_{1}\) is imposed respectively on \(s_{i,a,n}\) and \(h_{i,j}^{n}\). We have also tried the situation where \(\omega_{1}\) is also imposed on \(e_{i}^{n}\), which however did not show satisfactory performance. We suspect that this is because \(e_{i}^{n}\) represents those hardest samples and does not contribute much to the overall classification accuracy. Moreover, we also impose weighting factor \(\omega_{2}\) on the loss function.