Writing Songs with GPT-4: Part 2, Chords

Author:Murphy  |  View: 25103  |  Time: 2025-03-23 18:40:15
"a musician playing acoustic guitar in a professional studio wearing headphones with a computer screen," Image created using an AI image creation program, Midjourney, and edited by the author

This is the second article in a series of three about using the new GPT-4 language model from OpenAI [1] to compose Music. In the first article, I explored using the model to write lyrics for songs in various styles. For this one, I used the system to compose chords for the songs. I will look into composing melodies in the third installment.

Background on GPT-4

GPT-4 is the latest large language model from OpenAI. It is available using their ChatGPT user interface and accessed via their API. The new model is available as part of a paid ChatGPT Plus subscription, which costs US$20 per month. As I noted in my last article, OpenAI will capture your inputs and responses which that might use to train future versions of their models. This is enabled by default, but you can opt out of data collection using their form here.

The responses from GPT-4 are notably better than the previous GPT-3.5 model. According to OpenAI's technical report, the new model scored 1,400 out of 1,600 on the SAT exams (710 for language, 690 for math), whereas the earlier model scored 1,260 (670, 590.)

Despite the excellent test scores, OpenAI reports that the output from the system is not always reliable and is not free from showing biases learned from the training data.

Despite its capabilities, GPT-4 has similar limitations to earlier GPT models: it is not fully reliable (e.g. can suffer from "hallucinations"), has a limited context window, and does not learn. Care should be taken when using the outputs of GPT-4, particularly in contexts where reliability is important. … GPT-4 can generate potentially harmful content. … It can represent various societal biases and worldviews that may not be representative of the user's intent, or of widely shared values. – OpenAI [1]

This sounds scary and ominous. But for what I am doing in this project, generating chords for songs, the stakes are a lot lower.

Using GPT-4 to Create Chords for Songs

In my previous article, I asked GPT-4 to create lyrics for a rock song about cats and dogs. Here's my first attempt to get the model to create chords for this song.

RobG: Write chords for the first verse of this rock song.

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

Side by side, they chase the wind Bound together, best of friends They're rockin' in the moonlit night Dogs and cats, they're out of sight

_GPT-4:_Here are the chords for the first verse of the song:

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

Am C Side by side, they chase the wind G D Bound together, best of friends G C They're rockin' in the moonlit night Em D Dogs and cats, they're out of sight

The chords seem pretty good, albeit a tad basic. Like most Large Language Models, GPT-4 was trained on lots of text from books and the Internet and it seems to have picked up on enough discussions about chords to generate decent sequences. I like the AABA structure of the progression: G – C – Em – D, G – C – Em – D, AmCGD, G – C – Em – D.

However, there is an issue with text formatting. The chords don't line up with the phrasing of the lyrics, i.e., the "D" chord should probably line up with "they're" or "out" on the last line. I found an alternative approach that works fine: put the chords in line with the lyrics. I just had to ask.

RobG: Show the chords in line with the lyrics in square brackets separated by spaces.

GPT-4: [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

[Am] Side by side, they [C] chase the wind [G] Bound together, [D] best of friends [G] They're rockin' in the [C] moonlit night [Em] Dogs and cats, they're [D] out of sight

Ah, much better. Having the D chord start before "out" for the last line makes sense because "they're" is used as a pick-up note before the next chord starts.

In addition to generating chord progression, GPT-4 also explains things related to music theory. So I occasionally asked it questions about the songs I was working on, like this.

RobG: What key is this in?

GPT-4: The chords provided for the rock song are in the key of G major. The G major key consists of the following chords: G (I), Am (ii), Bm (iii), C (IV), D (V), Em (vi), and F#dim (vii°).

That seems correct. And I appreciated the full explanation of the chords used in the key of G major. Notice how it used both the letter names of the chords and the Roman numeral notation, where major chords are capitalized, i.e., (I), and minor chords are in lowercase, i.e., (ii.) I liked the way it used the ‘°' character for the diminished chord.

I used a commercial app called Band-in-a-Box (BiaB) from PG Music to hear what the chords sounded like. I typed in the chord names, pasted in the corresponding lyrics, chose a "rock" style, and it rendered the song. Here it is. Note that there is no melody, so feel free to sing along with your tune.

That sounded pretty good. The chord sequence was fine, and BiaB did an excellent job with the guitar, bass, and drum parts. Without the vocal melody, the best parts of the tune were the guitar fills at the end of each phrase.

Up next, I'll show how I used AI to extract both the lyrics and chords from recordings of songs.

Using AI to Extract Lyrics and Chords from Songs

In the previous article, I showed how I used the Whisper model from OpenAI [2] to transcribe the lyrics from audio files. For this project, I wrote some code to use another neural network called Autochord to extract the chords and stitch them together.

The Autochord model was created and trained by C. J. Bayron, a software engineer and ML enthusiast. It works well. You feed it an audio file, and seconds later, you get a list of start times, end times, and chords. Here's an example visualization of the results from the model from his online app. You can generate a label file by following the instructions here.

Autochord Visualization, Image by Author

It only finds major and minor chords, but this was fine for my purposes. I then took the output from Whisper with the word timings and wrote some Python code to integrate the chords with the lyrics. For example, here is a rendering of a very famous song.

And here is the transcription of lyrics and chords using Whisper and Autochord, respectively.

[C] Happy Birthday to [G] you, Happy Birthday to [C] you, [C] Happy Birthday [F] dear reader, Happy [C] Birthday [G] to [C] you!

This seems pretty good. All the chords were predicted correctly. It even picked up the quick turnaround for the last three words. The change to the F major chord should have come after the word "dear," but that's the only mistake.

Notice how the phrases are not split up correctly, however. This was based on the phrase segmentation calculated by the Whisper model. To straighten it out, I fed the transcription into GPT-4 with the following prompt.

RobG: Here are the chords and lyrics to a song.

[C] Happy Birthday to [G] you, Happy Birthday to [C] you, [C] Happy Birthday [F] dear reader, Happy [C] Birthday [G] to [C] you!

Break the song up into shorter lines at the commas, and show the current chord at the head of the line.

GPT-4: [C] Happy Birthday to [G] you [G] Happy Birthday to [C] you [C] Happy Birthday [F] dear reader [F] Happy [C] Birthday [G] to [C] you!

OK, that is easier to read. And the system will be able to analyze and generate lyrics with chords in this format, as you will see in the next section.

Composing Chords for New Songs

After I got the code in place to extract lyrics and chords from a song, my next step was to ask GPT-4 to analyze the chords from an existing tune. I did this with the song "Grow," written and performed by The Agents, a ska band from Providence, RI. They agreed to let me use AI to analyze their song and use the analysis to create a new song in a similar style.

The Agents, Photo Used with Permission

I ran my Python code to get the lyrics and chords from the recording, and I used GPT-4 to format the text using the technique I described above. Here's the prompt I used to get an analysis of the chords. I am only showing an excerpt here, but I passed the complete lyrics into GPT-4.

RobG: Analyze the chords to this song, "Grow" by The Agents.

[Verse 1] [Em] Yeah! On that day, the very first day I [C] met [C] You girl, the very first time I [G] held [G] Your hand, the very first time I [B] looked into [B] Your eyes, I told you that I loved you [Em] From that day till ever after [C] The troubling times, the sorrow, [C] The [G] laughter [G] Hand in hand now we walk together [B] Can't imagine anything better now

[Chorus] [Em] Grow, let your love [G] Grow, [C] grow [C] Let your love come [G] Rise up, rise up [G] Plant the seed and let [B] your [B] Love grow, higher and higher. . .

_GPT-4:_In the song "Grow" by The Agents, there are several distinct chord progressions found in different sections of the song. These progressions give the song its structure and emotional content. Here's an analysis of the chord progressions in each section:

Verse: The verse has a chord progression of Em – C – G – B. This progression features a mix of major and minor chords, creating a balance of tension and release. The Em (minor) to C (major) transition provides a sense of longing, while the move from G (major) to B (major) adds an uplifting quality.

Chorus: The chorus chord progression is Em – G – C – G – B. This progression starts with the same Em – G – C as the verse but replaces the final B chord with a G, and then goes to B. This slight variation maintains the uplifting quality of the verse but adds an extra layer of tension and release with the added G chord before moving to B.

Bridge: The bridge has a different progression: Bm – G – B – Em – C – G. It starts with a Bm (minor) chord, which adds a darker, more introspective quality. The progression then moves through G (major), B (major), and Em (minor) chords, creating a sense of build-up and anticipation before returning to the familiar C – G chords from the verse and chorus.

Interlude: The interlude features a more straightforward chord progression of C – B – Eb – C – Em – G. This progression provides a break from the primary progressions used in the verse and chorus, adding variety and keeping the listener engaged.

In summary, "Grow" by The Agents uses a combination of major and minor chords to create a balance of tension and release throughout the song. The verse and chorus share similar chord progressions, while the bridge and interlude provide contrast and variety to maintain listener interest.

Wow, that was a comprehensive analysis of the chord progressions. It appears that GPT-4 knows music theory well and it provided a summary of how listeners may react to the different parts of the song.

In the same chat session, I asked the model to create chords for a song using a similar style. I used GPT-4 to create these lyrics in part one of this series.

RobG: Create chords for this song using a similar style. Title: "Dance with the Fear"

[Verse 1] Waking up to a brand new day, Feeling the fear but not turning away, Facing the unknown, that's where we'll start, With an open mind and a fearless heart.

[Pre-Chorus] No more hiding, no more doubts, It's time to let our courage out.

[Chorus] Dance with the fear, don't run away, Embrace the challenge, come what may. Find your rhythm, face the unknown, With every step, your strength has grown.

[Verse 2] In the darkness, we'll find the light, Guided by dreams that take flight. No more trembling, no more fright, Together we'll soar to new heights.

[Pre-Chorus] … [Chorus] …

[Bridge] When fear is knocking at your door, Stand tall, and face it once more. The journey's long, but you'll find, You're stronger than you realized.

[Chorus] …

[Outro] Dance with the fear Dance with the fear Dance with the fear Dance with the fear

GPT-4: Title: "Dance with the Fear"

[Verse] [Em] Waking up to a [G] brand new day, [D] Feeling the fear but [A] not turning away, [Em] Facing the unknown, [G] that's where we'll start, [D] With an open mind and [A] a fearless heart.

[Pre-Chorus] [Am] No more hiding, [C] no more doubts, [G] It's time to let our [D] courage out.

[Chorus] [Bm] Dance with the fear, [C] don't run away, [G] Embrace the challenge, [D] come what may. [Bm] Find your rhythm, [C] face the unknown, [G] With every step, your [D] strength has grown.

[Verse 2] [Em] In the darkness, [G] we'll find the light, [D] Guided by dreams that [A] take flight. [Em] No more trembling, [G] no more fright, [D] Together we'll soar to [A] new heights.

[Pre-Chorus] … [Chorus] …

[Bridge] [Am] When fear is knocking [Em] at your door, [C] Stand tall, and face it [D] once more. [Am] The journey's long, but [Em] you'll find, [C] You're stronger than you [D] realized.

[Chorus] …

[Outro] [Em] [G] Dance with the Fear [D] [A] Dance with the Fear [Em] [G] Dance with the Fear [D] [A] Dance with the Fear

I first noticed how it placed the generated chords in square brackets in line with the lyrics, which was nice. It picked up on this style of notation from my previous interaction. The second thing I noticed is that it was in the key of G, like the analyzed song, "Grow."

Here is a side-by-side comparison of the chord progressions.

Comparison of Chord Progressions, Image by Author

You can see that although the chord progressions have some similarities, there are some noticeable differences. For example, "Grow" has a mix of passages that use 4, 5, and 6 chords, whereas "Dance with the Fear" always uses four chords for the progressions.

Both songs heavily use the Em, G, and C chords. "Grow" mixes in B and Bm, while "Dance with the Fear" mixes in A, Am, and D. For reference, here's what GPT-4 said earlier about the key of G major.

The G major key consists of the following chords: G (I), Am (ii), Bm (iii), C (IV), D (V), Em (vi), and F#dim (vii°).

"Grow" occasionally uses the out-of-key B chord, and "Dance with the Fear" uses the out-of-key A chord. I particularly like the A to Am transition from the verse to the pre-chorus. To find out more about this transition, I asked GPT-4.

RobG: What is it called if the chord changes from A to Am in a song in the key of G major?

GPT-4: In music theory, using a chord that is not diatonic to the key is called a "chromatic chord" or "chromaticism." In the case of going from A major to A minor in the key of G major, the A major chord is not diatonic to the key, so it creates a sense of tension or dissonance. When the chord changes to A minor, it creates a sense of resolution or relaxation as the music returns to a diatonic chord.

Well, there you have it. I guess I like that chord change because of the return to the diatonic chord. Here is the song with lyrics and chords so you can listen for yourself. Once again, the backing tracks were provided by Band-in-a-Box.

The Band-in-a-Box app didn't have any settings for ska music, so I chose a reggae style and cranked up the tempo from 85 to 150 beats per minute. I also dropped out the bass and drums for the second verse, known as "a rhythm" in reggae music, and dropped out the horns for the bridge to add interest to the song. Overall I think the song is pretty good, and the chord progressions work well. Of course, what's missing is the vocal melody, but I will tackle that in the third and final installment of this series.

Check out two other tunes in the appendix with alternative rock and hip-hop styles.

Summary and Next Steps

In this article, I provided a little background info on the new GPT-4 model from OpenAI. I showed how I used the Whisper and Autochord AI models to extract lyrics and chords from songs and used my Python code on Google Colab to merge the two. I then showed how GPT-4 could analyze chord progressions for existing pieces and suggest chords for new songs in various styles.

My next step is to use GPT-4 to compose melodies for songs given lyrics and chords. I'll write about this in the final article in the series.

Discussion

Without any specific prompting to steer it in a different direction, GPT-4 seems to be working from a formula when composing songs. For example, it tends to use an (A) verse, (B) chorus, (A) verse, (B) chorus, (C) bridge, (B) chorus, and (A) outro form for the songs. And it always uses a four-chord pattern for the song parts.

By default, it will stick with the common diatonic chords in the key, but, as you saw above, you can steer it to use chromatic chords. In general, the chord patterns it creates sound good. I didn't use the "regenerate" command at all. And the patterns seem unique, with occasional sparks of innovation.

In the discussion at the end of my last article, I hypothesized that most music fans wouldn't care much if they found out that songwriters were using AI systems to help compose lyrics for songs. This would probably be true for composing chords, too. If, in the end, the songs are good, then the fans will like them, regardless of the tools that were used to create them.

Source Code

The source code for this project is available on GitHub.

Creative Commons Attribution Sharealike

Acknowledgments

I want to thank Pete Fayan from the Agents for his engagement with this project. I also thank Jon Gryckiewicz from Rhode Iceland and Fez Aswat from Hi Fi Monk for their contributions as well. I thank Jennifer Lim, Néstor Nápoles, and Oliver Strimpel for reviewing the article and providing feedback.

More on Writing Songs with GPT-4

Here are the first and third articles in this series.

Writing Songs with GPT-4: Part 1, Lyrics

Writing Songs with GPT-4: Part 3, Melodies

References

[1] OpenAI, GPT-4 Technical Report (2023)

[2] A, Radford et al., Robust Speech Recognition via Large-Scale Weak Supervision (2022)

[4] C. J. Bayron, Autochord – Automatic Chord Recognition Library and Chord Visualization App, (2021), 22nd International Society for Music Information Retrieval Conference

Appendix

Here are two more songs in different styles that I created with the help of GPT-4. You can read about how the lyrics were created in the first article of this series. The bands agreed to let me use AI to analyze their songs and use the analyses to create new songs with similar styles.

Fading Echoes

The first song is based on "Bloody Brain" by Rhode Iceland, an alternative rock band from Lowell, MA.

Battleground Voices

The second song is based on "Break" by Hi Fi Monk, a hip-hop/funk/reggae band based in Boston, MA.

Tags: Artificial Intelligence Gpt 4 Hands On Tutorials Machine Learning Music

Comment