File size: 3,369 Bytes
527b696
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/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,
  ),
);