HarmonyRL
Chord progressions for a melody. HarmonyRL reads a lead sheet from MusicXML or MIDI, writes chords under the melody, and can redraw only the bars you choose while keeping the rest.
The models are transformer chord policies pretrained on human accompaniments, then fine-tuned with reinforcement learning. Pick the one whose sound you want:
| Model | Style |
|---|---|
CloudHolic/harmonyrl-chromatic |
rich reharmonization, many chords from outside the key |
CloudHolic/harmonyrl-smooth |
consonant, resolving progressions |
CloudHolic/harmonyrl-base |
close to the training data |
Each model card describes its training and evaluation.
Installation
Python 3.12 or later.
pip install harmonyrl
A GPU is used when PyTorch finds one; the models also run on the CPU.
Usage
from pathlib import Path
from harmonyrl import HarmonyRL
from harmonyrl.ingest import read_lead_sheet
from harmonyrl.render import write_lead_sheet
model = HarmonyRL.from_pretrained("CloudHolic/harmonyrl-chromatic")
sheet = read_lead_sheet(Path("melody.musicxml")).sheet
# Up to 3 different harmonizations of the whole lead sheet
candidates = model.harmonize_sheet(sheet, candidates=3, seed=0)
write_lead_sheet(candidates[0], Path("harmonized.musicxml"))
# Redraw bars 4 and 5 (counted from 0) and keep every other chord
redrawn = model.harmonize_sheet(candidates[0], bars=range(4, 6), candidates=2)
write_lead_sheet(redrawn[0], Path("redrawn.mid"))
A lead sheet that already has chord symbols works the same way: read it, then pass bars= to
fill only those bars. Without bars=, every chord is written anew.
Generation settings
Each model ships its defaults in generation_config.json. Keyword arguments override them for
one call, and model.generation_config holds them for later calls.
| Setting | Meaning |
|---|---|
temperature |
Sampling temperature. Lower is safer, higher is more varied |
pool |
When refilling bars between kept chords, drafts drawn per candidate; the chords after the bars weigh which drafts are returned |
max_duplicates |
Repeated draws allowed before the search for distinct candidates stops |
model.harmonize_sheet(sheet, candidates=4, temperature=0.8)
The candidates always differ, so a call can return fewer than candidates (at most 16): each
draw that repeats a candidate already found counts toward max_duplicates (1 by default), and
the search stops there with what it has. A few bars between kept chords often leave few distinct
progressions, so raise max_duplicates to look longer. seed makes a call reproducible on the
same device.
Melodies and chords as data
HarmonyRL.harmonize takes 1 Melody of up to 32 bars and returns a list of up to candidates
tuples of ChordEvent, the types in harmonyrl.schema. harmonize_sheet splits longer parts
into overlapping 32-bar windows (overlap=, 4 bars by default) and calls it per window.
Files
| Format | Read | Write |
|---|---|---|
MusicXML (.musicxml, .xml; .mxl read only) |
melody and chord symbols | melody and chord symbols |
MIDI (.mid, .midi) |
melody | melody and chords |
- A score splits into parts at time signature changes and, in MusicXML, at rehearsal marks.
Bar numbers in
bars=count across all parts. read_lead_sheet(path, part=...)picks the part (MusicXML) or track (MIDI) that holds the melody; without it, the most melody-like one is chosen.- The whole piece gets 1 key, from its key signature and notes. Pass
key=when the key signature does not match the music. - Chord symbols the model cannot spell exactly are approximated; their bars are listed in
SheetImport.approximated. Repeats are read as written, not expanded, and reported inSheetImport.warnings. - To refine chords over several sessions, write MusicXML and read it back. MIDI output keeps the chords only as notes.
Limitations
- One call to
harmonizecovers up to 32 bars, and the windows ofharmonize_sheetdo not see each other beyond their overlap, so song-level structure such as repeated verses is not modeled. - A new chord can sound abrupt against the kept chords around it. Redraw, or ask for more candidates.
- Each harmonization is a sample: outputs differ from draw to draw unless
seedis set.
License
The code is MIT licensed. The model weights are CC BY-NC-SA 3.0, following their training data: Hooktheory melodies and chords as released with Sheet Sage (Donahue, Thickstun, Liang, "Melody Transcription via Generative Pre-Training", ISMIR 2022).
Metadata
Release files for harmonyrl 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| harmonyrl-1.0.0.tar.gz | 38.7 kB | Without provenance | Details for harmonyrl-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| harmonyrl-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for harmonyrl-1.0.0-py3-none-any.whl |
Total release size: 88.3 kB
Release files / harmonyrl-1.0.0.tar.gz
| Download URL | harmonyrl-1.0.0.tar.gz |
|---|---|
| Size | 38.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d3321b0235566e6949cd191907870141c15423532093b3cd76a6b289eeca921d
|
|
BLAKE2b-256 checksum How to use checksums |
6e3df0a938978a7042e819af5394cccd1d14c5ef5a6d471bb1df99c5509b5bb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / harmonyrl-1.0.0-py3-none-any.whl
| Download URL | harmonyrl-1.0.0-py3-none-any.whl |
|---|---|
| Size | 49.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd8e701002fa6f948e65681d5eb3e84357432c064b7c649f19e631663cebfe8c
|
|
BLAKE2b-256 checksum How to use checksums |
160af870c30d2946ded111d3b2e599aec993c35c421f35c1bebafb1647b9f17a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for harmonyrl 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.