Skip to content

Add --output-confidence to write the decoder's confidence for each note - #244

Draft
goldnead wants to merge 1 commit into
liebharc:mainfrom
goldnead:konfidenz
Draft

goldnead wants to merge 1 commit into
liebharc:mainfrom
goldnead:konfidenz

Conversation

@goldnead

Copy link
Copy Markdown

Motivation

homr only outputs the decoder's argmax, so downstream tools can't tell a confident note from a guess. A choir rehearsal app uses the decoder's confidence to flag uncertain measures for human review.

What it does

With --output-confidence, each <note> gets a comment next to imgpos, for example:

<!-- conf: r:0.9987:0.9971;p:0.9412:0.8803;l:0.9999:0.9998;a:0.9990:0.9981;s:0.9995:0.9990;o:0.9993:0.9987 -->

One entry per decoder branch: r rhythm, p pitch, l lift, a articulation, s slur/beam, o position. Each entry is branch:probability:margin: the softmax probability of the chosen token and its gap to the second most likely token, both in [0, 1]. A comment (like imgpos) keeps the MusicXML schema-valid. The values describe model certainty and are not calibrated error rates.

Opt-in

The flag sets Config.output_confidence (default off). Without it nothing extra is computed, the output is unchanged, and token selection stays argmax. The decoder only reads logits it already has.

Tests

tests/test_confidence.py runs without model weights and covers the probability/margin helper, no comment without the flag, a parseable comment with values in range with the flag, a mocked decoder session that picks the same tokens with and without confidence, and the CLI flag defaulting to off.

black, isort and ruff pass; the related test files pass (107 tests); mypy reports only the two errors that also exist on main in inference_segnet.py. Not run yet: full make ci (training dependencies) and the Polish scores benchmark from AGENTS.md. The default path is unchanged, so no difference is expected there. That's why this is a draft. Happy to add the benchmark run if you'd like to have it.

AI usage

This was ported and drafted by Claude Code (an AI coding agent) from a patch we already run in production, and the agent ran the checks listed above. A person on our side approved submitting it. Feedback is very welcome, including "please do it differently".

With the flag, every note gets a MusicXML comment next to imgpos, e.g.
<!-- conf: r:0.9987:0.9971;p:0.94:0.88;l:...;a:...;s:...;o:... -->
with the softmax probability of the chosen token and its margin to the
runner-up for each decoder branch. A choir rehearsal app uses this to
flag uncertain measures for review.

The token selection is still the plain argmax and without the flag
nothing is computed or written.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant