How Spotify Already Knows Your Next Favourite Song

So I was on the train this morning, listening to my “Discover Weekly” playlist on Spotify. I was sitting there being blown away by it’s crazy accuracy, and thinking “damn, how did it know I would like that song?”.

Discover Weekly is a playlist of 30 songs, that you haven’t listened to before. They are unique to you and your taste in music. And Spotify generates a new Discover Weekly each and every Monday.

Spotify on the go. Photo Credit: Jean Via Unsplash


Many of us are aware that companies like Spotify, Facebook and Twitter use our data to “enhance” our experience on their site.  In Spotify’s case, I’m okay with this! But between your data and your new favourite artist, is an algorithm,  a machine learning algorithm.

But I’ve always wondered, exactly how Spotify could suggest songs which had the same FEEL.

How on earth does an algorithm learn THAT!?

I couldn’t help myself – I had to find out.

 

But first, what IS Spotify?

 

Spotify is a music streaming service with over 180 million users. And just like Amazon suggests books, Facebook suggests friends, and Netflix recommends shows, Spotify recommends songs. With 10’s of millions of songs, it is quite the challenge to accurately suggest music to users!

When Spotify realised that it’s users were browsing other’s playlists on search of new music, they thought – “why not automate this?”.

So their idea was – why not put all of these playlists into a machine learning algorithm and predict songs for users.  This resulted in a much-loved feature of Spotify – it’s “Discover Weekly”.

And all of this is thanks to a term that I’m sure many people are familiar with – a machine learning algorithm.

 

 

From playlist to prediction

 

Taking a brief step back, I will start by clearly defining WHAT exactly an algorithm IS.

An algorithm is simply a sequence of steps or calculations, that is performed to answer a specified problem.

(Although the whole point of algorithms is to be precise, it sure is an ambiguous definition!)

Machine learning workflows can be simplified down to this (Image produced by author).

This new buzzword, “machine learning”, is just the use of algorithms to predict or classify something. A machine learning algorithm takes in a bunch of data, performs specific steps, and outputs predictions.

A machine learning algorithm “learns” from the input data using statistics, to build up a knowledge base (or a model), and then applies this model to your data of interest.

What Spotify does, is it takes all of the playlists that user’s have created on Spotify, and uses this as the input data. It also deduces what it calls your “taste profile“, based on your song history (Unfortunately, this is not available to the public!).

Using these two pieces of information, Spotify can predict new songs for you, every week.

How Spotify generates your Discover Weekly playlist (Image produced by author).

 

Your data as input

 


For those of you interested in a more in-depth answer, Spotify uses 4 main approaches to bring you new songs every Monday.

These Include:

  • Natural language processing (NLP) models, which analyse text i.e. giving songs with similar titles!
  • Audio models, which analyse raw audio tracks, allowing Spotify to find songs with that same FEEL.
  • Your taste profile, which is something Spotify builds based on your play logs
  • Collaborative filtering.

The first three kind of make sense, but it is collaborative filtering that is a bit more interesting, which is best explained with an analogy.

Photo credit: Kevin McCutcheon Via Unplash

Say that I am a student, and I like to purchase 2-minute noodles, coffee, and pens.

Then say that you are also a student, perhaps in a different field, but could be considered ‘similar’ to me.

If you normally purchased a lot of pens and coffee, collaborative filtering would suggest 2-minute noodles to you.

You may or may not like noodles – but this is how collaborative filtering works! Where my shopping list, is the accumulation of millions and millions of user playlists.

Machine Learning Magic

Machine learning algorithms have a wide range of applications including genetics, weather prediction, and physics. The main difference being the type of input data!

And specific techniques are used it different applications. For example, a collaborative filtering approach may be more useful for a genetics application than an NLP. Where  NLP is better suited to helping scientists summarise millions of scientific papers. But of course, scientists don’t have much of a use for audio models or your taste profile.

Although at first it seems a bit creepy, I feel that this really does a service to smaller, up-and-coming artists. Machine learning can connect musicians with the soon-to-be-fans, which would have never otherwise come across their music.

 

 

For the interested learner…

  • Some good advice on how to hack your Discover Weekly.
  • This article goes into more detail with the algorithms behind Spotify’s machine learning.
  • If you’re interested, the open-source software Spotify uses is called Kafka.
  • For more information about how much of your personal data Spotify keeps, and how to download it, click here.

8 Responses to “How Spotify Already Knows Your Next Favourite Song”

  1. Hahah thanks Sofie! Glad that my post inspired a dad joke.

    But yeah, their analysis of the raw audio files seems a bit vague. All I could find is this: https://developer.spotify.com/documentation/web-api/reference/tracks/get-audio-analysis/

    So things such as tempo, time/key signature, volume range, pitch, timbre. My understanding is that the audio files are encoded to include the frequency/amplitude information (digital signal processing), and from there they can do cool calculus stuff to classify “feel”.

    I’m not sure this is the exact algorithm Spotify use but this explains it quite well: https://sites.tufts.edu/eeseniordesignhandbook/2015/music-mood-classification/

    Hope that helped!

  2. abjerre says:

    Man, Holly. Your voice really shines through in your post. I love it!
    Also. thansk for explaining this. Like, I had a vague idea how this works, but pff, I know nothing when it comes to algorithms.

    Do you happen to know, how the ‘algorithm’ determines the feel of the song. My guess is ‘listening’ and analyzing chords and paces, but that seems far too limited to me.

    Also, here’s a dad joke for ya.
    “my discover weekly is based on algorhythms”

  3. Indeed, I did a quick google and it seems like part of Youtube’s algorithm uses collaborative filtering!

    And definitely, over time these websites/companies have gained more and more “input” data, which leads to more accurate predictions!

  4. Xiaohan Hu says:

    Great blog! I think youtube also does a great job of recommending videos for me. And I realize that compared to 4 or 5 years ago, the recommendation just got better and better, the algorithms must be evolving too!

  5. Thanks! It’s pretty interesting, hey?

    And yeah, sometimes they are a bit TOO similar. What I find works is deliberately switching between listening to a variety of genres. So like one day I’ll be really into my rap, then the next day go back to metalcore. Then after switching between the two for a few weeks, Spotify starts to suggest some really cool combinations of both genres! Like metal songs but the lyrics are raps? Kinda cool!

  6. Ashley Densham says:

    Great stuff Holy! Been wondering how that worked for a while now, so thanks for the explanation.

    Sometimes I feel like my Discover Weekly is too similar to the music I listen to, and it could do with a dose of something a little out of the ordinary to expand my musical horizons. Maybe if they built in a slight bit of leeway or randomness into the algorithm it would suggest some slightly different styles of music that I might end up liking!

  7. Thank you! I’m glad it helped 🙂

    An algorithm is just a sequence of steps! Each step is relatively simple, it is just the sum of all of the steps that looks overwhelming. Sometimes those steps involve calculations, but as you say, there is often a range of things involved!

  8. Danielle Fong says:

    This was a really cool, in depth but simple look into algorithms and how they affect our lives more than we’d first think!

    The diagrams and schematics you made really helped me visualise the various connections.

    When I hear algorithms, all I think is ‘maths’. But you’ve helped de-mystify them and shown me a lot more is involved.