The Magic Spotify Code (Hint: It’s AI!)

By Vaughn Luthringer

Image Credit: Billy Steele - Engadget

“Artificial intelligence” is a term hard to avoid in 2020. After all, AI is everywhere! And, if you’ve ever had a conversation about AI, or even read about it in an article, the words “machine learning” were more than likely mentioned.

But, what is this “machine learning” thing really all about? Let’s break it down a little.

In the words of the MIT Technology Review: “Machine-learning algorithms use statistics to find patterns in massive amounts of data.” To put it into context, machine-learning algorithms collect data from your activity on-screen, and look for patterns within it. Algorithms then use this data to predict what you’ll do next, and cater to this prediction accordingly.

Machine-learning algorithms are put to use in countless applications and websites. Social media, search engines, and voice assistants are all powered by machine learning, alongside many other apps and sites.

Let’s dive into one app, in particular: Spotify. The endless curated playlists and customized content on Spotify are a product of machine learning. 

Discover Weekly is one of Spotify’s characteristic features. It’s a weekly playlist that delivers users brand-new songs that they’ve never listened to before, tailored to their individual music taste. As it turns out, Discover Weekly is a product of three distinct models.

Collaborative Filtering models analyze behavior (yours and others’), Natural Language Processing models analyze text, and Raw Audio models analyze music.

Spotify feeds song data into Collaborative Filtering models to make recommendations for users. This data comes in the form of the number of streams for a specific song, and actions taken on the song by other users--saving the song, visiting an artist’s page, etc.

Collaborative Filtering works by looking at users’ preference for songs and finding similarities among users. Spotify can then recommend new songs to users based on the users’ similar-taste counterparts’ preferences. To better understand how Collaborative Filtering models work, check out the article, “Spotify’s Discover Weekly: How machine learning finds your new music” in the “Sources” list below!

Next up: Natural Language Processing, or “NLP” for short. NLP analyzes words and speech. Spotify’s NLP models search for descriptions of songs, artists, etc., and look for other songs and artists that are mentioned with them. These words, phrases, titles, and names become “top terms” or “cultural vectors,” and are used to calculate how similar two songs are.

Lastly, Raw Audio models! Raw Audio models analyze songs’ content directly, meaning that it doesn’t matter who listens to the song or what’s written or said about it. All that matters is what’s actually in the song. Here, neural networks come into play, and analyze the characteristics of the song. This is a lot to dive into here, but with a little research, you can learn all about neural networks.

Well, there it is! The magic Spotify code that creates Discover Weekly. It gets much deeper and more complex than what is covered in this article, and there’s plenty more to learn about in terms of machine learning in music. Check out the articles in the “Sources” list or search the web to keep exploring AI in music. You can also check out Spotify’s developer page to learn more about what powers the app!

Learn more

Spotify for Developers (


“What is machine learning?” (

“Spotify’s Discover Weekly: How machine learning finds your new music” (