mir_eval developer on retainer: mir_eval.melody.evaluate(ref_voicing=float_scores) nonzero float truthy — 180,000 unvoiced frames included — Raw Pitch Accuracy 71% reported vs 89% actual — 14 months — mir_eval developer on monthly retainer
mir_eval 0.7 • Python 3.9; mir_eval.melody.evaluate(ref_voicing=ref_voicing_float); MedleyDB float confidence scores 0.0–1.0 passed as voicing; nonzero float → truthy → 180,000 unvoiced frames (confidence 0.001–0.499) included as voiced; denominator 900,000 vs correct 720,000 frames; melody extractor noise pitches on spurious frames; Raw Pitch Accuracy 71% reported; actual 89%; 14 months wasted improving architecture below state-of-the-art; fix: ref_voicing=(ref_voicing_float ≥ 0.5); 89% • Westfield MIR Eval Ltd. (1,200 polyphonic clips; 1,200,000 frames; 14 months; 2.5h)
Westfield MIR Eval Ltd. built an automatic melody extraction system for a singing voice corpus — 1,200 polyphonic audio clips of 10 seconds each, 22.05 kHz, with ground-truth annotations from the MedleyDB probabilistic melody annotator at 100 frames per second (10 ms per frame), totalling 1,200,000 annotation frames. The MedleyDB annotator outputs a float voicing confidence score (0.0–1.0) per frame and a reference pitch frequency in Hz per voiced frame. The correct usage is to binarize the confidence score at 0.5 to obtain a boolean voiced/unvoiced label per frame. The developer passed the raw float confidence array directly to mir_eval.melody.evaluate(ref_time, ref_freq, est_time, est_freq, ref_voicing=ref_voicing_float, est_voicing=est_voicing_bool). Inside mir_eval.melody, the voicing inputs are tested as ref_voicing > 0: any strictly positive value is treated as voiced, 0.0 exactly is treated as unvoiced. Of the 1,200,000 total frames: 720,000 (60%) had confidence ≥ 0.5 (genuinely voiced — sustained notes, vibrato, legato passages); 180,000 (15%) had confidence in (0.0, 0.5) (low-confidence boundary frames from consonant transitions, brief pauses, annotation ambiguity near voicing onset and offset); 300,000 (25%) had confidence = 0.0 exactly (unambiguously unvoiced: instrumental breaks, silence, fricatives). The 180,000 low-confidence frames were included as voiced reference frames in the evaluation. On those frames, the melody extractor produced near-silence outputs (0 Hz, sub-55 Hz noise, or spurious harmonics): approximately 5% coincidentally fell within 50 cents of some reference frequency. The result: denominator 900,000, numerator 649,800, reported Raw Pitch Accuracy 71.4%. Actual accuracy (correctly evaluated): 640,800 / 720,000 = 89.1%. The 17.7-percentage-point gap meant the system appeared to perform below the state-of-the-art benchmark of 85% on this corpus, when it in fact exceeded it by 4 points.
The mechanism: mir_eval.melody.raw_pitch_accuracy(ref_voicing, ref_freq, est_voicing, est_freq) computes a voiced mask as voiced = (ref_voicing > 0) & (est_voicing > 0), then computes accuracy as the fraction of voiced frames where the pitch difference is within 50 cents: np.mean(np.abs(freq_to_cents(ref_freq[voiced]) − freq_to_cents(est_freq[voiced])) < 50). For a correctly binarized ref_voicing (threshold at 0.5), voiced spans 720,000 frames × (est_voicing match fraction ≈ 1.0) = 720,000 genuine evaluation frames. With float ref_voicing, voiced spans 900,000 frames: 720,000 genuine + 180,000 spurious low-confidence frames. The 180,000 spurious frames are regions where the reference annotator was uncertain whether voicing was present — by design, the melody extractor had no ground truth to track. The extractor either outputs 0 Hz (below the minimum 55 Hz threshold, treated as unvoiced by est_voicing) or some harmonically plausible pitch from the polyphonic mixture (a spurious partial). With est_voicing being boolean True when the extractor detects any pitch: on the 180,000 spurious reference frames, est_voicing is True for approximately 60% (108,000 frames) where the extractor detects a background partial; of those, ~8% (8,640 frames) coincidentally fall within 50 cents of the low-confidence reference pitch. This adds 8,640 “correct” frames to the numerator but 108,000 to the denominator — reducing the computed accuracy from 89.1% to 71.4%. The fix was a one-line change: ref_voicing_bool = (ref_voicing_float ≥ 0.5).astype(float). The 14 months of model retraining, architecture changes, and self-supervised pretraining that followed the first publication were responding to an artifact of evaluation, not a limitation of the model. Hours logged to HourTab per session.
# Westfield MIR Eval Ltd. — mir_eval 0.7 voicing threshold fix
# mir_eval 0.7; Python 3.9; NumPy 1.24; librosa 0.10
# Automatic melody extraction evaluation; 1,200 polyphonic clips × 10 s × 100 fps
# Total frames: 1,200,000; ref_voicing: float confidence 0.0–1.0 (MedleyDB annotator)
#
# Problem: ref_voicing_float passed directly to mir_eval.melody.evaluate
# nonzero float > 0 → truthy → 180,000 low-confidence frames included as voiced
# denominator: 900,000 (should be 720,000)
# melody extractor noise pitches on spurious 180,000 frames drag accuracy down
# Reported Raw Pitch Accuracy: 71% — Actual: 89%
# Fix: binarize ref_voicing at 0.5 threshold before evaluation
import numpy as np
import mir_eval
VOICING_THRESHOLD = 0.5 # MedleyDB annotator decision boundary
def validate_voicing_array(ref_voicing: np.ndarray,
total_frames: int,
corpus_name: str = "") -> None:
"""
Guard against passing raw float confidence scores as voicing.
Voiced fraction should be 0.50–0.75 for typical polyphonic audio.
Deviations indicate misconfigured threshold or wrong voicing type.
"""
voiced_fraction = np.mean(ref_voicing > 0)
if voiced_fraction > 0.80:
raise ValueError(
f"Voiced fraction {voiced_fraction:.2%} exceeds 80% {corpus_name}. "
f"Likely cause: ref_voicing is float confidence scores "
f"(all nonzero values treated as voiced). "
f"Apply threshold: ref_voicing = (ref_voicing_float >= {VOICING_THRESHOLD}).astype(float)"
)
if voiced_fraction < 0.40:
raise ValueError(
f"Voiced fraction {voiced_fraction:.2%} below 40% {corpus_name}. "
f"Likely cause: voicing threshold set too high or ref_voicing all-zero. "
f"Check annotation loading and threshold configuration."
)
def evaluate_melody(ref_time: np.ndarray,
ref_freq: np.ndarray,
ref_voicing_input: np.ndarray,
est_time: np.ndarray,
est_freq: np.ndarray,
est_voicing: np.ndarray,
corpus_name: str = "") -> dict:
"""
Safe wrapper for mir_eval.melody.evaluate that:
1. Binarizes float voicing confidence scores at VOICING_THRESHOLD.
2. Validates voiced fraction is in the expected 0.50–0.75 range.
3. Returns all five standard melody evaluation metrics.
"""
# Detect and handle float confidence scores
if ref_voicing_input.dtype.kind == 'f':
# Float input — binarize at threshold
ref_voicing_bool = (ref_voicing_input >= VOICING_THRESHOLD).astype(float)
else:
# Already boolean — use as-is
ref_voicing_bool = ref_voicing_input.astype(float)
# Validate voiced fraction
validate_voicing_array(ref_voicing_bool, len(ref_time), corpus_name)
# Evaluate
scores = mir_eval.melody.evaluate(
ref_time, ref_freq,
est_time, est_freq,
ref_voicing=ref_voicing_bool, # FIXED: binarized boolean
est_voicing=est_voicing.astype(float)
)
return scores
# BUGGY call: float voicing passed directly — Raw Pitch Accuracy 71%
def evaluate_buggy(ref_time, ref_freq, ref_voicing_float, est_time, est_freq, est_voicing):
"""BUGGY: ref_voicing is float — nonzero low-confidence frames treated as voiced."""
return mir_eval.melody.evaluate(
ref_time, ref_freq, est_time, est_freq,
ref_voicing=ref_voicing_float, # BUG: float confidence scores
est_voicing=est_voicing
)
# scores['Raw Pitch Accuracy'] = 0.714 — 180,000 spurious frames included
# FIXED call: threshold at 0.5 — Raw Pitch Accuracy 89%
def evaluate_fixed(ref_time, ref_freq, ref_voicing_float, est_time, est_freq, est_voicing):
"""FIXED: binarize at 0.5 before evaluation."""
ref_voicing_bool = (ref_voicing_float >= VOICING_THRESHOLD).astype(float)
# Sanity check: 55–70% voiced frames expected for polyphonic singing corpus
assert 0.50 <= np.mean(ref_voicing_bool) <= 0.75, (
f"Unexpected voiced fraction {np.mean(ref_voicing_bool):.2%}; "
f"check voicing threshold and annotation format"
)
return mir_eval.melody.evaluate(
ref_time, ref_freq, est_time, est_freq,
ref_voicing=ref_voicing_bool, # FIXED: boolean threshold
est_voicing=est_voicing
)
# scores['Raw Pitch Accuracy'] = 0.891 — correct denominator 720,000 frames
Why float voicing is a silent evaluation error that inflates the denominator and deflates reported accuracy
The critical property of mir_eval.melody’s voicing handling is that it uses a greater-than-zero test, not a boolean test. This design decision allows numeric voicing values (which may come from non-binary annotators) to work correctly if they are already binarized at the annotator’s decision threshold. But it creates a silent failure mode when raw probability scores are passed directly: a confidence score of 0.001 (nearly unvoiced, below any sensible threshold) is treated identically to a confidence score of 0.999 (definitely voiced). There is no warning, no TypeError, no ValueError. The evaluation runs to completion and returns a plausible-looking set of numbers. The only observable indicator of the problem is the voiced fraction: a correctly binarized singing voice corpus should show 55–70% voiced frames; the buggy evaluation showed 75% voiced frames (900,000 / 1,200,000). That 5–15 percentage point elevation is subtle enough to be dismissed as a corpus characteristic, particularly in a dataset with many legato melismatic passages. The validate_voicing_array function above catches this by raising when the voiced fraction exceeds 80%. At Westfield MIR Eval Ltd., this check would have fired immediately on the first evaluation: 75% is within the warn-but-not-error range; with an explicit 80% hard limit, the threshold mismatch would have been investigated before the first paper was submitted. The two-step fix — detect float dtype, binarize at threshold, assert voiced fraction range — adds four lines of code and would have saved 14 months of model iteration and three conference submission cycles.
Westfield MIR Eval Ltd.’s retainer engagement was 2.5h: 0.5h triage (request full mir_eval.melody.evaluate call; ref_voicing_float dtype=float64 identified; check voiced fraction at threshold 0: 75% — above expected 60%; check voiced fraction at threshold 0.5: 60% — matches expected; verify: np.sum(ref_voicing_float > 0) = 900,000 vs np.sum(ref_voicing_float ≥ 0.5) = 720,000 — 180,000 extra frames confirmed; re-run evaluation on 50-clip subset with threshold 0.5: Raw Pitch Accuracy 89.3% vs 71.4% — confirmed 18 pp gap); 0.5h root cause (derive correct threshold from MedleyDB annotator documentation: 0.5 is the stated decision boundary; compute voicing recall and false alarm at multiple thresholds: 0.3 → voiced fraction 81% too high; 0.4 → 71%; 0.5 → 60% correct; 0.6 → 51% too low; threshold 0.5 validated against manually binarized held-out set; Spearman correlation 0.98); 1.0h fix (replace ref_voicing=ref_voicing_float with ref_voicing=(ref_voicing_float ≥ 0.5).astype(float); add validate_voicing_array pre-check; add denominator count assertion; re-run full 1,200-clip evaluation: Raw Pitch Accuracy 89.1%; Raw Chroma Accuracy 91.3%; Overall Accuracy 83.2% — above state-of-the-art on this corpus; revise papers); 0.5h validation (cross-check on held-out 100-clip set: 88.7% — consistent within 0.4 pp; resubmit revised paper with corrected evaluation; 2.5h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- pysepm developer on retainer — pysepm 0.1;
composite(clean, noisy, 8000)on 16 kHz wideband; NB PESQ range 0.18 MOS (12 models indistinguishable); WB PESQ 1.54 range; worst model selected; fix:fs=16000; 1.5h - dtaidistance developer on retainer — dtaidistance 2.3.11;
dtw.distance_matrix(series, window=0.05); float window truncated to 0; DTW ≡ Euclidean; AFib clustering 61%; fix:window=int(0.05 × L)=15; 94%; 3.5h - acoustics developer on retainer — acoustics 0.1.0;
t60_impulse(ir, fs)with stereo IR(N, 2); cumsum flattens to 2N; T30 ≈ 2× actual; 32/50 rooms falsely non-compliant; £450,000 abatement; fix:ir[:, 0]; 2.5h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →