Song of the machines (3) : Generating lyrics with musical context.

By Sander Van Grunderbeeck

In this episode of “Can 4 Dataroots colleagues without music production experience write hit songs with AI?” you discover how the Beatroots team finetuned a transformer model to generate musical lyrics for their hit song.


Lyric generation powered by Beatroots AI


No hit song without meaningful lyrics to go with it, right? This statement motivated the Beatroots team to explore the use of AI for lyric generation.  Since our vision this year was to use AI tools as ‘creative-partners’ during an artist’s songwriting process, we decided to develop a model which would generate meaningful lyrics depending on a given user input. The generated lyrics could then be used as a starting point or source of inspiration to obtain the perfect story for the song you, the artist, wants to write.

We, at Dataroots, like to dream big. Hence, the team decided to not stop there. We identified the opportunity to train the model to also provide a meaningful set of musical chords depending on the given input. This again emphasizes the goal of building AI tools able to help music artists in writing their songs. The generated chords could inspire the artist by giving hints on possible chords for the given input.

We identified that a transformer model for text generation (e.g. GPT-2) could be used for the task at hand. The next section will elaborate on how we finetuned GPT-2 in order to create our own lyric- and chord generating AI model: GPT-Sandy.

GPT-Sandy: The making (and use) of

GPT-Sandy is a fine-tuned GPT-2 model, able to generate lyrics and chords for any combination of artist, song name, music genre and decade.

GPT-2 (Generative Pre-trained Transformer 2) is a famous transformer model created by OpenAI for natural language processing (NLP) purposes. GPT-2 is pre-trained on an enormous amount of language data, developing an understanding of the English language.  

We leveraged the power of this model and finetuned it to perform a specific text generation task. The specific task being the generation of lyrics and chords depending on a certain metadata input (artist, song name, genre and decade). The model learns to complete the metadata information it receives with meaningful lyrics and corresponding chords.

If you want to learn more about transformers and NLP, our very own Murilo Cunha has written an excellent blogpost about this. A more practical guide and demos on how to use transformers for NLP tasks can be found on Huggingface.

Before deep diving a bit more in how GPT-Sandy was created and showing the results, a visual illustration is given on the process of developing this AI tool.

Dataset

Since we wanted to successfully finetune a model to generate lyrics accompanied by chords depending on artist, song name, music genre and decade we needed a sufficiently large dataset of songs containing all this information. This will ideally enable the model to learn representations of the different genres, artists,... present in the dataset.

The Lakh midi dataset, discussed in the previous blogpost by Zoë, served as a starting point as it contained a large number of unique midi files aligned with the Million Song Dataset. Some further preprocessing of this musical data allowed us to generate a final dataset containing thousands of entries with the necessary metadata and lyric information in the desired format.

Training & Results

Huggingface, the most popular package to work with transformers,  was used together with Amazon Sagemaker for training. A pre-trained GPT-2 model was obtained from Huggingface and finetuned using our dataset: GPT-Sandy was born.

The only thing that remained was to use GPT-Sandy in order to sample lyrics for the song we created. Since we humanoids deemed ourselves not able to come up with an award winning song title, we asked GPT-3 the following question: ‘Generate multiple creative titles for a song which would win the AI song contest’. Out of the different options given by GPT-3 we chose the song title we liked the most. Another collaboration between an AI-tool and a humanoid resulted in the following song title: Song of the Machines.

GPT-Sandy was tasked with generating multiple sequences of meaningful lyrics for this specific song title. The best samples were picked and finetuned by us, songwriters. We corrected the lyrics grammatically and made sure they went well together with the generated melody. Since the generated dataset was still rather small, some tweaking of the generated lyrics was necessary.

The final lyrics used for the song can be seen below. Our team was surprised to see how many elements in the generated lyrics could be related to the title of the song. We enriched the lyrics below with our team’s interpretation of the text. Ever heard a machine whine about it’s existence? No? Discover below.

Song of the machines

Conclusion

This blogpost, together with the previous ones in this series, illustrate the endless possibilities of using AI in creative processes such as writing a song. This blogpost illustrated how an AI tool can be developed and used to generate song lyrics depending on a specific metadata input. GPT-Sandy’s generated samples were cherry picked and minimally adjusted to create a set of meaningful lyrics for the song. Next to lyrics, the model also provided hints on musical chords that can be used together with the generated text. The generated chords were not used in the final submission as other AI tools were used for generating the melodies of the song.

Curious on how all generated samples were combined and rearranged to generate the final song? Stay tuned for the final blog post in this series on how a Digital Audio Workstation (DAW) was used to produce the final song.

You will also like

Songs of the machines (2) - Harmonisation - Zoë Van Noppen
This blog post is part of a series of content in which we uncover how we wrotethe song “Song of the Machines” with which we participated in the AI SongContest 2022. AI songcontestAs shared in the previous blog post, our vision for this year’s song contest wasto use AI tools as “creative partne…
Song of the Machines (1): Sampling musical sections - Dorian Van den Heede
Can 4 Dataroots colleagues without professional music production experiencewrite hit songs with AI? In this blogpost series the Beatroots team membersuncover how they wrote their latest song, Song of the Machines, which theysubmitted for the 2022 AI Song Contest. AI Song ContestThe AI Song Cont…