How does Spotify know what songs you’ll like?

A short ponder of Spotify’s recommendation algorithm and personalised content

Eat It
CodeX
3 min readApr 25, 2022

--

Today, on my taxi ride home, I was doing the usual — enjoying the April rain and blasting my favourite music. The not-so-talkative taxi driver and the absence of anything better to do caused me to wonder about how exactly does the music recommendation algorithm work. What parameters does Spotify analyse? Does it have a way of detecting genres? And, most interesting to me, how does it know if two songs are alike?

Photo by Alexander Shatov on Unsplash

In this article I will attempt to answer some of these questions and provide some insight into the magic of Spotify’s algorithm.

So, the bare bones summary is that Spotify uses an algorithm called approximate nearest-neighbour search, to group songs and users together based on shared attributes or qualities. For example, if you and I both enjoy listening to Adele and Eminem, as well as a few other common artists, we would be considered to belong to the same group of users. This means that if I also listen to Lil Peep, but you don’t yet, Spotify would recommend Lil Peep for you in your daily or weekly recommendations.

Another interesting way in which Spotify analyses songs is through the MUSIG system. This is a way to break down songs into their components — the instruments, words of lyrics, mood, you get the point. This method went down especially well in Japan, where there has been a sing-along feature, reducing the volume of the vocals and allowing you to sing along to your favourite tune.

A more technical overview of the MUSIG system: https://research.atspotify.com/making-sense-of-music-by-extracting-and-analyzing-individual-instruments-in-a-song/

Photo by Marcela Laskoski on Unsplash

Now for the fun part. I always love it when, amidst my playlists of 10 songs that I’ve been listening to for months on end, there is a new gem. A completely different genre, something that captures and surprises you. How does Spotify do this?

To explore the changing tastes of its users, Spotify sometimes throws in exploratory content, the type of content that the user is unfamiliar with, and tracks the user’s response.

This research paper sums up the importance of balance between exploration and exploitation algorithms in recommendations systems in general: https://dl.acm.org/doi/10.1145/3240323.3240354

But how does it know if two songs are similar or not?

This all comes down to one important concept — cosine similarity. Essentially a way for a machine to understand how similar 2 things are. We will need a tint of high school maths to get this.

When we have 2 lines (or vectors) that are perpendicular to each other, the angle between them is 90 degrees, the cosine of this value is 0, meaning that our 2 vectors are very different. If the vectors are parallel, the angle between them is 0 and cosine of that angle is 1, so they are as similar as can be.

For everyone familiar with vectors, the cosine similarity formula is identical to the vector dot product formula :)

We can create vectors with various dimensions, for example, hits and ranking, can be a 2-dimension vector that defines a song.

The way that this calculation is then used, is by creating a heat map — songs very similar to your taste, somewhat similar and not similar at all. Spotify would then select specific proportion of each of these song types and pepper your playlists with it for you to enjoy.

Before you go…

I’d love to hear your opinion of the Spotify algorithm — do you know any apps that do recommendations better? Have a good day and stay tuned for more!

--

--

Eat It
CodeX

"Fuelling a better future, one scan at a time."🌱🥑 Play and earn rewards through your planet-friendly choices.