Lyric matching treats common words as junk on longer songs (difflib autojunk) #16

Open
opened 2026-10-09 18:19:51 -07:00 by dejima-agent · 1 comment
Collaborator

Filed by LLM agent

match_lyrics in stages/transcribe.py uses difflib.SequenceMatcher with its default autojunk=True. Once a sequence has 200 or more items, difflib treats any token appearing in more than 1% of it as junk. In lyrics those are the most common words ("you", "I", "the", …), and junk tokens can't start a matching block.

As a result, runs of words that Whisper heard correctly come back as replace opcodes instead of equal. On one real song (388 heard tokens against 450 reference tokens), one block had 17 of 18 heard words matching the reference exactly but was still labelled replace. The overall ratio is 0.74 with autojunk and 0.81 without.

All three consumers of the matcher are affected:

  • the similarity check against SIMILARITY_THRESHOLD
  • dropped_lines
  • missing_spans, which are built from delete opcodes

Passing autojunk=False is a one-line change. Expect the similarity ratio and the dropped/missing classification to shift on longer songs, so it's worth checking a few real songs before and after.

**Filed by LLM agent** `match_lyrics` in `stages/transcribe.py` uses `difflib.SequenceMatcher` with its default `autojunk=True`. Once a sequence has 200 or more items, difflib treats any token appearing in more than 1% of it as junk. In lyrics those are the most common words ("you", "I", "the", …), and junk tokens can't start a matching block. As a result, runs of words that Whisper heard correctly come back as `replace` opcodes instead of `equal`. On one real song (388 heard tokens against 450 reference tokens), one block had 17 of 18 heard words matching the reference exactly but was still labelled `replace`. The overall ratio is 0.74 with autojunk and 0.81 without. All three consumers of the matcher are affected: - the similarity check against `SIMILARITY_THRESHOLD` - `dropped_lines` - `missing_spans`, which are built from `delete` opcodes Passing `autojunk=False` is a one-line change. Expect the similarity ratio and the dropped/missing classification to shift on longer songs, so it's worth checking a few real songs before and after.
Author
Collaborator

Comment by LLM agent

Measured on two real songs' transcripts, without running any model. Dropped lines and missing-lyrics spans come from classify_lyrics_match.

song matcher ratio exact-matched words dropped lines missing-lyrics spans
A (63 lines) difflib, autojunk on (current) 0.74 309 none 4 / 34s
A difflib, autojunk off 0.81 340 last line 4 / 43s
A edit distance (rapidfuzz Levenshtein opcodes) 0.81 340 6 lines 7 / 124s
B (52 lines) difflib, autojunk on (current) 0.68 192 8 lines 2 / 38s
B difflib, autojunk off 0.66 187 7 lines 2 / 60s
B edit distance 0.67 188 7 lines, including 3 the current matcher places correctly 8 / 123s

Turning autojunk off gives more exact matches on song A and fewer on song B. On both songs it also makes the line classification no better: song A gains a dropped line and more missing time, and song B gains more missing time. Plain edit distance is clearly worse, because it doesn't favour long runs of consecutive matches and breaks matched lines apart.

Not changing anything for now. A matching change needs a small set of songs with known-correct line placement to judge it against. Two songs without ground truth can't tell an improvement from a regression.

**Comment by LLM agent** Measured on two real songs' transcripts, without running any model. Dropped lines and missing-lyrics spans come from `classify_lyrics_match`. | song | matcher | ratio | exact-matched words | dropped lines | missing-lyrics spans | |---|---|---|---|---|---| | A (63 lines) | difflib, autojunk on (current) | 0.74 | 309 | none | 4 / 34s | | A | difflib, autojunk off | 0.81 | 340 | last line | 4 / 43s | | A | edit distance (`rapidfuzz` Levenshtein opcodes) | 0.81 | 340 | 6 lines | 7 / 124s | | B (52 lines) | difflib, autojunk on (current) | 0.68 | 192 | 8 lines | 2 / 38s | | B | difflib, autojunk off | 0.66 | 187 | 7 lines | 2 / 60s | | B | edit distance | 0.67 | 188 | 7 lines, including 3 the current matcher places correctly | 8 / 123s | Turning autojunk off gives more exact matches on song A and fewer on song B. On both songs it also makes the line classification no better: song A gains a dropped line and more missing time, and song B gains more missing time. Plain edit distance is clearly worse, because it doesn't favour long runs of consecutive matches and breaks matched lines apart. Not changing anything for now. A matching change needs a small set of songs with known-correct line placement to judge it against. Two songs without ground truth can't tell an improvement from a regression.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: branderson/songtrace#16