## 2 Proposed Methods for Speaker Recognition
#### 2.1.5 Loss Function  
During the model's training, we chose the triplet loss as the loss function. Triplet loss randomly selects a sample from all training samples as the anchor. Then, we randomly select a sample of the same category as an anchor and call it positive. Finally, a sample of a different category from anchor was randomly selected and called negative. The above three represent the triplets in triplet loss, and for the anchor, positive, and negative triplet loss. We can write the following equation:  
\[L=max(0,\;d(A,\;P)-d(A,\;N)+M)\;, \tag{8}\]  
where the anchor, positive, and negative are denoted as \(A\), \(P\), and \(N\), respectively. \(M\) is the margin, which is an adjustable parameter greater than 0; \(d(\;)\) is the distance calculation function, and in this case, the Euclidean distance [32; 33] is used. We defined \(d(x,y)\) as the Euclidean distance between \(x\) and \(y\), where \(x=(x_{1},x_{2},\cdots,x_{n})\) and \(y=(y_{1},y_{2},\cdots,y_{n})\). The algorithm for \(d(x,y)\) is as follows:  
\[d(x,y)=\sqrt{\left(x_{1}-y_{1}\right)^{2}+\left(x_{2}-y_{2}\right)^{2}+\cdots +\left(x_{i}-y_{i}\right)^{2}}\;, \tag{9}\]  
After calculating the positive and negative Euclidean distances of the anchor, we divided triplet loss into the following three types:  
\[L=\left\{ \begin{array}{ll}L_{1},&\text{if }\;d(A,P)<d(A,N)+M\\ L_{2},&\text{if }\;d(A,P)<d(A,N)<d(A,P)+M\\ L_{3},&\text{if }\;d(A,P)>d(A,N)\end{array} \right., \tag{10}\]  
The first case \(L_{1}\) is called an easy triplet. In this case, the anchor and positive values are close, which is the best case. The second case \(L_{2}\) is called a semi-hard triplet. In this case, although the anchor is similar to the positive, it is also similar to the negative because the difference between the two is within a margin. The third case \(L_{3}\) is called the hard triplet. In this case, the distance between the anchor and the positive is considerable, which is the worst case. Figure 7 shows the differences before and after the triplet-loss operation. Figure 6: LSTM internal architecture diagram. Figure 7: Schematic diagram of the operation of triplet loss. The state before training was \(L_{3}\). After training, triplet loss shortens the distance between the anchor and the positive and extends the distance between the anchor and the negative. After the training, the state was \(L_{1}\). Figure 7 shows that the anchor and the positive have become close, and the distance between the anchor and the negative has increased significantly. Bidirectional Long Short-Term Memory with Mel-Frequency Cepstral Coefficients for Triplet Loss (BLSTM-MFCC-TL) Method  
Based on the LSTM-MFCC-TL method combined with BLSTM, we propose a BLSTM-MFCC-TL method. BLSTM is composed of a two-way two-layer LSTM that obtains two-way information, expanding the model's perception field. The speaker recognition process of the proposed BLSTM-MFCC-TL method is shown in Figure 8. We divided the BLSTM-MFCC-TL method into five steps, where the fourth step differs from the LSTM-MFCC-TL method, and BLSTM [27] is used as the training model. The fourth step of the BLSTM model in the BLSTM-MFCC-TL method was proposed, as shown in Figure 9, and the parameter settings in the BLSTM model are listed in Table 2. Due to the BLSTM architecture, the number of parameters increased to 256, twice that of the LSTM architecture. Although the BLSTM architecture increases the number of parameters, it can help improve accuracy. The output size of the fully connected layer is the same as that of the LSTM-MFCC-TL method. Therefore, at the end of the fourth step, the BLSTM model outputs a feature vector of size \((1,\,128)\). Figure 8: BLSTM-MFCC-TL method architecture diagram. Figure 9: BLSTM model architecture diagram in the BLSTM-MFCC-TL method. BLSTM [27] used in the BLSTM model is a bidirectional application of LSTM architecture. Figure 10 shows a schematic of the BLSTM architecture.