Teaching an AI to Write Pop MusicBecause who has time to write it themselves anymore?Aaron FrederickBlockedUnblockFollowFollowingFeb 13I was never any good at writing lyrics.
In my high-school ska band, I wrote the horn parts and some other instrumentals and in my college a capella group, I was always just arranging covers of songs that that had already been written.
There was rarely ever a struggle that I felt that I could justify writing a song about, but they always were cheesy and lame when I did.
After years of giving up, I have finally discovered the tools I needed to solve this problem of writing lyrics while detaching myself from the sensation of lameness or cheesiness I felt in the past.
Using recurrent neural networks and a dataset near and dear to my heart, I will finally solve the problem I’ve had for decades — writing song lyrics.
The CD that started it allWhen I was 7 years old, I got a CD from Burger King as part of a kids meal: a 7 song Backstreet Boys CD called “For the Fans”.
That album sparked my love for the band that would soon release their smash hit “I Want It That Way”.
That song makes almost no sense.
“I Want It That Way” was written by the Swedish music-writing superstar Max Martin before his English was fluent, which is why the song is so inconsistent in what it means at any given point.
Because of its commercial success and how little it makes sense, “I Want It That Way” makes a great benchmark for coherency in an AI-generated song.
Using generative neural network models, I can take works of others as inspiration and get through the writers’ block associated with writing a song and go straight to the editing phase.
Because of my deep (and genuine) love for boy bands, I will be documenting my foray into AI-generated art using a Recurrent Neural Network (RNN) to write boy band lyrics.
All of the code used for this project is on my GitHub, special thanks to Danny Mendoza for helping with the implementation.
The complete works of the bands below were used to train my model:Backstreet BoysN’syncBoyz II MenOne DirectionWhy Don't WeNew Kids on the BlockJonas BrothersThe WantedLSTM and GRU nodes are great for recognizing sequences in data SourceGenerative models are by no means new, but aren’t typically well regarded when compared to art by humans- the obvious exception being the AI-generated work of art that sold for over $400,000.
There are different techniques used to generate different types of art — Generative Adversarial Networks (GAN) to generate pictures and RNNs generate both music and words due to their ability to recognize and create coherent sequences.
For this project, I used Gated Recurrent Unit (GRU) layers in my neural network, but colleagues in the field have also experienced success using Long Short-Term Memory (LSTM) networks.
To gather data, I used a combination of web scraping and python package calls.
Initially, I had planned on scraping all of the lyrics to the songs I wanted, but was foiled by crafty web developers preventing me from grabbing 700 songs from their sites.
With only a list of artist and song names that I had been able to grab, I used the PyLyrics package to make a list of song lyrics stripped of any formatting or punctuation.
I will be taking series of words from my output to make a song, not using any formatting from the song itself.
Once I had all of the lyrics from the songs, I added all of the words in order to a list as tokens to generate sequences of words 7 words long.
After removing the duplicate sequences, I trained my RNN model to predict the last word of each sequence given the first 6.
The function below shows how the model takes a seed word and generates lyrics of a length we can choose.
Using my RNN and this gen_sequence function, I have compiled the outputs of the model to write a boy band song below.
The raw outputs of the model are on the left along with how long the model was trained on the right.