Imani Danielle Mosley

bassoonist | musicologist | digital humanist

Filtering by Tag: computational musicology

Breaking the Doodle: Bach, AI, and our quest for the human

Before I start this post, I just want to address where I've been. Since my last post, I finished my dissertation and will be defending it next week (!!!) Needless to say, that took all of my focus and effort. I've tried as much as I could to post interesting things over at @humanistmachine but I'm hoping that with this post, I will be able to get back into the regular swing of things. Thank you to everyone who has written me telling me how much they have enjoyed my writing, it is always noted and appreciated.

———

Bach.

Our Eternal (musical) Father in Heaven. My birthday twin (happy birthday to us!) Loathed by every musician who has to breathe in order to perform. Every scientist & mathematician's favorite composer. 269 years later, we are still as enthralled with him as ever, convinced that hidden within his compositions are the secrets of life, death, and the universe. I will admit my deep love for Bach before I continue to make my position clear; I have his family crest tattooed on my right arm. So my birthday is often spent thinking about Bach a fair deal (something I hated as a child, it's my birthday too, damnit). Today was no exception. I woke up this morning to news of today's Google doodle in honor of Herr Bach: an interactive game of sorts, created using machine learning where you could input a soprano melody line, crank up the machine, and watch as it generated some good old-fashioned Bachian eighteenth-century counterpoint.

In that moment, I had no idea that I would spend the entirety of my day talking about it but, honestly, I should have known better.

Today’s Google Doodle, in honor of Bach’s 334th birthday

Today’s Google Doodle, in honor of Bach’s 334th birthday

My copy of the Bach-Riemenschnieder, no house is complete without it

My copy of the Bach-Riemenschnieder, no house is complete without it

The doodle is adorable. It even comes with a Wendy Carlos Switched-on-Bach-style version that is equally adorable (though sadly there's no mention of that seminal work and its history) And on its face, it's pretty remarkable. The start up graphics tell you how the doodle was created and that 306 of Bach's compositions were used as a dataset…not bad (only Papa Bach can give us those kinds of data points, right?) But like the constant pedants we are, my friends — music theorists, musicologists, performers, etc — immediately saw the doodle as a challenge with the intention of breaking it. What does that look like, exactly? My friend and colleague (who teaches counterpoint) plugged in the chorale tune "Erhalt uns, Herr, bei deinem Wort" (number 72 in the Bach-Riemenschnieder book of 371 harmonized chorales if you're following along) to get a two-measure result that he then graded (he was grading counterpoint homework anyway). Another friend put in her own soprano line, nothing crazy, but the result ended strangely with an F-sharp in the soprano line sounding at the same time as an F-natural in the bass. Other friends put in well-known tunes for their soprano melody lines ("All Star," "Baby Shark," and so on) while theorists on social media dug their heels in, complaining about the game's inability to understand cross-relations, part-writing, and other staples of contrapuntal writing.

Counterpoint analysis graded, courtesy of Google and Douglas Buchanan

Counterpoint analysis graded, courtesy of Google and Douglas Buchanan

This post isn't really about whether or not machine learning did a good job in this exercise. I'm not a theorist and though I'm trained well enough to talk extensively about contrapuntal writing and when it is and is not successful, I'm not quite concerned with that. My hat is off to the team at Google Magenta (a project with which I'm familiar) who used TensorFlow.js and other tools to create this doodle. If you have read my previous posts, you know that this type of project is similar to the kind of work I was doing at NPR and I know what goes into creating something like this. 306 compositions is a relatively small dataset, generally speaking (in my opinion, not nearly enough for supervised learning) and I think that it has provided a lot of people with some enjoyment today.

What I am interested in is the AI community's, dare I say it, obsession with Bach. Because I believe that the continued use of Bach as jumping off point for artificial intelligence reveals some very important things, namely how we think about Bach, how we think about the compositional process, and AI's ethical relationship to art and even humanity. This doodle is not the first example of using neural networks & machine learning to replicate Bach. An article in MIT Technology Review titled "Deep-Learning Machine Listens to Bach, Then Writes Its Own Music in the Same Style" asks readers if we could imagine trying to distinguish music written by Bach and music written by a neural network trained in Bach's style. The neural network, called DeepBach, is the work of Gaetan Hadjeres and Francois Pachet at the Sony Computer Science Labratories in Paris. Like the Google Magenta team, they started with 352 of Bach's chorales but in order to expand the dataset, they transposed them and the various permutations created a dataset with 2503 chorales. Their result, unsurprisingly, is far more nuanced than that of the Google doodle. And in their findings, half of their participants (that included professional musicians, music students and the like) thought the AI-generated music was by Bach 50% of the time, a very good number for such a project. While the research behind this is interesting, the text in the article sneakily gives away why Bach is the subject of such fascination: "These compositions have attracted computer scientists because the process of producing them is step-like and algorithmic. But doing this well is also hard because of the delicate interplay between harmony and melody."

Won’t you please think of the kittens?

Won’t you please think of the kittens?

Let's start with the first part of this thought. In a conversation I had today with a data scientist at Duke and our music librarian, I used the term "formulaic," a term I instantly regretted. I was not trying to say that Bach was formulaic in his compositions (something that our librarian clocked me on immediately), but that this understanding of counterpoint as rule-driven is problematic. Outside of musicology (and I mean that with a capital M, including theory and analysis) — and, in some places, within our discipline as well — there persists this idea of the mathematical Bach, the orderly Bach, the Bach who embodied the centuries-old rules of contrapuntal writing (if you're a music major, then you've seen the Bach parallel fifths kitten meme). Unsurprisingly, it is always more complex than that. Yes, from Gradus ad Parnassum and onward, we music students learn about the dos and donts of contrapuntal writing at our peril. What's good for Fux, is good for us, nein? But as I told our young data scientist today, this is and has always been a baseline (oh god, sorry for that pun) from which we can see and appreciate the creativity involved in composition of all things. I had one counterpoint teacher in college who often said that you can't break the rules if you don't know the rules. And Bach was a rule-breaker. There's no space here to get into the dizzying landscape that was Bach's compositional process. But it is important to place that brilliance alongside Bach's very real, very mortal life as a working composer. Even with this context, the mathematical Bach persists, enough to connect at least his chorale compositions to the modern idea of algorithms.

But what is to be said for melody and harmony as the second part posits? In Forkel's biography of Bach, he writes extensively on Bach's harmonic writing. In the following passage, he outlines how freedom is an essential quality of Bach's compositional process:

In such an interweaving of various melodies which are all so singing that each may, and really does, appear in its turn as the upper part, Bach's harmony consists … In his compositions in four parts, you may sometime even leave out the upper and lower part, and still hear in the two middle parts an intelligible and pleasing music. But to produce such harmony, in which the single parts must be in the highest degree flexible and yielding towards each other if they are all to have a free and fluent melody, Bach made use of quite peculiar means, which had not been taught in the treatises of musical instruction in those times, but with which his great genius inspired him.

Leaving the genius part at the end alone for now, this description of Bach's contrapuntal writing is as far away from step-like and algorithmic as possible. It is not quite as plug and play as the doodle might suggest. And this description of Bach comes at the beginning of the nineteenth century (contributing to the resurgence in Bach scholarship), it is not some twenty-first century portrait. Perhaps, the persistence of the mathematical Bach stems from Douglas Hofstadter's popular work Gödel, Escher, Bach though the book itself is more a study on cognition than anything else. Rahul Siddarthan, in his article on Bach and mathematics, attributes the appeal of Bach to scientists as the following:

The music of Bach seems to have a particularly wide following among scientifically or mathematically minded people … One could point to several reasons for this — the highly regular structures, the complex counterpoint, the use of simple themes to construct elaborate structures.

While we've already tackled some of these points earlier, this I think gets to the heart of the issue. How do we explain what music is, what it does, why it exists? Evolutionary biologists have been struggling with some of those questions for a long time (not to mention philosophers and mathematicians) There is a deep desire within humans to connect with pattern making and repetition, we know this. And with an art as non-representational as music, coming from who knows where, the mere presence of patterns gives us a grounding, a place to start from, a way to understand the non-understandable. And isn't that at the heart of artificial intelligence? The question has always been whether or not AI can re-present the most human aspects of our intellegence: creating art or music or humor. All of the other stuff is relatively simple by comparison. Language is just networks and networks are the computer's bread and butter (though deep learning has shown us that sometimes writing is hard, too) But to replicate the work of Picasso or Pollock? Bach or Mahler? That's the good stuff, that's the threshold. So with Bach, supposedly, you get the sublime ethereality of a brilliant composer (very human) with the math of a calculator. And this provides some really interesting questions and ethical debates for us to ponder. Does this desire to re-create art through AI act as another way for us to understand the unknowns of our own human mind? What purpose does this exercise serve? It can't be more than a digital party trick, it has to be at the service of something greater. I'm no philosopher so I won't attempt at these larger questions but as we approach (or are in) the posthumanist age, I think there is a desire, nay a need, to know more about what makes us human more than ever. Using AI perhaps is the long way round but it's a desire with which I can empathize.

This is all to say that I doubt that Bach will stop being the go-to for AI-generated music soon. I personally would love to see the rationale behind a Mahler dataset or a Sibelius dataset or any other composer, really (in truth, Schubert lieder could provide some fantastic data points), a composer to whom these ideas of rigidity are not so stubbornly attached. I think it would raise more questions than answers, more problems than solutions. But that's okay because it's one of the things that makes art, art.

Exspiravit ex machina

Getting this started has proved more difficult than initially envisioned, who knows why. I say this because I have been completely overtaken by this work and the questions that have arisen from it so, naturally, writing about it should be easy, right?

Right.

Let's start with a little background (or perhaps quite a bit of it), when I accepted this internship at NPR, I had no idea, truly, what I was in for. I've spent the last two years immersed in digital humanities and librarianship, realizing that this space was perfect for me. It was a weird combination of all the things I love, addressing the many and myriad questions I had about being a scholar in the future whatever that means, and it allowed me to focus on the things at which I'm really quite good: workflows, information management, metadata, academic technology, and so on. These were things that, over the years, I've noticed musicology as a discipline had little interest in (something that did not and still makes no sense to me personally) and this outlet was one I needed badly. So when I saw the call for interns and read the description, I knew it was something I needed to do. I had no idea just how much that decision would change my life.

Well that was dramatic.

My internship began and I learned about my daily tasks, things I was aware of such as ingesting new promotional music into our in-house database. After a few weeks of general intern training and practice working with our systems, I moved on to the real meat: music information retrieval (MIR) mood tagging. Now I had to do some research, you know, real scholarly stuff first. I read published papers by those foremost in the field such as J Stephen Downie and read the documentation provided by Essentia, the algorithm library we use to assess our tracks. Scintillating stuff that lead to the deepest of rabbit warrens. It was here that I learned about digital musicology, a term I had heard but with which I had not engaged. I am still learning quite a bit about it but what I have gleaned so far is that…there are not a lot of musicologists involved in digital musicology. That might sound odd to you, it sounded odd to me at first. Let's spend a little time on that, shall we?

Digital musicology along with music information retrieval touches on a number of various fields: music theory, acoustics, music cognition/perception, music psychology, programming, music science, library studies, and more. I suggest the Frontiers in Digital Humanities page linked above for more information. And to be fair, there are musicologists engaged in this work, asking really interesting questions. But when MIR is put to work in the real world, say, music streaming services, the specific tools that musicologists have as humanists are shelved in favor of the tools of theorists and programmers. 

Enter yours truly.

In the process of undertaking a massive assessment of several MIR algorithms, I found myself asking lots of epistemological questions — humanist questions — that seemed unanswered. What is tonality and how do we define it for an algorithm? What should be included in our training models? What biases are represented and replicated in our algorithms? Musicologist Anna Kijas touches on these things beautifully in her Medium post, taken from her keynote at the very recent Music Encoding Conference (at which my project supervisor was present) and I highly suggest reading it. I will get into all of the problems I have faced and am facing but this is already quite long for a blog post. (I know, it's my blog, I can do what I like. Point taken.) Plus, I feel it's only fair to give those problems the space they deserve.