| #!/usr/bin/env node |
|
|
| import assert from "node:assert/strict"; |
| import { readFile } from "node:fs/promises"; |
|
|
| const publication = JSON.parse( |
| await readFile(new URL("./raw/full-results.json", import.meta.url), "utf8"), |
| ); |
|
|
| assert.equal(publication.schema_version, 1); |
| assert.equal(publication.runs.length, 4); |
| assert.equal(publication.engine_summaries.length, 2); |
|
|
| const expectedManifest = publication.manifest_sha256; |
| const runsByEngine = new Map(); |
|
|
| for (const run of publication.runs) { |
| assert.equal(run.manifest_sha256, expectedManifest); |
| assert.equal(run.paced_in_real_time, true); |
| assert.equal(run.summary.requested_clips, 40); |
| assert.equal(run.summary.successful_clips, 40); |
| assert.equal(run.summary.failed_clips, 0); |
| assert.equal(run.clips.length, 40); |
|
|
| const aggregates = run.clips.reduce( |
| (total, clip) => { |
| assert.ok(clip.score, `${run.run_id}/${clip.id} has no score`); |
| total.referenceWords += clip.score.reference_words; |
| total.wordErrors += |
| clip.score.word_edits.substitutions |
| + clip.score.word_edits.insertions |
| + clip.score.word_edits.deletions; |
| total.referenceCharacters += clip.score.reference_characters; |
| total.characterErrors += |
| clip.score.character_edits.substitutions |
| + clip.score.character_edits.insertions |
| + clip.score.character_edits.deletions; |
| return total; |
| }, |
| { |
| referenceWords: 0, |
| wordErrors: 0, |
| referenceCharacters: 0, |
| characterErrors: 0, |
| }, |
| ); |
|
|
| const recomputedWER = aggregates.wordErrors / aggregates.referenceWords; |
| const recomputedCER = |
| aggregates.characterErrors / aggregates.referenceCharacters; |
| assert.equal( |
| recomputedWER, |
| run.summary.aggregate_score.word_error_rate, |
| `${run.run_id} WER differs from its clip rows`, |
| ); |
| assert.equal( |
| recomputedCER, |
| run.summary.aggregate_score.character_error_rate, |
| `${run.run_id} CER differs from its clip rows`, |
| ); |
|
|
| const engineRuns = runsByEngine.get(run.engine.id) ?? []; |
| engineRuns.push({ |
| runId: run.run_id, |
| werPercent: Number((recomputedWER * 100).toFixed(2)), |
| cerPercent: Number((recomputedCER * 100).toFixed(2)), |
| medianMS: run.summary.post_speech_latency.median_ms, |
| p95MS: run.summary.post_speech_latency.p95_ms, |
| }); |
| runsByEngine.set(run.engine.id, engineRuns); |
| } |
|
|
| for (const summary of publication.engine_summaries) { |
| const runs = runsByEngine.get(summary.engine_id); |
| assert.equal(runs?.length, summary.run_count); |
| assert.ok( |
| runs.every( |
| ({ werPercent }) => |
| werPercent === summary.word_error_rate_percent, |
| ), |
| ); |
| assert.ok( |
| runs.every( |
| ({ cerPercent }) => |
| cerPercent === summary.character_error_rate_percent, |
| ), |
| ); |
| assert.deepEqual( |
| [ |
| Math.min(...runs.map(({ medianMS }) => medianMS)), |
| Math.max(...runs.map(({ medianMS }) => medianMS)), |
| ], |
| summary.post_speech_latency_median_ms_range, |
| ); |
| assert.deepEqual( |
| [ |
| Math.min(...runs.map(({ p95MS }) => p95MS)), |
| Math.max(...runs.map(({ p95MS }) => p95MS)), |
| ], |
| summary.post_speech_latency_p95_ms_range, |
| ); |
| } |
|
|
| console.log( |
| JSON.stringify( |
| { |
| verified: true, |
| source_commit: publication.source_commit, |
| manifest_sha256: expectedManifest, |
| runs: Object.fromEntries(runsByEngine), |
| }, |
| null, |
| 2, |
| ), |
| ); |
|
|