Does a learned representation fix the loop detector? Run this and find out #
One question, and it is the only question that decides whether a feature encoder belongs in this app:
Can any of these representations make two frames of different music look different?
Not "which one is best at beat tracking" — beat_this is already within a point of the state of the art
there, and RESEARCH-frontier-loop-points.md §3 explains why the
leaderboard and this problem have diverged. The detector's failure is not a missing feature, it is a
missing difference, and a representation that scores well on a discriminative benchmark while keeping
every frame of a song cosinely adjacent has bought nothing here.
The number the whole thing turns on #
tail — the track's own 98th-percentile score over its candidate lags. It is the comparative half of the
threshold, tau = max(floor, tail), and its job is to represent what a lag scores when nothing is
repeating.
RESEARCH-loops-to-the-beat.md §11 measured it on ten real tracks: 0.955 to 0.998, every time. A threshold whose comparative half reports "everything here repeats" on tracks that do not is not a threshold; the floor was never consulted, and the winner was the shortest lag the search is allowed, which is what a comparison with no resolving power does.
tail(chroma) ≈ 0.99 → tail(X) = ?
The decision rule, in one sentence: if no representation drops the tail materially — call it below
0.90, and --selftest below shows what a representation that can tell frames apart does to it — then
representation is not the lever, the L1 branch closes, and everything after it is ranking, seam and user
labelling.
Procedure #
# 1. the instrument, against two manufactured cases. ~1 second, no downloads.
node --import ./scripts/ssl-bakeoff/ts-load.mjs scripts/ssl-bakeoff/bakeoff.mjs --selftest
# 2. real files. Any sample rate, any format soundfile/torchaudio decodes.
python3 scripts/ssl-bakeoff/dump_ssl.py \
--audio ~/music/track1.flac ~/music/track2.mp3 \
--out /tmp/ssl-bakeoff/dumps --models muq
# 3. the comparison, on the app's own search.
node --import ./scripts/ssl-bakeoff/ts-load.mjs scripts/ssl-bakeoff/bakeoff.mjs \
--dir /tmp/ssl-bakeoff/dumps --fuse
Step 1 matters more than it looks. It builds a "flat" representation — every frame the same vector plus a little noise, which is the §11 finding manufactured — and a "sharp" one, and asserts that the flat one pushes the tail to the top of the scale while the sharp one drops it and still finds a planted loop. It passes today with flat tail 0.965 / sharp tail 0.069, which is the §11 band and its opposite in one line: the instrument separates the thing the report says is unseparable. If it ever prints FAIL, the numbers in step 3 mean nothing, and the fault is in this harness rather than in the model.
ts-load.mjs is what lets the harness import src/lib/player/detect.ts under plain Node. It is not a
shim around the detector: it hooks Node's resolver for the app's extensionless imports and gives
import.meta.env a value, so the same search() that arms a loop in the browser is what scores every
arm. A reimplementation would have been a second detector whose agreement with the first needed its own
calibration — which is the trap scripts/neural-beat/parity.mjs exists to get out of.
What came out of building this (and is now in detect.ts) #
Doing the arithmetic behind the tail turned up a third cause of §11, independent of the representation:
the quantile is not a percentile on a beat grid. Candidate lags run from minPeriodSec to
maxPeriodSec, so how many there are is set by the length of a row:
| measured on | lags | lags above the 0.98 quantile |
|---|---|---|
| frame grid, 4 min @ 46 ms rows | 2435 | 49 |
| beat grid, 4 min @ 0.5 s rows | 225 | 5 |
| beat grid, 30 s clip | 15 | 1 |
So TAIL_QUANTILE = 0.98 on a beat grid means "be among the five best lags", and on a short clip it means
"be the best lag in the file" — while the same music on the frame grid gets a threshold with forty-nine
above it. A body that repeats contributes its period, its double, its triple and the grid neighbours of
each, which is more than five lags scoring near 1.0 by itself, so the tail sits at 0.99+ whatever the
representation is.
detect.ts now has tailLags to floor the quantile by a count. It defaults to 0 — today's behaviour —
and the reason is the most useful thing measured here. Setting it to 12 makes the threshold mean the
same thing on both clocks, and what arrived on the fixtures was §11 reproduced on demand: the
twenty-four-second answer displaced by the shortest period the search is allowed, 4.2 and 4.8 s. Loosening
the threshold without a better representation makes the detector worse, because every short lag that
overlaps a few copies of a flat representation now clears the bar and the ranking cannot clean it up. That
is the experiment's headline result before a single model has been downloaded, and it is why the knob ships
off: it is there to be watched at a console against files whose answers are known, not turned on by
argument.
Arms #
--models takes any of muq, mert, musicfm; --fuse adds a chroma+model arm whose rows are the two
blocks concatenated and normalised, so its cosine is the average of the two cosines — the cheapest hedge
there is, and the one that keeps the app's own feature in the score if the learned one is only marginally
better. Layer choice is --layer and defaults to the second-from-top: for MuQ that is the layer its own
paper used for beat and bar tracking, and the papers are consistent that the early, self-supervised
layers carry the acoustic detail while the fine-tuned top drifts toward semantics (§1.1 of the research
doc). A "musical understanding" embedding is precisely the wrong thing for frame-vs-frame repetition.
Chroma is always the baseline arm, pooled onto the same beat grid by the same code as every other arm, so the difference between arms is the representation and nothing else.
What has not been run, and should not be believed until it is. The TS side (bakeoff.mjs) is tested
against the app's real search() and its self-test passes. The python side is not: no torch, no weights and
no audio were available where it was written, so dump_ssl.py has only been exercised with --dry-run. Its
per-arm model loading follows each library's documented call shape (MuQ via output_hidden_states, MERT via
MertFeatureExtractor, MusicFM via extract_features) and catches failure per arm rather than per track, so
a wrong call loses one arm and prints why instead of losing the run. Expect to reconcile those three calls
with the installed versions on first use; the harness and its numbers are the parts that have been checked.
License, before anything is downloaded #
MuQ and MusicFM checkpoints are research weights under CC-BY-NC-4.0 (non-commercial). This app is MIT.
Measuring with them on your own library is one thing; shipping them is a decision somebody has to make
with the licence text in front of them, which is why this directory is separate from
scripts/neural-beat/ — that one is the worked example of what shipping a model actually takes: MIT
weights, an ONNX export, a hash in a README, and parity tests against the authors' own torch code.
If the answer from step 3 is "yes, and it's worth it", the options in licence order are: train a small convolutional frontend on this app's own labels (MERT's own ablation found a CNN matching its transformer on rhythm tasks — the transformer buys little for repetition and costs a lot in a browser), ship MERT's 95 M variant under its licence with the terms read, or use a permissively-licensed encoder and accept that you are choosing a worse embedding to keep the shipping question off the table.