## 4 Shingle Embedding
### Neural Network with Triplet Loss  
As a second embedding approach, we use neural networks to reduce the dimensionality of the audio shingles. Such networks can be used to learn non-linear functions that map high-dimensional input representations to low-dimensional output representations. We now show how the dimensionality of the audio shingles can be reduced using a convolutional neural network trained with the triplet loss [33]. During training, our network embeds three shingles for computing the loss, which is then used for updating the parameters of the network. This will be explained in detail later in this section. Figure 3 shows an illustration of this process. For learning embeddings, a loss function that enforces specified similarities and dissimilarities in the embedding space is used. An example of such a loss function is the _hinge loss_, which has been used to learn representations for cross-modal score-to-audio embeddings [45] and for artist similarity [46]. A related loss function is the _triplet loss_, which was developed for the task of face recognition [33] and then adapted for audio and music processing tasks such as speech retrieval [47], sound event classification [48], audio fingerprinting [49], artist clustering [50], music similarity [51], and cover song retrieval [37]. The latter study is conceptually similar to our approach, but presents results that are worse than those achieved by more traditional approaches [21]. Figure 3: Schematic overview of the triplet embedding: Anchor, positive, and negative shingles \((S^{a},S^{p},S^{n})\) are embedded into the vectors \((\mathbf{x}^{a},\mathbf{x}^{p},\mathbf{x}^{n})\) by a neural network. To define the triplet loss in our scenario, we select three shingles: An anchor shingle \(\mathsf{S^{a}}\), a positive shingle \(\mathsf{S^{P}}\), and a negative shingle \(\mathsf{S^{n}}\) (see the upper part of Figure 3 for an example). With respect to the anchor shingle, the positive shingle is musically similar, while the negative shingle is musically dissimilar. More precisely, the anchor and positive shingles originate from different versions of the same piece of music and correspond to the same musical position within that piece. Anchor and negative shingles do not correspond to each other. The goal is to find an embedding function \(f:\mathbb{R}^{F\times L}\rightarrow\mathbb{R}^{K}\) such that \(f(\mathsf{S^{a}})\) is numerically close to \(f(\mathsf{S^{P}})\) and far from \(f(\mathsf{S^{n}})\). The lower part of Figure 3 visualizes embeddings with this property. Let  
\[\mathbf{X}=\left(\mathbf{x}^{a},\mathbf{x}^{P},\mathbf{x}^{n}\right)=\left(f\left(\mathsf{S^{ a}}\right),f\left(\mathsf{S^{P}}\right),f\left(\mathsf{S^{n}}\right)\right). \tag{7}\]  
Then, following [PERSON] et al. [33], we define the loss as  
\[\mathcal{L}(\mathbf{X})=\max\left(0,d(\mathbf{x}^{a},\mathbf{x}^{p})-d(\mathbf{x}^{a},\mathbf{x}^{ n})+\alpha\right), \tag{8}\]  
with \(\alpha\in\mathbb{R}_{\geq 0}\) being a margin parameter and \(d\) being a distance function. In our experiments, we use the squared Euclidean distance, as defined in Equation (5). The cost function \(f\) to be optimized during batch gradient descent is the average of losses over a batch \(\mathbb{B}\) of triplets:  
\[J(\mathbb{B})=\frac{1}{|\mathbb{B}|}\sum_{\mathbf{X}\in\mathbb{B}}\mathcal{L}(\bm {X}). \tag{9}\]  
Our neural network architecture is summarized in Table 1. It comprises two blocks, each consisting of two convolutional layers and a max-pooling layer. Finally, a dense layer reduces the network's internal representation to the embedding dimensionality \(K\); an \(\ell^{2}\)-normalization layer ensures that the embedding vectors do not become arbitrarily large or small. This topology is inspired by a network for multi-modal music embeddings [45].