Writing Songs with GPT-4: Part 3, Melodies

Author:Murphy  |  View: 29771  |  Time: 2025-03-23 18:22:57
"a woman standing, wearing headphones, looking at a computer screen, while singing into a professional microphone," Image created using an AI image creation program, Midjourney, and edited by the author

This is the third and final article in my series on using GPT-4 [1] to compose music. My first article covered writing lyrics for songs, and my second article delved into composing chords to go along with lyrics. In this article, after a brief introduction to GPT-4, I'll show you how to coax the model to create melodies for songs with chords and lyrics. I'll wrap up with a general discussion and offer some next steps for composing music with AI.

Intro to GPT-4

GPT-4 is the latest large language model from OpenAI. It's available in the paid version of their ChatGPT service, which costs US$20 per month. The model is an improvement on their previous iteration, GPT-3.5. Here's an excerpt of what OpenAI says about the new model on their GPT4 landing site.

GPT-4 is more creative and collaborative than ever before. It can generate, edit, and iterate with users on creative and technical writing tasks, such as composing songs, writing screenplays, or learning a user's writing style. … We spent 6 months making GPT-4 safer and more aligned. GPT-4 is 82% less likely to respond to requests for disallowed content and 40% more likely to produce factual responses than GPT-3.5 on our internal evaluations – OpenAI

OK, they listed "composing songs" as one of their examples of creative tasks. They also mentioned the model being more "aligned," which is OpenAI's buzzword for making AI models follow human values and intent. You can read more about this in their technical report.

As I mentioned in my earlier articles on GPT-4, OpenAI collects users' prompts and responses by default and may use them to improve future models. However, you can opt out of this data collection by submitting this form, here.

Creating Melodies with GPT-4

Currently, large language models only deal with text in and text out. However, OpenAI is working on extending GPT-4 to use images in prompts. This model is not available to the public yet, but it is available in a beta version of an app called Be My Eyes. The app helps people who are blind or have low vision with daily tasks by analyzing pictures and reading a text description of the scene.

For this article, I explored various ways to get the model to compose melodies using text formats. I found the best format for this is using guitar tablature (or tab) notation.

Guitar Tabs

Musicians use guitar tabs to transcribe notes and chords for stringed instruments as plain text. Instead of the usual musical notes on a staff, guitar tabs show which frets are used over time for the strings on an instrument. For example, here's the first line of "Happy Birthday to You" as a six-stringed guitar tab.

Guitar Tab of the Melody for "Happy Birthday" Image by Author

Time is on the horizontal axis; the strings are on the vertical axis from the lowest at the bottom to the highest at the top. The numbers represent which fret to play at points in time. A bigger number corresponds to a higher note. After experimenting with this, I found that there were enough guitar tabs with the corresponding commentary found in the web-based training data to allow language models to compose in this format.

Interacting with GPT-4

Using the example song from my first two articles, I asked GPT-4 to compose a Melody one part at a time. Here's how the first interaction went.

RobG: Write a melody for the song Dogs and Cats in guitar tab format. Play one note for each syllable.

[G] Dogs and cats, they [C] roam the streets [Em] Furry friends with [D] hearts that beat [G] Claws and paws, they [C] rule the land [Em] Tails a-waggin', [D] they understand

GPT-4: I'm an AI text-based model, so I can't create or play a sound. But I can give you an example of how you might put these chords to a simple melody using guitar tab format, each note for each syllable.

The basic chords provided are G, C, Em, and D. I'll use the G major scale as the melody foundation.

Remember, in tab format, the lines represent the strings of a guitar (from low E on bottom to high E on top), and the numbers represent which fret to play on that string. Here's a simple example:

e|----------------0------------------|-----------------3------------------|
B|---------1---3-----3-1---------1--|-------0---1-3-------3-1------------|
G|-------0---0-----------2-0--------|-----0---0---------------2-0--------|
D|-----2----------------------2------|---2-------------------------------|
A|----------------------------------|-----------------------------------|
E|----------------------------------|-----------------------------------|
     G          C                   Em             D

e|----------------0------------------|-----------------3------------------|
B|---------1---3-----3-1---------1--|-------0---1-3-------3-1------------|
G|-------0---0-----------2-0--------|-----0---0---------------2-0--------|
D|-----2----------------------2------|---2-------------------------------|
A|----------------------------------|-----------------------------------|
E|----------------------------------|-----------------------------------|
     G          C                   Em             D

This is just a very simple example and the melody might not fully capture the spirit of your lyrics, but I hope it helps as a starting point. You may want to adjust the rhythm and melody to suit your song better.

This is interesting. It's a two-part musical phrase that is repeated twice. But on closer inspection, you can see that there are too many syllables in the phrases; it has twelve+eleven when it should be seven+seven. Also, the vertical lines don't line up. I repeated the process for the second verse and cleaned up the phrases a bit in a text editor to look like this.

e|-------------0-----|-------------------|
B|-------1---3---3---|-------0---1-3-----|
G|-----0---0---------|-----0---0-----0---|
D|---2---------------|---2---------------|
A|-------------------|-------------------|
E|-------------------|-------------------|
     G       C             Em      D

e|-------------------|-------------------|
B|-------0-3-1-0-----|-------0---3-1-----|
G|-----1---------2---|-----0---0-----2---|
D|---2---------------|---2---------------|
A|-------------------|-------------------|
E|-------------------|-------------------|
     Am      C           G       D

I wrote some Python code here to convert guitar tabs to MIDI files, so I could play them back to hear how they sounded. The code is based on a similar project by Brian Caffey [2]. Here's the complete score.

The Score for Dogs and Cats, Image by Author

And here's what the song sounds like. I used Band-in-a-Box by PG Music to arrange the song with piano, guitar, bass, and drums. Feel free to sing along.

Tags: Artificial Intelligence ChatGPT Machine Learning Melody Music Composition

Comment