feat(dual-track): ground-truth packaging, training diff and import-ultrastar
This commit is contained in:
@ -6,6 +6,7 @@ from unmix.eval.metrics import (
|
||||
evaluate_vocals,
|
||||
extract_text_from_reference,
|
||||
extract_text_from_vocals,
|
||||
generate_training_diff,
|
||||
normalize_text_for_wer,
|
||||
)
|
||||
from unmix.export.ultrastar import UltraStarNote, UltraStarSong
|
||||
@ -134,3 +135,59 @@ def test_evaluate_vocals_octave_error_and_timing_offset():
|
||||
# Median octave offset should be -1.0
|
||||
assert metrics["median_octave_offset"] == pytest.approx(-1.0)
|
||||
assert metrics["wer"] == pytest.approx(0.0)
|
||||
|
||||
|
||||
def test_generate_training_diff():
|
||||
ref_song = UltraStarSong(
|
||||
headers={"BPM": "120", "GAP": "1000"},
|
||||
lines=[
|
||||
[
|
||||
UltraStarNote(":", 0, 4, 0, "First ", start_sec=1.0, end_sec=1.5, midi=60.0),
|
||||
UltraStarNote(":", 4, 4, 2, "Second ", start_sec=1.5, end_sec=2.0, midi=62.0),
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
pred_doc = VocalsDocument(
|
||||
lines=[
|
||||
VocalLine(
|
||||
start=1.02,
|
||||
end=1.52,
|
||||
syllables=[
|
||||
VocalSyllable(text="First", start=1.02, end=1.52, midi=60.0, word_end=True),
|
||||
VocalSyllable(text="Extra", start=5.0, end=5.5, midi=65.0, word_end=True),
|
||||
],
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
diff = generate_training_diff(pred_doc, ref_song)
|
||||
assert "summary" in diff
|
||||
assert "systematic_biases" in diff
|
||||
assert "matched_notes" in diff
|
||||
assert "unmatched_reference_notes" in diff
|
||||
assert "unmatched_predictions" in diff
|
||||
|
||||
# Matched note checks
|
||||
assert len(diff["matched_notes"]) == 1
|
||||
m0 = diff["matched_notes"][0]
|
||||
assert m0["ref_text"] == "First"
|
||||
assert m0["pred_text"] == "First"
|
||||
assert m0["timing_error_ms"] == pytest.approx(20.0, abs=1.0)
|
||||
assert m0["pitch_error_semitones"] == pytest.approx(0.0)
|
||||
|
||||
# Unmatched reference note: "Second" was missed by AI
|
||||
assert len(diff["unmatched_reference_notes"]) == 1
|
||||
assert diff["unmatched_reference_notes"][0]["text"] == "Second"
|
||||
|
||||
# Unmatched prediction: "Extra" was hallucinated / extra
|
||||
assert len(diff["unmatched_predictions"]) == 1
|
||||
assert diff["unmatched_predictions"][0]["text"] == "Extra"
|
||||
|
||||
# Systematic biases
|
||||
biases = diff["systematic_biases"]
|
||||
assert biases["matched_notes_count"] == 1
|
||||
assert biases["unmatched_ref_notes_count"] == 1
|
||||
assert biases["unmatched_predictions_count"] == 1
|
||||
assert biases["mean_timing_bias_ms"] == pytest.approx(20.0, abs=1.0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user