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.
- Key Progression: The model first infers the most likely sequence of local keys (modulations) for the melody ($k_n$).
- 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.
- 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