Skip to content

feat(benchmark): score translation with chrF and report its latency - #482

Open
Goldloli wants to merge 1 commit into
QuentinFuxa:mainfrom
Goldloli:feat/477-translation-chrf-benchmark
Open

Goldloli wants to merge 1 commit into
QuentinFuxa:mainfrom
Goldloli:feat/477-translation-chrf-benchmark

Conversation

@Goldloli

Copy link
Copy Markdown

Refs #477

Summary

The suite can already run a translation but could not judge one: there was no translation quality metric anywhere, rows carried no translation reference, and the timings that describe what a reader actually saw were missing. This adds those three, following the acceptance criteria in the issue and the follow-ups in your comment on it.

  • whisperlivekit/benchmark/chrf.py: chrF per row and per language pair. Character n-gram order 6, word n-gram order 0, beta 2, whitespace removed, effective-order smoothing — sacrebleu's definition. The pair figure is computed from the summed [hypothesis, reference, match] counts over the rows of that pair, not from a mean of row scores, which is biased toward short rows. Empty inputs are distinguished: a reference with an empty hypothesis is a 0% measurement, while a row with no reference is unscored (chrf: null).
  • Manifest join in load_manifest(..., target_language=...): references come from the row of the same sentence_id in the target language. The manifest file and its hashes are only read, so fleurs-90.json stays byte-identical (asserted in a test). A row that already speaks the target language is left unscored instead of being scored against itself.
  • final_translation_time_s is the complete validated translation measured from feed start. provisional_lead_s is null unless the MT backend actually drafts: the harness flags a draft the first time buffer_translation is non-empty, so a backend that publishes only committed translations is not credited with a lead it does not have. The measurement comes from the FrontData snapshots the harness already sees, so it does not depend on feat: caption event stream for display consumers #449.
  • Schema 3.2: translation.config records the target language, backend, model and simultaneous-MT settings next to the ASR backend and model, as benchmarks/README.md asks. The terminal summary gains a chrF column per row and a corpus chrF line per language pair; --transcriptions also prints the translation reference and hypothesis.

sacrebleu is not added as a runtime dependency. The implementation is checked against three values (including a Mandarin case) plus a corpus figure computed once with sacrebleu 2.6.0 and pinned in the test.

User impact

  • New fields in the JSON report and new lines in the terminal summary; benchmark schema goes 3.1 → 3.2. Existing reports in benchmarks/evaluations/ are untouched and are not compared with 3.2 runs.
  • ASR-only runs print no chrF column and write an empty translation.config, so their output is unchanged apart from the schema number.
  • The manifest on disk and its hashes are unchanged; the join is load-time only.
  • Documentation updated in benchmarks/README.md, including the command line for an audio-to-translation run.

Validation

Implementation compared against sacrebleu.CHRF() 2.6.0 (char order 6, word order 0, beta 2, whitespace=False, default effective-order smoothing):

case implementation sacrebleu
the cat sat on a mat / the cat sat on the mat 65.97965990995549 65.97965990995549
hello world this is test / hello world, this is a test. 62.004049534810605 62.004049534810605
Mandarin row from fleurs-90.json (en_1682) with punctuation restored 80.02777735753219 80.02777735753219
the three rows above as one corpus 72.35151511816518 72.35151511816518

Fuzz comparison, 196 non-empty randomized pairs over mixed Latin/CJK/punctuation text: every per-row value matched to 1e-9, and a 30-row corpus figure matched too.

End-to-end run through the real BenchmarkRunner._run_sample code with a fake harness standing in only for the model (so the audio hashing, timing capture, scoring and report paths are the real ones), on a synthetic 3-row parallel manifest whose French rows share the English sentence_id:

version 3.2
translation config {'target_language': 'fr', 'translation_backend': 'alignatt'}
scored rows 1                     # the fr->fr row is left unscored
corpus {'en': {'corpus_chrf': 100.0, 'n_rows': 1}}
per-row chrf [100.0, None, None]  # en_2 has no parallel reference
final translation [0.4013, 0.4014, 0.4012]
lead [0.4014, None, None]

wlk bench --manifest benchmarks/corpora/fleurs-90.json --config translation.json --languages en parses and runs to completion through the real CLI path (the audio files themselves are not cached on this machine, so the samples report FileNotFoundError; the manifest, join and report paths above are exercised directly).

Test suite (uv-managed optional dependencies not installed on this machine):

python -m pytest -q tests/ --ignore=tests/test_pipeline.py --ignore=tests/test_asr_coalescing_pipeline.py
  351 passed, 20 skipped, 6 failed

The 6 failures are tests/test_deepgram_compat.py (needs deepgram-sdk) and tests/test_qwen3_backend_shims.py (needs the qwen3 backends); they fail identically on unmodified main in this environment, verified by stashing the change and re-running those files. New tests: 23 pass (19 in the two new files, plus the existing tests/test_benchmark.py unchanged and green).

Not run: real model ASR/MT passes (tests/test_pipeline.py, tests/test_asr_coalescing_pipeline.py), which download Whisper and load NLLB/AlignAtt; no GPU or MLX backend on this machine. The chrF path and the latency plumbing are model-independent and are covered without them, but the first real audio-to-translation report still needs a machine with a backend and a sidecar.

python -m ruff check . — All checks passed.

Checklist

  • I searched for an existing issue or discussion and linked it when relevant.
  • I added or updated tests for behavior changes.
  • I updated documentation for user-facing changes.
  • I ran ruff check ..
  • I ran the relevant pytest suite.
  • I did not commit credentials, model weights, generated caches, or private data.

The benchmark suite could run a translation but not judge it: no quality
metric existed, no row carried a translation reference, and the two
timestamps that describe what the reader saw were not recorded.

- chrF per row and per language pair, using sacrebleu's definition (char
  order 6, word order 0, beta 2, whitespace removed) and its effective-order
  smoothing. The pair figure is computed from the summed [hyp, ref, match]
  statistics, not from a mean of row scores, because a mean over-weights
  short rows. Inputs can be empty: a reference with an empty hypothesis is a
  0% measurement, a row with no reference is unscored (`chrf: null`).
- The parallel-corpus join happens when the manifest is loaded, keyed on
  `sentence_id`, so `fleurs-90.json` and its hashes stay unchanged. Rows that
  already speak the target language are left unscored rather than scored
  against themselves.
- `final_translation_time_s` records when the complete validated translation
  landed after feed start. `provisional_lead_s` is null unless the MT backend
  actually drafts over the unstable ASR tail, so a backend that publishes only
  committed translations is not credited with a lead it does not have.
- Schema 3.2 records the MT configuration (target language, backend, model,
  simultaneous-MT settings) next to the ASR backend and model, and prints the
  corpus chrF per language pair in the terminal summary.

sacrebleu is not a runtime dependency: the implementation is checked against
values computed once with sacrebleu 2.6.0 and pinned in the tests.

This branch has not been deployed

No deployments
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