BacHMMachine: An Interpretable and Scalable Model for Algorithmic Harmonization for Four-part Baroque Chorales

Yunyao Zhu, Stephen Hahn, Simon Mak, Yue Jiang, Cynthia RudinarXiv 2021

Abstract

BacHMMachine is a theory-driven Hidden Markov Model (HMM) designed for automated musical harmonization. By embedding classical composition principles and functional harmony constraints, it generates high-quality four-part chorales. The model offers significant improvements in speed and interpretability compared to deep learning approaches while maintaining competitive musical quality.

Introduction

Algorithmic harmonization—the task of generating a multi-part harmony for a given melody—is a classic challenge in computer music. Recently, the field has been dominated by "black-box" deep learning models like Google’s Coconet or DeepBach. While these models produce impressive results, they have significant drawbacks: they require massive amounts of training data, are computationally expensive, and often "forget" basic music theory rules, leading to errors like parallel fifths or nonsensical chord inversions.

On the other hand, older rule-based or simple Markov models often lack the creative "flow" of a human composer. The authors of BacHMMachine sought to bridge this gap by creating a model that is musically informed (using the "phrase model" of Baroque music) yet flexible enough to learn a composer's specific style from data.

Methodology

The core of BacHMMachine is a two-stage Key-Chord Hidden Markov Model. Unlike standard HMMs that might only consider chord transitions, this architecture explicitly models the hierarchical nature of music by separating key modulations from chord selections.

Two-stage Key-Chord Hidden Markov Model architecture.
  1. Key Progression: The model first infers the most likely sequence of local keys (modulations) for the melody ($k_n$).
  2. Chord Progression: Given the keys and the observed melody ($m_n$), it then infers the specific Roman numeral chords ($c_n$).

Theory-Driven Constraints

What makes BacHMMachine unique is the integration of formal music theory into the probabilistic framework. Instead of letting the model learn everything from scratch, the authors set the probability of "retrogressive" progressions (moves that violate standard music theory) to near zero.

Functional harmony transitions and Roman numeral mappings.
  • State Space Reduction: By representing chords as Roman numerals and transposing all training data to a common key, the search space was reduced from thousands of redundant MIDI-note combinations to just 31 functional chords.
  • Hard Constraints: The model applies a "penalty" system for violations of classical voice-leading rules, such as voice crossing or notes falling outside a singer's natural vocal range.
  • Non-Chord Tones: It probabilistically adds "ornamental" notes (passing tones, appoggiaturas) to make the music feel more fluid and less "blocky."

Key Results and Insights

The model's performance highlights the benefits of combining domain knowledge with statistical learning:

  • Efficiency: BacHMMachine is roughly 30x faster than Google’s Coconet at generating a new chorale and 1,000x faster to train than previous HMM-based approaches.
  • Interpretability: Because the model uses transition matrices, researchers can visualize what the model learned. For example, it correctly learned that "Tonic" chords lead to "Predominant" or "Dominant" chords with high probability.
  • Musical Quality: In blind listening tests on Amazon Mechanical Turk, participants preferred BacHMMachine’s harmonizations over those generated by Coconet. In a "Bach Turing Test," 31% of respondents believed the model's output was actually composed by J.S. Bach.
  • Flexibility: The model successfully harmonized rock melodies (like Procol Harum’s A Whiter Shade of Pale) by simply swapping the training data, proving the framework's versatility across genres.

Conclusion and Future Work

While BacHMMachine is highly efficient, it doesn't yet capture the full "creative signature" of Bach—human-composed originals still win in preference tests. Future directions include moving to higher-order Markov models to capture longer musical phrases, using finer time scales for complex rhythms, and explicitly modeling pivot chords for smoother key transitions.

Summary updated

BibTeX
@misc{zhu2021bachmmachine,
  author = {Yunyao Zhu and Stephen Hahn and Simon Mak and Yue Jiang and Cynthia Rudin},
  title = {{BacHMMachine: An Interpretable and Scalable Model for Algorithmic Harmonization for Four-part Baroque Chorales}},
  year = {2021},
  eprint = {2109.07623},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2109.07623},
}
Figure