Song of the machines (3) : Generating lyrics with musical context.
Published: 2022-12-12 03:00:45

---
title: Song of the machines (3) : Generating lyrics with musical context.
published: true
date: 2022-12-11 21:10:00 UTC
tags: 
canonical_url: https://dataroots.io/research/contributions/song-of-the-machines-3-generating-lyrics-with-musical-context
---

 **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](https://openai.com/) 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](https://dataroots.io/research/contributions/a-light-introduction-to-transformers-for-nlp) about this. A more practical guide and demos on how to use transformers for NLP tasks can be found on [Huggingface](https://huggingface.co/).

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.

![](https://lh6.googleusercontent.com/eaFdJYk1P0OCLy960xGPYZ0ZQpSC8p3OzzJzXde7IIIeQlzBJSaJ6Z5Ed4OvIw06oikRXP6a4cfZK0AgRQ2Xl01oF3OnnfzR8i_j4-3yln0p48_Qmv-xqabK5QdIkOnDpPeDyv94DfZbbgvrkuMxkdlUYDxMO_Q-ePuYrOcS7FDHkx8NIIJ1yvrTHTs9CA)

#### 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](https://colinraffel.com/projects/lmd/), discussed in the previous [blogpost](https://dataroots.io/research/contributions/ai-songcontest-2022-coconet)by Zoë, served as a starting point as it contained a large number of unique midi files aligned with the[Million Song Dataset](http://millionsongdataset.com/). 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** _

![](https://dataroots.ghost.io/content/images/2022/11/image-2.png)

#### 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…

 ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsSAAALEgHS3X78AAAAB3RJTUUH5QMTDQUuJijI6QAAAAFvck5UAc+id5oAAANWSURBVFjD7dZZiJVlGAfw33GGaWJomMzItEXbbHGGZoyiRW0RLxLypgutbiuIFiJbQCKKiGihneqiBW+CoGIIuqgkEJexxZRogbLQjJrKaLFi1Jm6eN7Pec93vnOcAaOb+cOB873b83+2//syhf8ZtUNyyuCDreeX3/UfEqg3PhPz8AWGJ0KmOYGyV1Ve1K+Zg2dwCbZjPdbiA+zCaBWZagITCWn9mjPwLBaXVu7HTryPd7ERX2OkOYHxg9txBcaSF9+n/2UM4Hmc05q1f0RaPsLd+LgwUuV1B25NCzsS66HkxRB2YB8WJs/PKnm9Bz0lAjVRI8uwqSBQqzB+OFbj9mQ8xxi+SxH5FCtxSjY/gocxiPNxGRZgFqZl617DCuyvlYx3437cgDaTw5+4F4+n6BSRPBFLcB9mpPHPcCmGc1Yz8ARuLBnfKfLfCr9gFR7NjMNefIkXsC0bPw5zGa+BWcn4laWD38MtIq8XpZCei+Pl9cOTeO7AV96yEeG92Jr2F5Huw1B7YvI0Li8ZfxM3iYKDz/EiZqfxVdnawyqN12OLqKEi6gPSx9kZM2nRK7guM15gNKXkDVHpBRag8yBp+iSlqkAvetqTZ8M4IU3sEu33Q4uQfiO6YV4aPQ3HNBCuL/A2hQAFTsKcdnyLrzIC3ThKyGmzkP4s9L4gMBMnY0cTFe0VaZ6djfVg7jTRPttKE32VQRw/fB8+zGY6cS0WYXpp13lYgwuzsTFRT+uKgtgipLLAQIPRRqU8umRoBd7CO0ILlgkpf1nUWU7+EdyB3YUQ9QuZLdhvxNIUnTK6cI9ozw7NMSLatysb+xsPCLUcgTYrlxB9uhzHZmmYnkK1JyPSg4dEG+Y6MKpeaqX5nOAfQuIfk4lVccivQtv70/cRycPrRYFuwLoU1qtKhtaLd8B88RY4U+NFtDuF/CVFqlNxFwTGxDV5TWljZzp4viiyspdvi3tje/ruFm+DRULrB1J0b8OrB3ZlnZWHcVC0yWKcnqKQo2z8ddws9KDA79icfk/hVNH/W6uMU30dH5k8vjj9+ozfYgXWCCn+qeHgVq+pCk2pHWRTV/JioZDrfnFHrMZvrQ6eKBqfZHdezQW9VWs7xK35I/46FMarCZQxyZBOYQqTxb9fddW1INHowAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wMy0xOVQxMzowNTo0NiswMDowMMNJPDoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDMtMTlUMTM6MDU6NDYrMDA6MDCyFISGAAAAAElFTkSuQmCC)datarootsdataroots

 ![](https://dataroots.io/static/32a92e04fa8f7dd798e53f660ba7e94f/f3583/Screenshot-2022-09-26-at-14.52.57.png)
](https://dataroots.io/research/contributions/ai-songcontest-2022-coconet)

[

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…

 ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsSAAALEgHS3X78AAAAB3RJTUUH5QMTDQUuJijI6QAAAAFvck5UAc+id5oAAANWSURBVFjD7dZZiJVlGAfw33GGaWJomMzItEXbbHGGZoyiRW0RLxLypgutbiuIFiJbQCKKiGihneqiBW+CoGIIuqgkEJexxZRogbLQjJrKaLFi1Jm6eN7Pec93vnOcAaOb+cOB873b83+2//syhf8ZtUNyyuCDreeX3/UfEqg3PhPz8AWGJ0KmOYGyV1Ve1K+Zg2dwCbZjPdbiA+zCaBWZagITCWn9mjPwLBaXVu7HTryPd7ERX2OkOYHxg9txBcaSF9+n/2UM4Hmc05q1f0RaPsLd+LgwUuV1B25NCzsS66HkxRB2YB8WJs/PKnm9Bz0lAjVRI8uwqSBQqzB+OFbj9mQ8xxi+SxH5FCtxSjY/gocxiPNxGRZgFqZl617DCuyvlYx3437cgDaTw5+4F4+n6BSRPBFLcB9mpPHPcCmGc1Yz8ARuLBnfKfLfCr9gFR7NjMNefIkXsC0bPw5zGa+BWcn4laWD38MtIq8XpZCei+Pl9cOTeO7AV96yEeG92Jr2F5Huw1B7YvI0Li8ZfxM3iYKDz/EiZqfxVdnawyqN12OLqKEi6gPSx9kZM2nRK7guM15gNKXkDVHpBRag8yBp+iSlqkAvetqTZ8M4IU3sEu33Q4uQfiO6YV4aPQ3HNBCuL/A2hQAFTsKcdnyLrzIC3ThKyGmzkP4s9L4gMBMnY0cTFe0VaZ6djfVg7jTRPttKE32VQRw/fB8+zGY6cS0WYXpp13lYgwuzsTFRT+uKgtgipLLAQIPRRqU8umRoBd7CO0ILlgkpf1nUWU7+EdyB3YUQ9QuZLdhvxNIUnTK6cI9ozw7NMSLatysb+xsPCLUcgTYrlxB9uhzHZmmYnkK1JyPSg4dEG+Y6MKpeaqX5nOAfQuIfk4lVccivQtv70/cRycPrRYFuwLoU1qtKhtaLd8B88RY4U+NFtDuF/CVFqlNxFwTGxDV5TWljZzp4viiyspdvi3tje/ruFm+DRULrB1J0b8OrB3ZlnZWHcVC0yWKcnqKQo2z8ddws9KDA79icfk/hVNH/W6uMU30dH5k8vjj9+ozfYgXWCCn+qeHgVq+pCk2pHWRTV/JioZDrfnFHrMZvrQ6eKBqfZHdezQW9VWs7xK35I/46FMarCZQxyZBOYQqTxb9fddW1INHowAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wMy0xOVQxMzowNTo0NiswMDowMMNJPDoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDMtMTlUMTM6MDU6NDYrMDA6MDCyFISGAAAAAElFTkSuQmCC)dataroots

 ![](https://dataroots.io/static/322d4cbb88c65a41e517992a884f863c/f3583/Screenshot-2022-06-30-at-08.55.48.png)
](https://dataroots.io/research/contributions/song-of-the-machine-1)