How to discover new music on Spotify with Artificial Intelligence

Source: Deep Learning on Medium

Find similar sounding music by artists you may never have heard of before

Go to the profile of Robert Smith

As a DJ, the question I hate most after “Have you got anything by [insert totally inappropriate artist here]?” is “What kind of music do you listen to?”. In my opinion, as soon as you put music in a genre box, it becomes constrained by its limits. But how to share and organise music if not by putting labels on it?

Spotify has the ability to create a playlist (or “radio station”) based on a particular track. It is very good at selecting music by similar artists, but, inevitably, it tends to play music you are probably already familiar with. Maybe this is what you want, but what if you’d like some recommendations of new music that you’ve never heard before? In the good old days before MP3s were invented, I would go to Jam Records in Piccadilly, London. Ollie would just know exactly what sort of thing I was after and I would know instantly whether I liked a tune or not after just listening to it for a few seconds… Let’s just say that a lot of money changed hands.

There’s no doubt that there is a huge amount of music out there that I don’t know, but how can I find it without someone like Ollie to help me? Instead of sticking music in categories, I wanted to come up with a continuous way to organise and explore it. Rather than going by information about the artists or the songs, I was looking for something that related songs by how they sounded. If you are interested in the technical details of how I wrote a program called Deej-A.I. to do this without using any labels or any data that was not publicly available, then have a look at this article.

I ran my program on all the Spotify tracks that (a) appear at least 10 times in a playlist (as of October 2018) and (b) can be downloaded in the form of a 30 second MP3 sample. This gave me two ways of relating Spotify songs: one, by how likely they were to appear close to each other in a playlist and another, by how similar they sounded. The first way tends to group songs by similar artists, while the second puts songs with similar energy, mood, rhythm or instrumentation together. Technically, these are called embeddings in a multi-dimensional space, in which the proximity of one track to another represents how similar they are to each other. Here’s the interesting bit: we can mix these two ways of relating the tracks and therefore control how open we are to discovering similar music that may be by artists we have never heard of before. I’m going to call this mixing parameter creativity, where 0 means by similar artist and 1 means by similar sound.

For example, if we ask Deej-A.I. to generate a playlist based on just how “Despacito” by Luis Fonsi sounds (I should say that this is not the kind of music I listen to :-) ) then we get the following results.

Interestingly, we end up with a bunch of songs which clearly sound very similar (auto tuned vocals, doom-chi-doom rhythm, etc) but are from all over the world and in various different languages. Maybe this is your thing, I’m not one to judge.

With Sia’s “Chandelier” it picks out some strikingly similar sounding songs, including one by Sia herself. Remember that with the creativity set to 100%, it has nothing to go on but how the music sounds.

What about if we give it something a bit more challenging? As it’s name indicates, “Funkier Than a Mosquito’s Tweeter” is not typical of Nina Simone. Here is what Spotify comes up with.

Deej-A.I., on the other hand, because it actually listens to the music, picks up on the funky African rhythms and serves up a much more coherent playlist. In this case, I chose a creativity of 50% in order to obtain similar sounding recommendations by similar artists.

Joining the dots

The obvious way to generate a playlist is to add songs that are nearest to the ones that have just been played. As you can see, this can give rise to an interesting but meandering path through the embedding space. You can never quite be sure where you’ll end up if you keep going long enough.

An alternative approach is what I call “joining the dots” (a term I have borrowed from DJ Gilles Peterson). You select the first and last tracks, as well as any others you want to visit along the way, and a playlist is generated from the tracks which are nearest to evenly spaced points along the lines joining these. In other words, we linearly interpolate between the chosen tracks as closely as possible. This can lead to some interesting results because different directions in the embedding space may somehow encode certain aspects of music, such as energy, presence of vocals and tempo etc. Certainly, if you plan to throw a party, you could use this to start off with something chilled out, before passing through some well-known favourites and ending up with full on house music…

Let’s see what it comes up with if we ask it to make a playlist starting off with the theme music from Game of Thrones and ending up with the theme music from Vikings, by going purely on sound.

What about if we try some different genres? Here’s a playlist I made earlier which goes from Disco House to Techno, with 50% creativity.

If you are feeling inspired (and have a Google account) you can play around with it yourself. Just click on the link below, open in “sandbox mode”, connect to a machine and press the play button.

If you come up with an interesting playlist, please include a link to it in the comments. Happy listening!