ailsntua/Chordonomicon
Viewer β’ Updated β’ 680k β’ 1.47k β’ 42
A recurrent (LSTM) next-chord prediction model trained on the Chordonomicon dataset of 666,000 chord progressions. Given a sequence of chords, it predicts the next chord.
The weights ship as chordonomicon.safetensors. The full model config is stored
as JSON in the file's metadata (key checkpoint), so the file is self-describing β
tensors only, no pickle, nothing executes on load.
| File | Description |
|---|---|
chordonomicon.safetensors |
Weights + model_config in the file metadata |
vocabs.pkl |
Chord β id tables and chord β part-id lookups |
Helpers.py |
Model definition (build_model) and loaders |
β οΈ
vocabs.pklis a Python pickle β only load the copy from this repo.
Chord spelling matches the dataset: sharps as s (Cs, Fs), minor as min
(Amin, Emin7), slash chords as C/E.
pip install torch safetensors pandas huggingface_hub
import json, importlib.util
import pandas as pd, torch
from huggingface_hub import hf_hub_download
from safetensors import safe_open
from safetensors.torch import load_file
REPO = "manchuwook/chordonomicon-prediction"
model_path = hf_hub_download(REPO, "chordonomicon.safetensors")
vocabs_path = hf_hub_download(REPO, "vocabs.pkl")
helpers = hf_hub_download(REPO, "Helpers.py")
spec = importlib.util.spec_from_file_location("Helpers", helpers)
Helpers = importlib.util.module_from_spec(spec); spec.loader.exec_module(Helpers)
vocabs = pd.read_pickle(vocabs_path)
with safe_open(model_path, framework="pt") as f:
config = json.loads(f.metadata()["checkpoint"])["model_config"]
model = Helpers.build_model(config, vocabs)
model.load_state_dict(load_file(model_path))
model.eval()
def encode(chords):
ids = [vocabs["chord_to_idx"][c] for c in chords]
if config["mode"] == "chord":
return ids
key = "chord_id_to_part_ids_3" if config["mode"] == "triad" else "chord_id_to_part_ids_4"
return [vocabs[key][i] for i in ids]
@torch.no_grad()
def predict_next(chords, top_k=5):
enc = encode(chords[-50:])
x = torch.tensor([enc], dtype=torch.long)
lengths = torch.tensor([len(enc)], dtype=torch.long)
out = model(x, lengths)
logits = out if config["mode"] == "chord" else out[-1]
p, i = torch.softmax(logits[0], dim=-1).topk(top_k)
return [(vocabs["idx_to_chord"][j], prob) for j, prob in zip(i.tolist(), p.tolist())]
for chord, prob in predict_next(["C", "G", "Amin", "F"]):
print(f"{chord:<10} {prob:.3f}")
Full training, evaluation and benchmark code is in the
Chordonomicon repository
(Chord_Prediction branch).
@article{kantarelis2024chordonomicon,
title = {CHORDONOMICON: A Dataset of 666,000 Songs and their Chord Progressions},
author = {Kantarelis, Spyridon and Thomas, Konstantinos and Lyberatos, Vassilis and Dervakos, Edmund and Stamou, Giorgos},
journal = {arXiv preprint arXiv:2410.22046},
year = {2024}
}