Datasets:
Download evaluation/normalization-guards.mjs from bryel-labs/MuSP-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/datasets/bryel-labs/MuSP-Bench/resolve/main/evaluation/normalization-guards.mjs
- Command line
-
hf download hf://datasets/bryel-labs/MuSP-Bench/evaluation/normalization-guards.mjs
-
curl -L -o normalization-guards.mjs https://huggingface.co/datasets/bryel-labs/MuSP-Bench/resolve/main/evaluation/normalization-guards.mjs
1.78 kB
| // Diagnostic only: do not import this into production evaluation. | |
| // A loss-only experiment isolates false positives caused by the named bugs. | |
| // Existing matches remain necessary: no synonyms or tolerances are added. | |
| import {matchesAcceptedAnswer, stripResponseWrapperResidue} from './answer-normalization.mjs'; | |
| export const numericFormats=new Set([ | |
| 'Positive integer','Signed integer','Integer','Bar number (digits)', | |
| 'Bar number (digits) or NA','Bar range (N-N)','Bar and beat', | |
| 'Beat number (digits)','Beat number (fraction)', | |
| 'Fractional beat number with optional beat prefix','Fraction written as N/N', | |
| 'Count in quarter notes','Count of eighth-note durations','Count and ornamentation', | |
| 'Count followed by note value','Count in number of beats (according to applicable meter)', | |
| 'Ratio','Section label followed by start-bar number','Bar number, yes-or-no', | |
| ]); | |
| export function romanSignature(value){ | |
| return [...stripResponseWrapperResidue(value).normalize('NFKC').matchAll(/(?<![A-Za-z])[#b♯♭]?[IViv]+(?![A-Za-z])/gu)].map(m=>m[0]); | |
| } | |
| export function numberSignature(value){ | |
| return [...stripResponseWrapperResidue(value).normalize('NFKC').matchAll(/[+-]?\d+(?:\.\d+)?/gu)].map(m=>String(Number(m[0]))); | |
| } | |
| export function diagnosticMatch(answer, reference, question, {roman=true,numeric=true}={}){ | |
| if(!matchesAcceptedAnswer(answer,reference,{fullQuestion:question.full_question}))return false; | |
| if(roman&&question.answer_format==='Roman-numeral chord symbol' | |
| &&JSON.stringify(romanSignature(answer))!==JSON.stringify(romanSignature(reference)))return false; | |
| if(numeric&&numericFormats.has(question.answer_format) | |
| &&JSON.stringify(numberSignature(answer))!==JSON.stringify(numberSignature(reference)))return false; | |
| return true; | |
| } | |