Feature Extraction
Transformers
Safetensors
PyTorch
beat_quantizer
music
rhythm-quantization
melody
symbolic-music
custom_code
Instructions to use wellCh4n/beat-quantizer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use wellCh4n/beat-quantizer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="wellCh4n/beat-quantizer", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("wellCh4n/beat-quantizer", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
BeatQuantizer (BeatQuantizerForRhythm)
Self-contained neural melody rhythm quantizer that snaps continuous vocal/melody note timings onto a 12-subdivision-per-beat score grid (supporting quarter, 8th, 16th notes, and triplets across 4/4, 3/4, 2/4, 6/8, and 12/8).
Model Specifications
| Property | Value |
|---|---|
| Architecture | 8-layer Pre-LN Relative-Bias Transformer (d_model=384, nhead=8, dim_feedforward=1536) + Monotonic Viterbi DP |
| Parameters | 15.01M (FP32, 57.28 MiB safetensors) |
| Grid Resolution | 12 subdivisions per beat (0, 3, 4, 6, 8, 9 for straight meters; 0, 2, 4, 6, 8, 10 for 6/8 & 12/8) |
| Supported Meters | 4/4, 3/4, 2/4, 6/8, 12/8 |
| Inference Latency | ~50 ms per full song on CPU |
Evaluation (GTSinger-CN Held-Out Test Set, 993 clips / 4,094 unseen bars)
| Metric | Score |
|---|---|
| Bar Rhythm Exact Match (Bar EM) | 75.65% (3,097 / 4,094) |
Strict Onset F1 (tol=0) |
91.51% |
Loose Onset F1 (tol=1) |
91.58% |
| 16th-Note False Positive Rate | 5.77% |
Usage
Requires transformers, torch, and numpy:
import numpy as np
from transformers import AutoModel
model = AutoModel.from_pretrained("wellCh4n/beat-quantizer", trust_remote_code=True)
model.eval()
# Option A: Quantize beat coordinates directly -> integer 12-grid (g_on, g_off)
res = model.quantize_sequence(
b_on=[0.02, 0.48, 1.03, 1.51],
b_off=[0.45, 0.96, 1.48, 1.95],
midi=[60, 62, 64, 62],
meter="4/4",
feel="straight",
bpm=96.0,
)
print(res) # {"g_on": [0, 6, 12, 18], "g_off": [6, 12, 18, 24]}
# Option B: Quantize physical seconds against beat_times -> Fraction q_on / q_off
beat_times = np.linspace(0.0, 10.0, 21)
notes = [
{"start": 0.01, "end": 0.46, "midi": 60},
{"start": 0.51, "end": 0.97, "midi": 62},
]
qnotes, grids = model.quantize_notes(notes, beat_times, meter="4/4", feel="straight")
print([(n["q_on"], n["q_off"]) for n in qnotes])
API & Decoding Parameters
model.quantize_sequence(b_on, b_off, midi, meter="4/4", feel="straight", bpm=100.0, override_params=None)
b_on,b_off(Sequence[float]): Note onset/offset positions in continuous beat units (>= 0).midi(Sequence[int]): MIDI pitch numbers (36β88).meter(str): Time signature ("4/4","3/4","2/4","6/8","12/8").feel(str): Rhythmic subdivision feel ("straight"or"triplet").bpm(float): Tempo in beats per minute (clamped to[30, 240]).- Returns
{"g_on": list[int], "g_off": list[int]}in 12-grid units (beat = g / 12).
model.quantize_notes(notes, beat_times, meter="4/4", feel="straight", override_params=None)
notes(list[dict]): Each dict must have"start","end"(seconds), and"midi".beat_times(Sequence[float]): Monotonic beat timestamps in seconds.- Returns
(qnotes, grids)where each note dict addsq_on/q_off(fractions.Fractionbeats) andgrids[beat_idx]is the max subdivision denominator in that beat.
Default decode_params (overridable via override_params)
lambda_ioi:1.0β weight for inter-onset-interval transition score in Viterbi DP.slot_16th_bias:0.35β penalty against spurious off-8th 16th-note onsets.slot_triplet_bias:0.45β penalty against triplet subdivisions in"straight"feel.mix_pen:2.0β penalty against mixing binary and triplet subdivisions within the same beat.legato_thr:0.45β probability threshold for snapping tied/legato offsets directly tog_on[i+1].dur_dev_pen:4.0β quadratic penalty against deviating from physicalb_off.max_end_dev_grids:4β maximum symmetric deviation (in 12-grid units) from rounded physical offset.max_end_overhang_grids:4β maximum phrase-end overhang beyond physical offset.phrase_end_16th_pen:0.45β penalty on trailing 16th-note endings before rests.
- Downloads last month
- 56