## 3 Systems
### Query-by-Example Spoken Term Detection
#### 3.2.1 End-to-End with Language Adaptation System (E2E + LA)
The positive audio segment contains the same terms as the query, while the negative audio segment is a randomly-selected audio segment extracted from the training set that does not match with the query term. Then, for each group, the tuples \((Q,S^{(P)})\) and \((Q,S^{(N)})\) are created to calculate the attention matrix, \(G\), for each tuple and the corresponding vector representations, \((V_{Q}^{(P)},V_{S}^{(P)})\) and \((V_{Q}^{(N)},V_{S}^{(N)})\). The \(V_{Q}\) vector representation differs depending on the audio segment for which it is computed, due to the two-way attention mechanism. The cosine distance is employed to measure the similarity between the tuples \(V_{Q}\) and \(V_{S}\), as in Equation (10):  
\[l(V_{Q},V_{S})=(1-\cos(V_{Q},V_{S}))/2. \tag{10}\]  
To minimise the distance between the query and the positive audio segment and maximise the distance between the query and the negative audio segment, the hinge objective function in Equation (11) is used. \[L_{hinge}=\max\{0,M+l((V_{Q}^{(P)},V_{S}^{(P)}))-l((V_{Q}^{(N)},V_{S}^{(N)}) )\}, \tag{11}\]  
where \(M\) is the maximum allowable distance, which is set to 1. For query and audio segment representation, 13-dimensional MFCC extracted using the Kaldi toolkit [74] and Python Speech Features library are employed. For MFCC computation, a 0.025 s-length sliding window with a shift equal to 0.01 s is used. The shared RNNs consist of two layers with 128 LSTM units for all the models. An Adam optimizer with a learning rate of 0.00005 and a minibatch of 128 are employed. The neural networks are implemented in Pytorch and are trained for four epochs. The system was initially trained on the English LibriSpeech database [178]. Specifically, 500 randomly selected terms that have at least six phonemes and last between 0.5 and 1.0 s were employed to form training samples from 2 audio segments that contain the same term (one for the query \((Q)\) and another for the positive audio segment \((S^{P})\)) and one audio segment that contains a different term for the negative audio segment \((S^{N})\). For each training epoch, there were 1000 groups in total, which consisted of the \((Q,S^{P},S^{N})\) tuple each. Then, the neural networks in the two-way attention mechanism are retrained for two epochs using the MAVIR development data. This aims to benefit from transfer learning by adapting the initial system trained on a language-independent setup to a small database in Spanish. The search of each query in each utterance applies an adaptive sliding window in the utterances to form the audio segments for attentive pooling network-based query/audio segment matching. The length of the sliding window depends on the length of the query. Different window lengths (i.e., 50, 100, 150 and 200 frames) with a 50% overlap are employed so that the window length for searching each query is the upper limit that best approximates the query length (e.g., if the query has 37 frames, the window length is set to 50; if the query has 160 frames, the window length is set to 200 and so on). Once the final vectors \(V_{Q}\) and \(V_{S}\) representing the query and the audio segment are obtained according to Figure 2, the cosine distance between both vectors is taken as the final score for each detection.