Can we use AI to write a Christmas song?

AI is very good at automating processes and decision making. It’s very, very bad at anything creative. Then we looked at some of the Christmas songs being touted for the top of the charts this year and thought “Hang on, they aren’t very creative either “(*cough cough Ed and Elton*). We want a piece of the Christmas pie but like every other Christmas song, we want to put the bare minimum effort in – so let’s train an AI to pen some Christmas lyrics and do it for us.

The data

The first job is to curate the data that we’ll train the AI on. There were standout options; either use the lyrics from all the Christmas number 1’s over the years to make a song destined for the top spot, or use lyrics from the most Christmassy Christmas songs to make a song that best captures the spirit of Christmas. Ultimately, we went with the second approach. After looking at some of the Christmas number 1’s, it’s plagued by X Factor winners, Rage Against the Machine and some bloke who really likes sausage rolls – so the end result wouldn’t really paint a coherent idea of Christmas. 

Approach sorted, the next job was to decide which songs to populate the data. We wanted to include some American hits too to potentially maximise the viral potential of our masterpiece so we found three playlists. One of the Billboard 100  from Kaggle, and two from Spotify for Christmas Hits and Christmas Songs Holiday Music 2021. Happy we had a good mix of songs, the final job was to scrape the lyrics and make the dataset for which the ‘geniusr’ package proved very useful, allowing us to access the Genius API and resulting in the 318 unique Christmas song lyrics ready to feed through a machine learning algorithm.

The Algorithm

Now we have to turn our attention to the AI itself. There are loads of potential AI algorithms to choose from now, each with their own strengths and weaknesses. Not one implementation fits all solutions, so as an aside, if you ever have conversations with a supplier who claims to have an “AI solution / tool”, always ask which algorithm or implementation they use. It’s a good way to test whether they know what they are talking about or just have some vapourware.  

In our case, there are a few features about our data and objective that stand out when selecting a method. Firstly, it’s completely exploratory with no dependent variable with which to judge accuracy on. It’s not like we are trying to predict a value or automate decision making which we can verify – we’ll have to read what comes out and judge how good it is qualitatively. Secondly, the only independent variable we have is the language of the lyrics itself. The AI doesn’t really “understand” the semantic meaning of words, it’s going to have to rely on probabilities and how often words co-occur to make judgements on structure.

With those constraints in mind, the standout method would be to use a Markov Chain. Without going into too much technical detail about Markov Chains, one of their key features is that instead of simulating from independent samples, they can simulate across an entire process with each probability being dependent on the last step in the chain. Why that’s super useful for us is that it captures some of the features of human language. When we write and compose sentences (or in this case lyrics), each word in your vocabulary doesn’t have an equal probability of being selected and those probabilities change depending on the word that was selected previously. For example, if the first word we chose was “Brussel”, the next word would have a much higher chance of being “Sprout” and Markov Chains let us capture this quite well.

The model

Now that we’ve decided on a Markov Chain, we have to build our model. If we were to just train it over the lyrics, the algorithm would look at how likely each word is to follow every other word in the dataset creating a huge relative probability matrix. This is the core information we need, but we need a way to make that accessible spit out words in a “song like structure”. To do this, we are going to wrap the model in our own function that can help a user impose the creative constraints of songwriting.

The end result is a function whereby we can select a starting word and the model returns the top_n terms that could follow it based on probabilities. The user can then pick from this list to ensure there is a degree of coherence in the lyrics. You’ll notice in our song there are still some quirky lines that stand out as written by a machine (“Momma’s gonna have some pumpkin”) – but overall, the song we ended up with is pretty darn Christmassy.

The song 

All that was left was to put the lyrics through human talent. We called upon our friends at Groove Machine Ltd who produced SHARE Happiness (at Christmas) and by far exceeded our expectations of what our AI generated words could sound like.

So there we have it – we’ve built an AI that can churn out Christmas banger after Christmas banger. In the future, we’re considering making a simple user interface to the word selection function so anybody can use it to write a festive masterpiece of their own. Get in touch if you’d be interested in seeing that (we’d just ask for a cut of the royalties).

For now though, here’s our very own data-driven Christmas belter; SHARE Happiness (at Christmas) – brought to life by Groove Machine Ltd.