{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Finding Similar Songs - Part 1: Distance Based Search\n", "\n", "The first part of this tutorial series demonstrates a distance based similarity search approach, based on extracted content descriptors and distance metrics. \n", "\n", "## Part 1 - Overview\n", "\n", "1. Introductions & Requirements\n", "2. Loading data\n", "3. Preprocess data\n", "4. Define the Similarity Model\n", "5. Optimize the Model\n", "\n", "# Short Introduction to Music Similarity Retrieval\n", "\n", "The objective of Music Similarity estimation or retrieval is to estimate the notion of similarity between two given tracks. A central part of such an approaches is the definition of a measure for similarity which is further affected by the approach taken to extract the relevant information. One approach is to analyze contextual data such as user generated listening behaviour data (e.g. play/skip-counts, user-tags, ratings, etc.). The approach followed by this tutorial is based on the music content itself and largely focuses on the notion of *acoustic similarity*. Music features are extracted from the audio content. The resulting music descriptors are high-dimensional numeric vectors and the accumulation of all feature vectors of a collection forms a vector-space. The general principle of content based similarity estimations is based on the assumption that numerical differences are an expression of perceptual dissimilarity. Different metrics such as the Manhattan (L1) or the Euclidean Distance (L2) or non-metric similarity functions such as the Kullback-Leibler divergence are used to estimate the numerical similarity of the feature vectors." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Requirements\n", "\n", "Please follow the instructions on the tutorial's Github page to install the following dependencies to run this tutorial:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2017-08-24T10:20:32.488000Z", "start_time": "2017-08-24T10:20:32.483000Z" } }, "outputs": [], "source": [ "# visualization\n", "%matplotlib inline\n", "import matplotlib\n", "import matplotlib.pyplot as plt\n", "matplotlib.style.use('ggplot')\n", "\n", "# numeric and scientific processing\n", "import numpy as np\n", "import pandas as pd\n", "\n", "# misc\n", "import os\n", "import progressbar\n", "\n", "from IPython.display import HTML, display\n", "pd.set_option('display.max_colwidth', -1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Loading Data\n", "\n", "Before we can train our models we first have to get some data." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "DATASET_PATH = \"D:/Research/Data/MIR/MagnaTagATune/ISMIR2018\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load Feature Data\n", "\n", "load feature data from numpy pickle" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "with np.load(\"%s/ISMIR2018_tut_Magnagtagatune_rp_features.npz\" % DATASET_PATH) as npz:\n", " features_rp = npz[\"rp\"]\n", " features_ssd = npz[\"ssd\"]\n", " clip_id = npz[\"clip_id\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "prepare feature-metadata for alignment with dataset meta-data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "feature_metadata = pd.DataFrame({\"featurespace_id\": np.arange(features_rp.shape[0]), \n", " \"clip_id\" : clip_id})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load Metadata\n", "\n", "load meta-data from csv-file." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | clip_id | \n", "mp3_path | \n", "track_number | \n", "title | \n", "artist | \n", "album | \n", "url | \n", "segmentStart | \n", "segmentEnd | \n", "original_url | \n", "
---|---|---|---|---|---|---|---|---|---|---|
19200 | \n", "42150 | \n", "D:/Research/Data/MIR/MagnaTagATune/mp3_full/f/professor_armchair-too_much_mustard-10-bethena-117-146.mp3 | \n", "10 | \n", "Bethena | \n", "Professor Armchair | \n", "Too Much Mustard | \n", "http://www.magnatune.com/artists/albums/armchair-octopants/ | \n", "117 | \n", "146 | \n", "http://he3.magnatune.com/all/10-Bethena-Professor%20Armchair.mp3 | \n", "
7745 | \n", "16994 | \n", "D:/Research/Data/MIR/MagnaTagATune/mp3_full/c/liquid_zen-seventythree-04-close-262-291.mp3 | \n", "4 | \n", "Close | \n", "Liquid Zen | \n", "Seventythree | \n", "http://www.magnatune.com/artists/albums/liquid-seventythree/ | \n", "262 | \n", "291 | \n", "http://he3.magnatune.com/all/04-Close%20-%20Liquid%20Zen.mp3 | \n", "
25416 | \n", "57455 | \n", "D:/Research/Data/MIR/MagnaTagATune/mp3_full/6/doc_rossi-demarzi6_sonatas_for_cetra_o_kitara-23-sonata_vi_allegro-59-88.mp3 | \n", "23 | \n", "Sonata VI Allegro | \n", "Doc Rossi | \n", "Demarzi-6 Sonatas for Cetra o Kitara | \n", "http://www.magnatune.com/artists/albums/rossi-demarzi/ | \n", "59 | \n", "88 | \n", "http://he3.magnatune.com/all/23-Sonata%20VI%20Allegro-Doc%20Rossi.mp3 | \n", "
613 | \n", "1473 | \n", "D:/Research/Data/MIR/MagnaTagATune/mp3_full/b/philharmonia_baroque-beethoven_symphonies_no_3_eroica_and_no_8-01-eroica_1st-117-146.mp3 | \n", "1 | \n", "Eroica 1st | \n", "Philharmonia Baroque | \n", "Beethoven Symphonies No 3 Eroica and No 8 | \n", "http://www.magnatune.com/artists/albums/pb-eroica/ | \n", "117 | \n", "146 | \n", "http://he3.magnatune.com/all/01-Eroica%201st-Philharmonia%20Baroque.mp3 | \n", "
15095 | \n", "33011 | \n", "D:/Research/Data/MIR/MagnaTagATune/mp3_full/0/barbara_leoni-human_needs-07-ring_around_the_rosey-88-117.mp3 | \n", "7 | \n", "Ring around the rosey | \n", "Barbara Leoni | \n", "Human Needs | \n", "http://www.magnatune.com/artists/albums/leoni-human/ | \n", "88 | \n", "117 | \n", "http://he3.magnatune.com/all/07-Ring%20around%20the%20rosey-Barbara%20Leoni.mp3 | \n", "