Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions submissions/bjork-gudmundsdottir-hmm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Transcribe twice, follow with a pitch HMM

Team Björk Guðmundsdóttir (Matthias Nagl, Klaus Lex, Kevin Eberl), Music
Informatics WS26, JKU Linz.

Our third audio score follower. Like our second one
(`bjork-gudmundsdottir-dual`), it turns the audio into notes with two
streaming piano transcribers: a slower one whose notes decide where in the
score the performer is, and a faster one whose notes decide when the next
chord comes. The transcribers and their weights are unchanged. The follower
changes in two places:

1. **Where:** Matchmaker's pitch HMM (`pthmm`) takes the place of the
event-level online time warping.
2. **When:** a fast chord only counts if its pitch fits the score chord it
would move to.

## Why

Both changes come from the validation fold.

- **The time warping runs ahead on repeated chords.** In the Vienna 4x22
excerpt of Chopin's op. 38, which is built from repeated chords, the
event-level online time warping was ahead of the played chord on 15 % of
the chords and never behind, and it reached the end of the score 11
seconds before the pianist did. It only moves forward, so every extra note
of the transcriber can push it on and nothing pulls it back. With the
notes of our transcriber without lookahead it lost 6 validation pieces
over 6 runs (3 training seeds, 2 ways of forming chords). Where we traced
it, it ran ahead within the first seconds and never came back. The pitch
HMM keeps probability on the neighbouring score positions and can move
back. On the same notes it lost 2.
- **The fast layer counted chords without looking at them.** In
`bjork-gudmundsdottir-dual` every fast chord moved the output one score
chord further. A false note of the fast transcriber, or the second half of
a spread chord, then put the output a whole chord too far until the slow
follower caught up. That made the mean error on two of the four Vienna
4x22 validation pieces worse than in our first submission, although the
median was better.

## How it works

1. **Transcription** (`DualProcessor` in `solution.py`, unchanged). One
log-filtered spectrogram (4096-sample window, hop 882, 50 frames per
second) is computed one frame at a time and fed to two networks of our
own transcriber (`transcriber_b/stream.py`, numpy). Both have 5 blocks of
3x3 convolutions, a one-directional GRU with 256 units, and sigmoid heads
for onset, sounding note and offset of the 88 keys (1.5 million
parameters).
- `anchor.npz`: 5 frames of lookahead. A note starts where the onset
activation of a key is at least 0.5, higher than one frame earlier and
at least as high as one frame later, and the key has not started a note
in the last 50 ms. Onsets are final 166 ms after their frame.
- `fast.npz`: no lookahead. The same rule without the condition on the
next frame. Onsets are final 46 ms after their frame.
2. **Following where** (`TranscriptionFollower`). The anchor's onsets within
35 ms of the first note of a chord form one chord. Each chord, as a
vector over the 88 keys, is one observation of the pitch HMM. The HMM is
Matchmaker's `PitchHMM` with its default arguments: one state per score
chord, one inserted state between two chords, the same pitch profiles,
start distribution and transition density.
3. **Banded step** (`banded_pitch_hmm.py`). Matchmaker's step multiplies
with the full transition matrix, so its time grows with the square of the
score length (13 to 16 ms per chord at 3,700 to 4,000 states on our
machine). Ours
does the same arithmetic on the 768 states before and after the current
one. A single transition cannot reach further than that in double
precision, so only probability left over further away from earlier steps
is dropped. On the 20 validation pieces, with the chords of five
different transcriptions (107,070 chords), it ended in the same state as
Matchmaker's step after every chord.
4. **Following when** (`DualFollower`). The fast onsets are grouped into
chords at their first note (35 ms). A fast chord that starts more than
35 ms after the anchor's last chord moves the reported position one score
chord further, if one of its notes has a pitch of that score chord. A
fast chord that does not fit is ignored. When the anchor takes its next
chord, the count starts again from there.
5. **Reported position.** From the last chord (fast or anchor), the position
moves on at the tempo the anchor followed over the last 4 seconds (at most
8 beats per second, for at most 1.5 seconds after the chord), as in
`bjork-gudmundsdottir`.

## Validation fold

One run of the benchmark's own runner on the 20 validation performances for
each of our three submissions:

| | Tracked | Mean of per-piece median beat errors | Mean of per-piece mean beat errors | Within 0.1 beat | Within 0.5 beat |
|---|---|---|---|---|---|
| `bjork-gudmundsdottir` | 20/20 | 0.085 | 0.183 | 0.667 | 0.919 |
| `bjork-gudmundsdottir-dual` | 20/20 | 0.023 | 0.159 | 0.792 | 0.924 |
| this submission | 20/20 | 0.013 | 0.096 | 0.867 | 0.952 |

The mean error is lower than in `bjork-gudmundsdottir` on all 20 pieces and
lower than in `bjork-gudmundsdottir-dual` on 19. Real-time factor about 0.16
(two pieces at a time on a 2-core machine).

What these numbers do not show:

- Both changes were developed on these 20 pieces, after a close look at two
of them, so this is not an unbiased estimate. Neither change has a tuned
setting.
- The pitch HMM fails in its own way: it can fall behind for a while and
come back. One validation piece (`asap/Piano_Sonatas_10-1/Hou02M`) has a
higher mean error than in `bjork-gudmundsdottir-dual` for that reason
(0.145 against 0.095 beats). With other notes than the ones used here it
lost a validation piece like that (with the notes of our first
submission's transcriber, and with one of three training seeds of our
transcriber without lookahead).
- All 6 Batik validation pieces are tracked by all three submissions, so the
validation fold says nothing about Batik.

## What we saw of the evaluation fold

After our first two entries had been evaluated, we read the public
leaderboard, its rows per dataset only. Our entries lose pieces on Batik,
and with the same AMT notes Matchmaker's pitch HMM loses none there while
its Arzt follower does. That was our reason to try the pitch HMM. We did not
open the per-piece evaluation results, and we never ran anything on the
evaluation fold. The choice was made on the validation fold, as described
above. We asked the course organisers before submitting an entry that the
leaderboard prompted, and they agreed.

## Training data

Both networks are the ones of `bjork-gudmundsdottir-dual`, trained by us on
the MAESTRO v3.0.0 train split only. The MAESTRO validation split chose the
checkpoint (best onset F1) and the onset threshold (0.5 for both). ASAP's
audio are MAESTRO recordings: all 42 ASAP recordings of the benchmark folds
(10 valid, 32 eval) are in MAESTRO's test split, listed in
`asap_in_maestro.csv` with their MAESTRO file names. That split was never
prepared or read, and our data preparation stops if any of the 42 appears in
the train or validation split. We used MAESTRO with the agreement of the
course instructor. Batik and Vienna 4x22 are not part of MAESTRO.

## Files

| File | What it is | Licence |
|---|---|---|
| `solution.py` | Processor, both followers and registration | Apache-2.0 |
| `banded_pitch_hmm.py` | Matchmaker's pitch HMM with the banded step | Apache-2.0 |
| `transcriber_b/` | Our transcriber's spectrogram and frame-by-frame numpy network | Apache-2.0 |
| `anchor.npz` | Weights of the network with lookahead, trained by us | CC BY-NC-SA 4.0 |
| `fast.npz` | Weights of the network without lookahead, trained by us | CC BY-NC-SA 4.0 |
| `settings.json` | Both onset thresholds and the weights' sha256 | |
| `asap_in_maestro.csv` | The 42 benchmark recordings in MAESTRO's test split | |
| `requirements.txt` | No dependencies beyond the benchmark environment | |

The weights carry CC BY-NC-SA 4.0 because MAESTRO, their training data, is
licensed under it. `banded_pitch_hmm.py` builds its model with two functions
of `matchmaker.prob.hmm` and follows Matchmaker's `PitchHMM`.

## References

- J. Park, C. Cancino-Chacón, S. Chiruthapudi and J. Nam. Matchmaker: An
open-source library for real-time piano score following and systematic
evaluation. ISMIR 2025. (The pitch HMM `pthmm` and the benchmark.)
- C. Hawthorne et al. Enabling Factorized Piano Music Modeling and Generation
with the MAESTRO Dataset. ICLR 2019.
- C. Hawthorne et al. Onsets and Frames: Dual-Objective Piano Transcription.
ISMIR 2018. (Our sounding-note head also gets the onset probabilities, as
there.)
- R. Kelz, S. Böck and G. Widmer. Deep Polyphonic ADSR Piano Note
Transcription. ICASSP 2019. (The spectrogram features.)
Binary file added submissions/bjork-gudmundsdottir-hmm/anchor.npz
Binary file not shown.
43 changes: 43 additions & 0 deletions submissions/bjork-gudmundsdottir-hmm/asap_in_maestro.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
fold,piece_id,maestro_audio_stem,maestro_split
valid,asap/Piano_Sonatas_10-1/Hou02M,MIDI-Unprocessed_09_R1_2011_MID--AUDIO_R1-D3_13_Track13_wav,test
valid,asap/Prelude_bwv_862/Song04M,MIDI-Unprocessed_13_R1_2008_01-04_ORIG_MID--AUDIO_13_R1_2008_wav--1,test
valid,asap/Prelude_bwv_891/Duepree06M,MIDI-Unprocessed_03_R1_2008_01-04_ORIG_MID--AUDIO_03_R1_2008_wav--1,test
valid,asap/Fugue_bwv_858/VuV01M,MIDI-Unprocessed_R1_D1-1-8_mid--AUDIO-from_mp3_02_R1_2015_wav--1,test
valid,asap/Prelude_bwv_863/LeeN01M,MIDI-Unprocessed_R1_D1-1-8_mid--AUDIO-from_mp3_07_R1_2015_wav--1,test
valid,asap/Piano_Sonatas_5-1/Colafelice02M,MIDI-Unprocessed_23_R1_2011_MID--AUDIO_R1-D9_03_Track03_wav,test
valid,asap/Fugue_bwv_863/Shychko01M,MIDI-Unprocessed_11_R1_2011_MID--AUDIO_R1-D4_07_Track07_wav,test
valid,asap/Transcendental_Etudes_10/CaoJ03M,MIDI-Unprocessed_065_PIANO065_MID--AUDIO-split_07-07-17_Piano-e_3-01_wav--3,test
valid,asap/Prelude_bwv_873/Lisiecki13M,MIDI-Unprocessed_11_R3_2008_01-04_ORIG_MID--AUDIO_11_R3_2008_wav--1,test
valid,asap/Transcendental_Etudes_3/Huang14M,MIDI-Unprocessed_04_R3_2008_01-07_ORIG_MID--AUDIO_04_R3_2008_wav--3,test
eval,asap/Fugue_bwv_858/Zhang01M,MIDI-Unprocessed_07_R1_2011_MID--AUDIO_R1-D3_02_Track02_wav,test
eval,asap/Fugue_bwv_862/Song04M,MIDI-Unprocessed_13_R1_2008_01-04_ORIG_MID--AUDIO_13_R1_2008_wav--1,test
eval,asap/Fugue_bwv_863/LeeN01M,MIDI-Unprocessed_R1_D1-1-8_mid--AUDIO-from_mp3_07_R1_2015_wav--1,test
eval,asap/Fugue_bwv_863/TongB01M,MIDI-Unprocessed_056_PIANO056_MID--AUDIO-split_07-07-17_Piano-e_1-05_wav--1,test
eval,asap/Fugue_bwv_873/Lisiecki13M,MIDI-Unprocessed_11_R3_2008_01-04_ORIG_MID--AUDIO_11_R3_2008_wav--1,test
eval,asap/Fugue_bwv_891/Duepree06M,MIDI-Unprocessed_03_R1_2008_01-04_ORIG_MID--AUDIO_03_R1_2008_wav--1,test
eval,asap/Prelude_bwv_858/VuV01M,MIDI-Unprocessed_R1_D1-1-8_mid--AUDIO-from_mp3_02_R1_2015_wav--1,test
eval,asap/Prelude_bwv_858/Zhang01M,MIDI-Unprocessed_07_R1_2011_MID--AUDIO_R1-D3_02_Track02_wav,test
eval,asap/Prelude_bwv_863/Shychko01M,MIDI-Unprocessed_11_R1_2011_MID--AUDIO_R1-D4_07_Track07_wav,test
eval,asap/Prelude_bwv_863/TongB01M,MIDI-Unprocessed_056_PIANO056_MID--AUDIO-split_07-07-17_Piano-e_1-05_wav--1,test
eval,asap/Prelude_bwv_891/BLINOV04M,MIDI-Unprocessed_XP_03_R1_2004_01-02_ORIG_MID--AUDIO_03_R1_2004_01_Track01_wav,test
eval,asap/Piano_Sonatas_12-1/Kleisen05M,MIDI-Unprocessed_06_R1_2008_01-04_ORIG_MID--AUDIO_06_R1_2008_wav--2,test
eval,asap/Piano_Sonatas_16-1/BuiJL02M,MIDI-Unprocessed_046_PIANO046_MID--AUDIO-split_07-06-17_Piano-e_2-02_wav--2,test
eval,asap/Piano_Sonatas_16-1/Khmara05M,MIDI-Unprocessed_05_R1_2008_01-04_ORIG_MID--AUDIO_05_R1_2008_wav--2,test
eval,asap/Piano_Sonatas_16-1/LeeSH02M,MIDI-Unprocessed_049_PIANO049_MID--AUDIO-split_07-06-17_Piano-e_2-06_wav--2,test
eval,asap/Piano_Sonatas_16-1/Woo05M,MIDI-Unprocessed_17_R1_2008_01-04_ORIG_MID--AUDIO_17_R1_2008_wav--2,test
eval,asap/Piano_Sonatas_18-4/ChenGuang06M,MIDI-UNPROCESSED_04-05_R1_2014_MID--AUDIO_04_R1_2014_wav--2,test
eval,asap/Piano_Sonatas_18-4/KOLESO06M,MIDI-Unprocessed_XP_15_R1_2004_03_ORIG_MID--AUDIO_15_R1_2004_03_Track03_wav,test
eval,asap/Piano_Sonatas_3-2/MiyashitaM04M,MIDI-Unprocessed_R1_D1-9-12_mid--AUDIO-from_mp3_09_R1_2015_wav--2,test
eval,asap/Piano_Sonatas_5-1/SunD02M,MIDI-Unprocessed_R1_D2-13-20_mid--AUDIO-from_mp3_16_R1_2015_wav--2,test
eval,asap/Piano_Sonatas_8-3/Na06M,MIDI-Unprocessed_09_R1_2009_01-04_ORIG_MID--AUDIO_09_R1_2009_09_R1_2009_03_WAV,test
eval,asap/Piano_Sonatas_9-3/Tysman05M,MIDI-Unprocessed_17_R1_2009_01-03_ORIG_MID--AUDIO_17_R1_2009_17_R1_2009_01_WAV,test
eval,asap/Etudes_op_10_12/Bult-ItoS04M,MIDI-Unprocessed_R1_D1-1-8_mid--AUDIO-from_mp3_05_R1_2015_wav--4,test
eval,asap/Etudes_op_10_12/HuNY03M,MIDI-Unprocessed_R1_D2-21-22_mid--AUDIO-from_mp3_22_R1_2015_wav--3,test
eval,asap/Etudes_op_10_12/LuoJ08M,MIDI-Unprocessed_R1_D1-1-8_mid--AUDIO-from_mp3_06_R1_2015_wav--6,test
eval,asap/Etudes_op_10_12/WuuE06M,MIDI-Unprocessed_R1_D1-9-12_mid--AUDIO-from_mp3_11_R1_2015_wav--3,test
eval,asap/Etudes_op_10_12/ZhangYunling02M,MIDI-Unprocessed_07_R1_2011_MID--AUDIO_R1-D3_03_Track03_wav,test
eval,asap/Transcendental_Etudes_10/Huang17M,MIDI-Unprocessed_04_R3_2008_01-07_ORIG_MID--AUDIO_04_R3_2008_wav--6,test
eval,asap/Transcendental_Etudes_10/LeungM06M,MIDI-Unprocessed_Recital17-19_MID--AUDIO_19_R1_2018_wav--3,test
eval,asap/Preludes_op_23_6/Nikiforov14M,MIDI-Unprocessed_12_R3_2008_01-04_ORIG_MID--AUDIO_12_R3_2008_wav--3,test
eval,asap/Toccata/DupreeF13M,MIDI-UNPROCESSED_19-20_R1_2014_MID--AUDIO_19_R1_2014_wav--8,test
eval,asap/Toccata_repeat/WangY07M,MIDI-UNPROCESSED_11-13_R1_2014_MID--AUDIO_13_R1_2014_wav--4,test
102 changes: 102 additions & 0 deletions submissions/bjork-gudmundsdottir-hmm/banded_pitch_hmm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""Matchmaker's PitchHMM (the MIDI method `pthmm`) with a forward step whose cost does not grow with the score.

The model is the one `matchmaker.prob.PitchHMM` builds with its default
arguments (`has_insertions=True`, `piano_range=True`):

- States: one per score chord and one "inserted" state between two chords,
at the position halfway between them.
- Observation: a chord as a vector over the 88 keys. Its probability in a
state is the product over the keys of p (key played) or 1 - p (not
played), with the pitch profiles of
`matchmaker.prob.hmm.compute_discrete_pitch_profiles`.
- Transition from state i: a left-skewed Gumbel density (scale 1) over the
target state, with its mode two states further for a chord state and one
state further for an inserted state, so always at the next chord. Every
row is divided by its sum over all states. The density is exactly zero in
double precision from 7 states past the mode on, and from about 745 states
before it.
- Start: `matchmaker.prob.hmm.init_dist`.

Matchmaker's step multiplies the forward variable with the full transition
matrix (number of states squared) and evaluates the observation in every
state. This step does the same arithmetic on the states within REACH of the
current one and leaves the others at zero. REACH is above the 745 states a
single transition can reach at all, so the only thing dropped is probability
left over further away than that from earlier steps. The memory is one block
of (2 REACH + 1) squared numbers per parity of the window start instead of
the full matrix.

We compared the state after every chord with Matchmaker's PitchHMM on the 20
validation pieces, with the chords of five different transcriptions
(107,070 chords): never a different state, forward variables equal to 8e-16.
"""

import numpy as np
from matchmaker.prob.hmm import compute_discrete_pitch_profiles, init_dist
from scipy.stats import gumbel_l

REACH = 768 # states on each side of the current one that a step uses
LEFT, RIGHT = 760, 8 # the transition density is exactly zero outside these offsets from its mode
NORMALISER_FLOOR = 1e-6 # as in hiddenmarkov.forward_algorithm_step


class BandedPitchHMM:
def __init__(self, score_note_array):
# as PitchHMM._build_hmm_modules
onsets = np.unique(score_note_array["onset_beat"])
chord_pitches = [score_note_array["pitch"][score_note_array["onset_beat"] == onset] for onset in onsets]
self.profiles = compute_discrete_pitch_profiles(chord_pitches=chord_pitches, piano_range=True, inserted_states=True)
self.score_positions = np.insert(onsets, np.arange(1, len(onsets)), onsets[:-1] + 0.5 * np.diff(onsets))
n = self.n_states = len(self.score_positions)
self.initial = init_dist(n_states=n, dist=gumbel_l)

# Row i of Matchmaker's stable_transition_matrix(scale=1.0, inserted_states=True) is
# gumbel_l.pdf(j, loc=i + 2) for even i and gumbel_l.pdf(j, loc=i + 1) for odd i, over
# the target states j = 0 .. n - 1, divided by its sum.
offsets = np.arange(-LEFT, RIGHT + 1)
self.kernel = gumbel_l.pdf(offsets, loc=0, scale=1.0)
if self.kernel[0] != 0.0 or self.kernel[-1] != 0.0:
raise RuntimeError("the transition density is not zero at the edges of the kernel")
shift = np.where(np.arange(n) % 2 == 0, 2, 1) # mode of row i is i + shift[i]
mode = np.arange(n) + shift
cumulative = np.concatenate(([0.0], np.cumsum(self.kernel)))
first = np.clip(-mode, -LEFT, RIGHT + 1) # offset of target state 0
last = np.clip(n - 1 - mode, -LEFT - 1, RIGHT) # offset of target state n - 1
self.row_scale = 1.0 / (cumulative[last + LEFT + 1] - cumulative[first + LEFT])

# blocks[p][a, b]: density of the step from state lo + a to state lo + b, for lo of parity p
width = min(2 * REACH + 1, n)
a, b = np.arange(width)[:, None], np.arange(width)[None, :]
self.blocks = []
for parity in (0, 1):
offset = b - a - np.where((a + parity) % 2 == 0, 2, 1)
inside = (offset >= -LEFT) & (offset <= RIGHT)
self.blocks.append(np.where(inside, self.kernel[np.clip(offset, -LEFT, RIGHT) + LEFT], 0.0))

self.forward = None
self.current_index = 0

def _observation(self, vector, lo, hi):
"""Probability of the chord in the states lo .. hi - 1, as compute_bernoulli_pitch_probabilities."""
profiles = self.profiles[lo:hi]
return np.prod(np.where(vector > 0, profiles, 1.0 - profiles), axis=1)

def step(self, vector):
"""One chord (88 keys, 1 where a note starts). Sets current_index to the most likely state."""
vector = np.asarray(vector)
n = self.n_states
if self.forward is None:
lo, hi = 0, min(n, 2 * REACH + 1) # the start distribution is zero from about state 70 on
prior = self.initial[lo:hi]
else:
lo, hi = max(0, self.current_index - REACH), min(n, self.current_index + REACH + 1)
source = self.forward[lo:hi] * self.row_scale[lo:hi]
prior = np.dot(self.blocks[lo % 2][: hi - lo, : hi - lo].T, source)
updated = self._observation(vector, lo, hi) * prior
updated /= max(updated.sum(), NORMALISER_FLOOR)
self.forward = np.zeros(n)
self.forward[lo:hi] = updated
self.current_index = lo + int(np.argmax(updated))

def get_current_position(self):
return float(self.score_positions[self.current_index])
Binary file added submissions/bjork-gudmundsdottir-hmm/fast.npz
Binary file not shown.
Loading
Loading