“Bach’s music… …is a really good resource for machine learning to learn music”
-Jacob Howcroft, Software Engineer, Google Doodle Team
I came across the Bach Google Doodle last spring:

It was created using a machine learning model which was trained on 306 of Bach’s chorale harmonizations. A chorale harmonization is a short piece written in four parts, typically a sung by a choir in a church. A typical example looks something like this:

The Google model was trained by taking a Bach Chorale, deleting random notes from it, and then having the model guess the missing notes. The basic way the Doodle works is that the user inputs a two-bar melody consisting of any notes they want. The Doodle then harmonizes the melody “in Bach’s distinctive style”.
After inputing a single-line melody of your choice into the model…

…the AI returns a four-part harmonization in the style of Bach:

What I find fascinating about this Doodle is not the high quality of the music that it produces (the beginning and end usually sound good, but things tend to go off the rails in the middle), but rather is the type of music that it produces. It doesn’t harmonize the melody simply by producing lead-sheet style chords. It actually produces four-part counterpoint.
What’s the difference between counterpoint and a lead sheet? A typical lead sheet looks something like this:

There’s the melody with the name of the chord written above each note. This lets the musicians know which notes they should play along with the melody as accompaniment. And this “lead sheet notation”, at least in my opinion, is a major achievement of Western Civilization. It allows an entire song to be condensed onto a single page, with all of the basic information intact.
But lead sheets leave a lot of room for interpretation by individual performers: the performers have a lot of freedom regarding the specific notes that they choose to play. This is in stark contrast with classical music, where all of the notes tend to be written out explicitly.
In other words, the Doodle could have “harmonized” the melody into a lead sheet, like this:

Technically, the chords are the same in both outputs. What makes the Bach Doodle more sophisticated is that rather than producing a single series of chord symbols, it outputs four distinct melodic lines. And this actually gives some insight into how modern Western music developed in the first place.
A common way to start learning music is to learn chords, maybe on a guitar or on a keyboard. And this is a great way to get started: there are countlessly many songs that only require three chords in order to play. For example, this Lynyrd Skynyrd classic:

But chords are deceptively simple. They are the Python of music. They’re easy to learn, they are very powerful, and they can do amazing things, but they’re actually a very recent historical phenomenon, the product of hundreds if not thousands of years of development.
Humans have been making music from time immemorial, but it’s really only since the European Middle Ages that there has been anything resembling modern polyphony. For example, if you listen to Peking Opera, no matter how many people are singing or playing instruments, they’re only ever playing one unique note at a time. (and where polyphony did exist in non-Western cultures, for example in Africa and Oceania, it was usually in the form of drones like on a bagpipe.)
How did polyphony develop in the West? For centuries, monks had sung single-voice Gregorian Chant. As time went on, another line would be added to enhance the harmony, often resulting in the kind of parallel motion you might remember from the monks in Monty Python and the Holy Grail:

Although this chant contains three separate lines, they are all perfect parallel copies of each other. In data science speak, there is perfect multicollinearity, with no linear independence whatsoever. But, as time went on, these additional voices became more and more independent, until by Bach’s time, they had developed into the modern tonal harmony that we know today.
So let’s take one more look at some four-part harmony, in the form of Beethoven’s famous Ode To Joy:
This particular arrangement includes the lead-sheet chord symbols. But if you look closely, you’ll see that there’s a lot going on under the surface. The first five notes, for example, are written as “F” using chord symbols, yet in reality there are four distinct lines of music, each with its own individual contour and register that can’t be captured with only a chord symbol.
As modern musicians, it can be easy to forget that there is more to tonal harmony than chords, just as it can be easy to forget, as data science students, that there’s more to computer science than high-level programming languages like Python. Chords are so simple to learn and easy to use that one can forget that they actually developed out of something more fundamental.
Google’s Bach Doodle is a great tool for getting back in touch with where chords and, more broadly, Western tonal harmony actually came from: multiple lines of music playing at the same time, namely, counterpoint.
