Datasets:
Benchmark results, method, limitations and the failure log
Browse files- README.md +154 -0
- docs/FAILURES.md +253 -0
- docs/LIMITATIONS.md +64 -0
- docs/METHOD.md +92 -0
- hypotheses/hyp_b1n1yam__shook-medium-amharic-2k.json +0 -0
- hypotheses/hyp_b1n1yam__shook-tiny-amharic-stage2-polish.json +0 -0
- hypotheses/hyp_badrex__Ethio-ASR-amharic.json +0 -0
- hypotheses/hyp_badrex__Ethio-ASR-multilingual-1B.json +0 -0
- hypotheses/hyp_badrex__Ethio-ASR-multilingual-600M.json +0 -0
- results/bootstrap.json +69 -0
- results/phase1_greedy.json +43 -0
- scripts/README.md +18 -0
- scripts/bench_asr.py +243 -0
- scripts/bench_lm.py +293 -0
- scripts/bootstrap_ci.py +89 -0
- scripts/geez_eval.py +134 -0
README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
language:
|
| 4 |
+
- am
|
| 5 |
+
task_categories:
|
| 6 |
+
- automatic-speech-recognition
|
| 7 |
+
pretty_name: Amharic ASR Benchmark
|
| 8 |
+
size_categories:
|
| 9 |
+
- 1K<n<10K
|
| 10 |
+
tags:
|
| 11 |
+
- amharic
|
| 12 |
+
- ethiopia
|
| 13 |
+
- benchmark
|
| 14 |
+
- evaluation
|
| 15 |
+
- low-resource
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# Amharic ASR Benchmark
|
| 19 |
+
|
| 20 |
+
An evaluation of open speech recognition models for Amharic, on a test set that
|
| 21 |
+
**none of them could have trained on**, with certain labels and honest
|
| 22 |
+
statistics.
|
| 23 |
+
|
| 24 |
+
Published by [Dataset.ET](https://dataset.et).
|
| 25 |
+
|
| 26 |
+
## Results
|
| 27 |
+
|
| 28 |
+
1,548 clips, 4.72 hours. Greedy decoding.
|
| 29 |
+
Character error rate, lower is better.
|
| 30 |
+
|
| 31 |
+
| model | CER | 95% CI | WER | |
|
| 32 |
+
|---|---|---|---|---|
|
| 33 |
+
| [`badrex/Ethio-ASR-amharic`](https://huggingface.co/badrex/Ethio-ASR-amharic) | **0.0946** | [0.0896, 0.0999] | 0.2845 | CTC, monolingual Amharic |
|
| 34 |
+
| [`badrex/Ethio-ASR-multilingual-600M`](https://huggingface.co/badrex/Ethio-ASR-multilingual-600M) | **0.0991** | [0.0939, 0.1042] | 0.2984 | CTC, w2v-BERT 2.0, five Ethiopian languages |
|
| 35 |
+
| [`b1n1yam/shook-medium-amharic-2k`](https://huggingface.co/b1n1yam/shook-medium-amharic-2k) | **0.1147** | [0.1087, 0.1202] | 0.2943 | Seq2seq, Whisper medium |
|
| 36 |
+
| [`badrex/Ethio-ASR-multilingual-1B`](https://huggingface.co/badrex/Ethio-ASR-multilingual-1B) | **0.1308** | [0.1249, 0.1366] | 0.3894 | CTC, MMS-based |
|
| 37 |
+
| [`b1n1yam/shook-tiny-amharic-stage2-polish`](https://huggingface.co/b1n1yam/shook-tiny-amharic-stage2-polish) | **0.2735** | [0.2648, 0.2820] | 0.6200 | Seq2seq, 37.8M parameters |
|
| 38 |
+
|
| 39 |
+
### Are the differences real?
|
| 40 |
+
|
| 41 |
+
Every model is scored on the **same 1,548 clips**, so comparing
|
| 42 |
+
marginal confidence intervals is the wrong test — they can overlap while the
|
| 43 |
+
difference is real. A paired bootstrap over 2,000
|
| 44 |
+
resamples of clips:
|
| 45 |
+
|
| 46 |
+
| comparison | mean CER difference | 95% CI | distinguishable |
|
| 47 |
+
|---|---|---|---|
|
| 48 |
+
| `Ethio-ASR-amharic` vs `Ethio-ASR-multilingual-600M` | -0.0045 | [-0.0067, -0.0022] | **yes** |
|
| 49 |
+
| `Ethio-ASR-multilingual-600M` vs `shook-medium-amharic-2k` | -0.0155 | [-0.0194, -0.0120] | **yes** |
|
| 50 |
+
| `shook-medium-amharic-2k` vs `Ethio-ASR-multilingual-1B` | -0.0161 | [-0.0202, -0.0120] | **yes** |
|
| 51 |
+
| `Ethio-ASR-multilingual-1B` vs `shook-tiny-amharic-stage2-polish` | -0.1427 | [-0.1498, -0.1361] | **yes** |
|
| 52 |
+
|
| 53 |
+
The top two intervals overlap and the difference is still real at p = 0.001.
|
| 54 |
+
Every adjacent pair here is separable.
|
| 55 |
+
|
| 56 |
+
## What makes this worth trusting
|
| 57 |
+
|
| 58 |
+
**The labels are certain.** A contributor was shown a sentence and read it
|
| 59 |
+
aloud, so the reference existed before the audio. Most speech benchmarks score
|
| 60 |
+
against transcripts someone typed while listening, which carries an unmeasured
|
| 61 |
+
error rate of its own.
|
| 62 |
+
|
| 63 |
+
**No model could have seen it.** Every model predates the test set by five to
|
| 64 |
+
nine months, verified against publication timestamps:
|
| 65 |
+
|
| 66 |
+
| asset | published |
|
| 67 |
+
|---|---|
|
| 68 |
+
| **this test set** | **2026-08-25** |
|
| 69 |
+
| `badrex/Ethio-ASR-*` | 2026-03-24 |
|
| 70 |
+
| `b1n1yam/shook-medium-amharic-2k` | 2025-12-08 |
|
| 71 |
+
| `b1n1yam/shook-tiny-*` | 2025-11-21 |
|
| 72 |
+
|
| 73 |
+
**Speaker-disjoint splits.** No voice appears in more than one split.
|
| 74 |
+
|
| 75 |
+
**The outputs are published.** `hypotheses/` holds every model's raw transcript
|
| 76 |
+
for all 1,548 clips. Do not trust these numbers — recompute them.
|
| 77 |
+
|
| 78 |
+
## Three findings worth stating
|
| 79 |
+
|
| 80 |
+
**The 600M model beats the 1B by 24% relative, at 40% of the size.** Larger is
|
| 81 |
+
not better within this family. We had been building on the 1B.
|
| 82 |
+
|
| 83 |
+
**A monolingual model narrowly beats the multilingual one** for Amharic
|
| 84 |
+
specifically: 0.0946 against 0.0991, a real difference. Multilingual training
|
| 85 |
+
costs a little here rather than helping.
|
| 86 |
+
|
| 87 |
+
**CER and WER disagree about ranking.** `shook-medium-amharic-2k` has worse CER
|
| 88 |
+
than `Ethio-ASR-multilingual-600M` (0.1147 vs 0.0991) but better WER
|
| 89 |
+
(0.2943 vs 0.2984). The sequence-to-sequence model produces fluent whole words
|
| 90 |
+
that match exactly; the CTC model gets characters closer but whole words
|
| 91 |
+
slightly off. For an agglutinative language written in Ge'ez script, which
|
| 92 |
+
metric you choose changes who wins.
|
| 93 |
+
|
| 94 |
+
## Read this before quoting anything
|
| 95 |
+
|
| 96 |
+
This is **one domain**: people reading prompts into a phone. On spontaneous
|
| 97 |
+
speech the same models are far worse — we measured roughly three times the
|
| 98 |
+
disagreement between them on podcast audio. These are not general Amharic ASR
|
| 99 |
+
figures. See [`docs/LIMITATIONS.md`](docs/LIMITATIONS.md).
|
| 100 |
+
|
| 101 |
+
Decoding is greedy, so every number is a lower bound, and that penalty is **not
|
| 102 |
+
evenly distributed** between CTC and sequence-to-sequence models.
|
| 103 |
+
|
| 104 |
+
## What went wrong
|
| 105 |
+
|
| 106 |
+
[`docs/FAILURES.md`](docs/FAILURES.md) is the honest engineering log: ten
|
| 107 |
+
failures including three that produced results which looked correct, a health
|
| 108 |
+
check that reported a working system as broken, and a shutdown timer we
|
| 109 |
+
triggered by trying to disable it.
|
| 110 |
+
|
| 111 |
+
It is the most useful document here. Benchmarks are usually published as though
|
| 112 |
+
they fell out of the sky.
|
| 113 |
+
|
| 114 |
+
## Contents
|
| 115 |
+
|
| 116 |
+
```
|
| 117 |
+
README.md this
|
| 118 |
+
docs/METHOD.md test set, scoring, statistics
|
| 119 |
+
docs/FAILURES.md what went wrong and what it cost
|
| 120 |
+
docs/LIMITATIONS.md read before quoting
|
| 121 |
+
results/phase1_greedy.json the numbers
|
| 122 |
+
results/bootstrap.json intervals and paired tests
|
| 123 |
+
hypotheses/ every model's raw output, per clip
|
| 124 |
+
scripts/ the evaluation code
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
## Reproducing
|
| 128 |
+
|
| 129 |
+
```bash
|
| 130 |
+
python scripts/bench_asr.py --push-to <your-repo>
|
| 131 |
+
python scripts/bootstrap_ci.py build/am-v0.2.0 hypotheses/
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
The test set is [`snapwre/amharic-speech`](https://huggingface.co/datasets/snapwre/amharic-speech),
|
| 135 |
+
open under CC BY 4.0.
|
| 136 |
+
|
| 137 |
+
## Citing
|
| 138 |
+
|
| 139 |
+
```bibtex
|
| 140 |
+
@misc{datasetet2026amharicasr,
|
| 141 |
+
title = {Amharic ASR Benchmark: an uncontaminated evaluation of open speech models},
|
| 142 |
+
author = {Dataset.ET},
|
| 143 |
+
year = {2026},
|
| 144 |
+
url = {https://huggingface.co/datasets/snapwre/amharic-asr-benchmark}
|
| 145 |
+
}
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
## Contact
|
| 149 |
+
|
| 150 |
+
Corrections and additional models are welcome — open a discussion. If you built
|
| 151 |
+
one of these models and think a decoding choice disadvantaged it, say so and we
|
| 152 |
+
will rerun it.
|
| 153 |
+
|
| 154 |
+
Chapi, Dataset.ET
|
docs/FAILURES.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# What went wrong
|
| 2 |
+
|
| 3 |
+
Benchmarks are published as though they fell out of the sky. This one took four
|
| 4 |
+
days, and most of that was spent being wrong in ways worth writing down. Every
|
| 5 |
+
failure below is one we actually hit, in the order we hit it, with what it cost
|
| 6 |
+
and what fixed it.
|
| 7 |
+
|
| 8 |
+
The reason to publish this is not confession. It is that **three of these bugs
|
| 9 |
+
produced results that looked correct**, and the only thing that caught them was
|
| 10 |
+
a diagnostic we nearly did not run.
|
| 11 |
+
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
## 1. The experiment that passed and was worthless
|
| 15 |
+
|
| 16 |
+
Before benchmarking anything we ran a calibration experiment: do two ASR models
|
| 17 |
+
agreeing tell you the transcript is right? It reported GO. It was invalid, and
|
| 18 |
+
for three separate reasons at once.
|
| 19 |
+
|
| 20 |
+
**The decode limit truncated one model.** Whisper was generated with
|
| 21 |
+
`max_new_tokens=200`. On long clips it simply stopped mid-sentence. 139 of 500
|
| 22 |
+
clips were affected and the model was charged for words it was never allowed to
|
| 23 |
+
emit.
|
| 24 |
+
|
| 25 |
+
**A language tag was scored as text.** One model does joint recognition and
|
| 26 |
+
language identification, so it prefixes `[AMH]`. That tag was compared against
|
| 27 |
+
the reference as though it were speech. 290 of 500 outputs carried one. The
|
| 28 |
+
model was penalised for doing the second job it was designed to do.
|
| 29 |
+
|
| 30 |
+
**The disagreement metric was asymmetric.** Character error rate divides by the
|
| 31 |
+
reference length, and we passed one model's output as the reference. Twenty
|
| 32 |
+
clips scored above 1.0, which is impossible for a symmetric disagreement.
|
| 33 |
+
|
| 34 |
+
**How we caught it.** Not from the headline number, which looked fine. From a
|
| 35 |
+
diagnostic printed beside it: rank correlation between agreement and each
|
| 36 |
+
model's true error. It came out **0.935 against one model and 0.087 against the
|
| 37 |
+
other**. If agreement were measuring mutual corroboration those would be
|
| 38 |
+
similar. They were not, so agreement was tracking one model's failures.
|
| 39 |
+
|
| 40 |
+
> A single summary number cannot tell you it is wrong. Print the diagnostic that
|
| 41 |
+
> would look different if your assumption failed, and print it every run.
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## 2. The same truncation bug, reintroduced two days later
|
| 46 |
+
|
| 47 |
+
We fixed the 200-token limit in the calibration script. Then we wrote a new
|
| 48 |
+
benchmark script, and typed `max_new_tokens=200` into it.
|
| 49 |
+
|
| 50 |
+
It gave `shook-medium-amharic-2k` a CER of **0.3107**. The true figure is
|
| 51 |
+
**0.1147**. We nearly published a number that made a good model look broken.
|
| 52 |
+
|
| 53 |
+
**How we caught it.** Output length against reference length, bucketed:
|
| 54 |
+
|
| 55 |
+
| reference length | Whisper output / reference | CTC output / reference |
|
| 56 |
+
|---|---|---|
|
| 57 |
+
| 0-60 chars | 0.96x | 1.08x |
|
| 58 |
+
| 60-90 | 0.95x | 1.03x |
|
| 59 |
+
| 90-120 | 0.80x | 1.01x |
|
| 60 |
+
| 120-160 | 0.63x | 1.00x |
|
| 61 |
+
| 160+ | **0.46x** | 0.96x |
|
| 62 |
+
|
| 63 |
+
A model that is merely *wrong* is wrong at all lengths. A model that is
|
| 64 |
+
**truncated** degrades as length grows. The CTC column is the control that makes
|
| 65 |
+
it unambiguous.
|
| 66 |
+
|
| 67 |
+
> Fixing a bug in one file does not fix it in your head. The check that catches
|
| 68 |
+
> a class of bug belongs in the pipeline, not in your memory.
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
## 3. A working system reported as broken
|
| 73 |
+
|
| 74 |
+
Our health check for the language model toolchain was:
|
| 75 |
+
|
| 76 |
+
```bash
|
| 77 |
+
lmplz --help > /dev/null 2>&1 && echo "ok" || echo "MISSING"
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
**`lmplz --help` exits with status 1.** Many C++ tools print usage to stderr and
|
| 81 |
+
return non-zero. The binary was installed and working; we reported it missing
|
| 82 |
+
and skipped a phase.
|
| 83 |
+
|
| 84 |
+
This is the mirror image of the bugs above: there, a broken thing looked fine;
|
| 85 |
+
here, a working thing looked broken. Both come from testing a **proxy** instead
|
| 86 |
+
of the thing itself. The fix was to check that `lmplz` actually builds a model
|
| 87 |
+
from three lines of input.
|
| 88 |
+
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
## 4. Every result silently failed to save
|
| 92 |
+
|
| 93 |
+
Results were pushed to a private repository with `HfApi()` and no explicit
|
| 94 |
+
token. The library picked up an ambient `HF_TOKEN` from the environment — a
|
| 95 |
+
**read** token for a different account — and every upload returned
|
| 96 |
+
`Repository Not Found`.
|
| 97 |
+
|
| 98 |
+
Five models had been scored. The machine terminated itself on schedule and would
|
| 99 |
+
have taken all of it. We pulled the files off over SSH minutes before it went.
|
| 100 |
+
|
| 101 |
+
The same ambient-credential precedence bug had already cost us a day earlier in
|
| 102 |
+
the project, in a completely different service. Knowing about a class of bug is
|
| 103 |
+
not the same as being immune to it.
|
| 104 |
+
|
| 105 |
+
> An ambient credential is not a default, it is a trap. Pass the token you mean.
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## 5. The deadman switch we triggered by trying to disable it
|
| 110 |
+
|
| 111 |
+
Rented machines had a shutdown timer:
|
| 112 |
+
|
| 113 |
+
```bash
|
| 114 |
+
( sleep 32400; kill_self ) &
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
To keep a machine alive for debugging, we killed the `sleep`. The subshell
|
| 118 |
+
proceeded immediately to the next command, which was `kill_self`. **Killing the
|
| 119 |
+
timer fires the timer.**
|
| 120 |
+
|
| 121 |
+
We destroyed a healthy machine and the evidence on it. The fix is a loop that
|
| 122 |
+
checks a flag file, so interrupting one iteration costs a minute rather than
|
| 123 |
+
executing the payload:
|
| 124 |
+
|
| 125 |
+
```bash
|
| 126 |
+
( for i in $(seq 1 540); do sleep 60; [ -f NODEADMAN ] && exit 0; done
|
| 127 |
+
kill_self ) &
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
---
|
| 131 |
+
|
| 132 |
+
## 6. Four dependency collisions, each invisible to the previous fix
|
| 133 |
+
|
| 134 |
+
The GPU image ships deep learning frameworks but not data tooling, and every
|
| 135 |
+
`pip install` that pulled a newer version collided with something preinstalled.
|
| 136 |
+
|
| 137 |
+
| Symptom | Actual cause |
|
| 138 |
+
|---|---|
|
| 139 |
+
| `numpy._DTypeMeta object is not subscriptable` | `soundfile` 0.13+ uses numpy 2 generics; the image has numpy 1.x |
|
| 140 |
+
| `libcudart.so.13: cannot open shared object file` | installing a VAD package pulled a **CUDA 13** torchaudio onto a **CUDA 12.8** torch |
|
| 141 |
+
| **`cannot import name 'AutoProcessor' from 'transformers'`** | **Pillow 9.0.1.** `PIL.Image.Resampling` arrived in 9.1, and without it every transformers processor class fails to import |
|
| 142 |
+
| `Special word <unk> is not allowed in the corpus` | the text corpus contains literal `<unk>` tokens; the LM trainer aborts rather than ignoring them |
|
| 143 |
+
|
| 144 |
+
The third one deserves attention. The error names `transformers` and
|
| 145 |
+
`AutoProcessor`. The cause is an image library four versions behind. Nothing in
|
| 146 |
+
the message points anywhere near it, and it cost two machine launches.
|
| 147 |
+
|
| 148 |
+
**What finally worked** was not fixing them individually but adding a preflight
|
| 149 |
+
that runs on the machine, before any real work, and imports **the exact symbols
|
| 150 |
+
the pipeline uses** — not the packages, the symbols. A stub-based local check
|
| 151 |
+
cannot catch these by construction, because it replaces the very libraries that
|
| 152 |
+
collide.
|
| 153 |
+
|
| 154 |
+
Two durable fixes came out of it: pin `torchaudio` to `torch`'s own version and
|
| 155 |
+
CUDA tag read at runtime rather than hard-coded, and move to a newer OS image so
|
| 156 |
+
the whole class of stale-system-package problems disappears instead of being
|
| 157 |
+
patched one at a time.
|
| 158 |
+
|
| 159 |
+
---
|
| 160 |
+
|
| 161 |
+
## 7. Losing 374 recordings to a silent failure
|
| 162 |
+
|
| 163 |
+
In the collection stage, a download worker had a circuit breaker: ten
|
| 164 |
+
consecutive failures and stop. But the branch where the download succeeds and
|
| 165 |
+
the audio conversion produces nothing incremented the failure counter and then
|
| 166 |
+
**continued without checking it**.
|
| 167 |
+
|
| 168 |
+
One machine hit that branch on every single item. All three of its shards ran to
|
| 169 |
+
completion reporting `0 uploaded, 123 failed`, wrote a "finished" marker, and
|
| 170 |
+
the supervisor saw nothing wrong. 374 recordings, silently.
|
| 171 |
+
|
| 172 |
+
Two fixes: every failure path must reach the circuit breaker, and a shard that
|
| 173 |
+
fails more than a tenth of its work does not get to call itself finished.
|
| 174 |
+
|
| 175 |
+
---
|
| 176 |
+
|
| 177 |
+
## 8. A metric that argued against the right decision
|
| 178 |
+
|
| 179 |
+
We built a tool where people correct machine-written transcripts, and it
|
| 180 |
+
reported an effort ratio of **17.5x** — seventeen seconds of human time per
|
| 181 |
+
second of audio. At that rate the approach is not worth pursuing.
|
| 182 |
+
|
| 183 |
+
The timer measured **wall-clock from assignment to submission**. One clip logged
|
| 184 |
+
4,590 seconds: someone opened it and went to lunch.
|
| 185 |
+
|
| 186 |
+
| statistic | effort |
|
| 187 |
+
|---|---|
|
| 188 |
+
| p25 | 1.1x realtime |
|
| 189 |
+
| **median** | **2.0x realtime** |
|
| 190 |
+
| p75 | 5.1x |
|
| 191 |
+
| p95 | 79.2x |
|
| 192 |
+
| mean | 12.1x |
|
| 193 |
+
|
| 194 |
+
The median is the real number and it is **six times better** than the mean. A
|
| 195 |
+
badly specified metric nearly killed a good idea.
|
| 196 |
+
|
| 197 |
+
> When a distribution has walk-aways in it, the mean is not a summary, it is an
|
| 198 |
+
> artefact. Report the median and the tail separately.
|
| 199 |
+
|
| 200 |
+
---
|
| 201 |
+
|
| 202 |
+
## 9. Choosing the wrong model to build on
|
| 203 |
+
|
| 204 |
+
Our pipeline used a 1-billion-parameter model as one of its two transcribers,
|
| 205 |
+
because it was the largest in the family and we assumed size ordered quality.
|
| 206 |
+
|
| 207 |
+
Measured on this benchmark:
|
| 208 |
+
|
| 209 |
+
| model | parameters | CER |
|
| 210 |
+
|---|---|---|
|
| 211 |
+
| `Ethio-ASR-multilingual-600M` | 600M | **0.0991** |
|
| 212 |
+
| `Ethio-ASR-multilingual-1B` | 1B | 0.1308 |
|
| 213 |
+
|
| 214 |
+
The **smaller** model is 24% better. It is also the one the community actually
|
| 215 |
+
downloads, by a factor of 500. The information was public the whole time; we
|
| 216 |
+
never checked.
|
| 217 |
+
|
| 218 |
+
---
|
| 219 |
+
|
| 220 |
+
## 10. Things that were simply true, and surprising
|
| 221 |
+
|
| 222 |
+
**A published threshold does not transfer across domains.** A filter calibrated
|
| 223 |
+
on read prompts, where two models disagreed by 0.10 on average, was applied to
|
| 224 |
+
spontaneous podcast speech where they disagree by 0.32. It retained 8% of the
|
| 225 |
+
data. Nothing was broken. The number was measured somewhere else.
|
| 226 |
+
|
| 227 |
+
**Both transcribers collapse on long segments, in opposite ways.** Above roughly
|
| 228 |
+
ten seconds of spontaneous speech, the CTC model silently drops content — its
|
| 229 |
+
output fell to 0.74x the length of the other model's — while the sequence model
|
| 230 |
+
falls into repetition loops, one 29.7-second segment repeating the same clause
|
| 231 |
+
nine times. Retention above ten seconds was **zero**.
|
| 232 |
+
|
| 233 |
+
**Overlapping confidence intervals do not mean a tie.** Our top two models have
|
| 234 |
+
intervals of [0.0896, 0.0999] and [0.0939, 0.1042], which overlap. But they are
|
| 235 |
+
scored on the same clips, so the correct test is paired — and the difference is
|
| 236 |
+
real at p = 0.001. Reading marginal intervals would have given the wrong answer.
|
| 237 |
+
|
| 238 |
+
---
|
| 239 |
+
|
| 240 |
+
## What we would tell someone starting this
|
| 241 |
+
|
| 242 |
+
1. **Print the diagnostic that would look different if you were wrong**, next to
|
| 243 |
+
every headline number. Correlations, output-length ratios, retention by
|
| 244 |
+
bucket. Three invalid results here were caught by exactly one such number.
|
| 245 |
+
2. **Test the thing, not a proxy for it.** `--help` exiting zero is not proof a
|
| 246 |
+
tool works.
|
| 247 |
+
3. **Never let ambient credentials be your default.**
|
| 248 |
+
4. **Write the decision rule before the run**, and do not move it afterwards.
|
| 249 |
+
Ours said stop below 10% retention. We hit 8%. Saying so is the whole point.
|
| 250 |
+
5. **Check the leaderboard before picking the biggest model.**
|
| 251 |
+
6. **Medians, when your data has humans in it.**
|
| 252 |
+
|
| 253 |
+
None of this made the benchmark better. It made it *true*, which took longer.
|
docs/LIMITATIONS.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Limitations
|
| 2 |
+
|
| 3 |
+
Read this before quoting anything here.
|
| 4 |
+
|
| 5 |
+
## 1. One domain, and it is the easy one
|
| 6 |
+
|
| 7 |
+
Every number is measured on **people reading prompts aloud into a phone**. One
|
| 8 |
+
speaker, close microphone, scripted grammatical sentence, no overlap, no music.
|
| 9 |
+
|
| 10 |
+
That is not how anyone talks.
|
| 11 |
+
|
| 12 |
+
We measured the gap on spontaneous podcast audio using teacher agreement as a
|
| 13 |
+
proxy: the same models disagree with each other **roughly three times more** on
|
| 14 |
+
spontaneous speech than on read prompts (mean pairwise distance 0.32 against
|
| 15 |
+
0.10). We could not put an absolute error rate on it because we had no ground
|
| 16 |
+
truth for spontaneous speech.
|
| 17 |
+
|
| 18 |
+
**Do not quote these figures as general Amharic ASR performance.** They describe
|
| 19 |
+
one domain, and it is the domain most favourable to every model in the table.
|
| 20 |
+
|
| 21 |
+
## 2. Greedy decoding only
|
| 22 |
+
|
| 23 |
+
No beam search, no language model in the base numbers, no hyperparameter search
|
| 24 |
+
per model. Every figure is a lower bound on what the model can do.
|
| 25 |
+
|
| 26 |
+
This limitation is **not evenly distributed**. Sequence-to-sequence models are
|
| 27 |
+
usually deployed with beam search and gain more from it than CTC models
|
| 28 |
+
typically do. The within-family comparisons are sound; the cross-family
|
| 29 |
+
comparison should be treated as provisional.
|
| 30 |
+
|
| 31 |
+
## 3. Normalisation is a choice, and it moves the numbers
|
| 32 |
+
|
| 33 |
+
Folding Ge'ez homophone families is defensible — those characters are not
|
| 34 |
+
distinguished in modern pronunciation — but it is a choice, and a stricter
|
| 35 |
+
scorer would produce higher error rates for everyone. The script is published so
|
| 36 |
+
the choice is inspectable rather than implicit. Numbers from a different
|
| 37 |
+
normaliser are not comparable to these.
|
| 38 |
+
|
| 39 |
+
## 4. Small by benchmark standards
|
| 40 |
+
|
| 41 |
+
1,548 clips and 4.72 hours. Enough to separate models that differ by more than
|
| 42 |
+
about half a point of CER, as the confidence intervals show, and **not** enough
|
| 43 |
+
to rank models that are genuinely close. Where the paired test says a difference
|
| 44 |
+
is not distinguishable, treat it as a tie however different the point estimates
|
| 45 |
+
look.
|
| 46 |
+
|
| 47 |
+
## 5. Single run, no seed variance
|
| 48 |
+
|
| 49 |
+
Each model was evaluated once. Greedy decoding is deterministic, so there is no
|
| 50 |
+
sampling variance to average over, but nor is there any check against a
|
| 51 |
+
transient environment problem. The full inputs and outputs are published so that
|
| 52 |
+
an independent rerun is cheap.
|
| 53 |
+
|
| 54 |
+
## 6. What is not measured at all
|
| 55 |
+
|
| 56 |
+
- Real-time factor, latency, memory. A model that is slightly better and ten
|
| 57 |
+
times slower is not better for most deployments.
|
| 58 |
+
- Robustness to noise, telephone bandwidth, or code-switching into English,
|
| 59 |
+
which is extremely common in Ethiopian speech.
|
| 60 |
+
- Speaker demographics beyond what the corpus records. If a model is worse for
|
| 61 |
+
women, or for particular regional accents, nothing here would reveal it.
|
| 62 |
+
|
| 63 |
+
That last one is a real gap and we intend to close it, since the corpus carries
|
| 64 |
+
gender, age band and region for every clip.
|
docs/METHOD.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Method
|
| 2 |
+
|
| 3 |
+
## The test set
|
| 4 |
+
|
| 5 |
+
1,548 clips, 4.72 hours, drawn from the test split of an open Amharic speech
|
| 6 |
+
corpus of read prompts.
|
| 7 |
+
|
| 8 |
+
**The labels are certain.** A contributor was shown a sentence and read it
|
| 9 |
+
aloud, so the reference text existed before the audio did. This is unusual and
|
| 10 |
+
it matters: most speech benchmarks score against transcripts a person typed
|
| 11 |
+
while listening, which carries its own error rate that nobody measures. Here
|
| 12 |
+
there is no transcriber to be wrong.
|
| 13 |
+
|
| 14 |
+
**The splits are speaker-disjoint.** No speaker appears in more than one split,
|
| 15 |
+
so a model cannot score well by having memorised a voice.
|
| 16 |
+
|
| 17 |
+
## No contamination
|
| 18 |
+
|
| 19 |
+
Every model evaluated was published **before** the test set existed. Checked
|
| 20 |
+
against creation timestamps, not asserted:
|
| 21 |
+
|
| 22 |
+
| asset | published |
|
| 23 |
+
|---|---|
|
| 24 |
+
| **the test set** | **2026-08-25** |
|
| 25 |
+
| `badrex/Ethio-ASR-*` (all variants) | 2026-03-24 |
|
| 26 |
+
| `b1n1yam/shook-medium-amharic-2k` | 2025-12-08 |
|
| 27 |
+
| `b1n1yam/shook-tiny-*` | 2025-11-21 |
|
| 28 |
+
| `openai/whisper-large-v3` | 2023-11 |
|
| 29 |
+
|
| 30 |
+
This is the property that makes the numbers worth quoting. A benchmark whose
|
| 31 |
+
test data may sit in the training set of the models it ranks is measuring
|
| 32 |
+
memory, not recognition.
|
| 33 |
+
|
| 34 |
+
## Scoring
|
| 35 |
+
|
| 36 |
+
**Character error rate is the headline metric.** Amharic is agglutinative:
|
| 37 |
+
prefixes, suffixes and clitics attach to a stem, so a single wrong affix on a
|
| 38 |
+
long word costs an entire word under WER and discards most of the signal. Word
|
| 39 |
+
error rate is reported alongside it because it is what everyone else quotes and
|
| 40 |
+
comparability matters more than being right about which metric is better.
|
| 41 |
+
|
| 42 |
+
Before scoring, both reference and hypothesis pass through the corpus's own
|
| 43 |
+
published evaluation script, which:
|
| 44 |
+
|
| 45 |
+
- folds Ge'ez homophone families that carry no phonemic distinction in modern
|
| 46 |
+
usage (ሀ/ሐ/ኀ, ሰ/ሠ, አ/ዐ, ጸ/ፀ)
|
| 47 |
+
- strips Ethiopic punctuation, which lives in the same Unicode block as letters
|
| 48 |
+
and so is not caught by generic punctuation classes
|
| 49 |
+
- normalises to NFC
|
| 50 |
+
|
| 51 |
+
One model performs joint recognition and language identification and prefixes
|
| 52 |
+
its output with a tag such as `[AMH]`. That tag is stripped before scoring.
|
| 53 |
+
Leaving it in charges the model for doing the second job it was designed to do,
|
| 54 |
+
and in an earlier experiment it silently affected 290 of 500 outputs.
|
| 55 |
+
|
| 56 |
+
Normalisation is applied **for scoring only**. Folding ሐ into ሀ is correct when
|
| 57 |
+
comparing two strings and wrong as a training target: a model trained on folded
|
| 58 |
+
text learns to misspell.
|
| 59 |
+
|
| 60 |
+
## Decoding
|
| 61 |
+
|
| 62 |
+
Greedy, no beam search, for every model. This is a deliberate limitation rather
|
| 63 |
+
than a claim of optimality, and it is stated because it is not neutral: CTC and
|
| 64 |
+
sequence-to-sequence models are not equally penalised by it. Sequence models are
|
| 65 |
+
normally run with beam search and were not here. **Treat every number as a
|
| 66 |
+
conservative lower bound**, and treat the CTC-versus-Whisper comparison with
|
| 67 |
+
more caution than the comparisons within each family.
|
| 68 |
+
|
| 69 |
+
Sequence models are generated with a 440-token limit. An earlier pass used 200
|
| 70 |
+
and truncated them; see `FAILURES.md`.
|
| 71 |
+
|
| 72 |
+
## Statistics
|
| 73 |
+
|
| 74 |
+
Point estimates are not enough to say one model beats another.
|
| 75 |
+
|
| 76 |
+
- **95% confidence intervals** come from a bootstrap over 2,000 resamples of
|
| 77 |
+
**clips**, not characters, so the unit of resampling matches the unit of
|
| 78 |
+
independence.
|
| 79 |
+
- **Comparisons use a paired bootstrap.** Every model is scored on the same
|
| 80 |
+
clips, so the difference between two models is computed within each resample
|
| 81 |
+
rather than by comparing marginal intervals.
|
| 82 |
+
|
| 83 |
+
This distinction is not academic here. Our top two models have intervals of
|
| 84 |
+
[0.0896, 0.0999] and [0.0939, 0.1042], which overlap — and the paired test finds
|
| 85 |
+
the difference real at p = 0.001. Reading the marginal intervals alone would
|
| 86 |
+
have produced the wrong conclusion.
|
| 87 |
+
|
| 88 |
+
## Reproducing
|
| 89 |
+
|
| 90 |
+
`hypotheses/` contains every model's raw output for all 1,548 clips. You do not
|
| 91 |
+
have to trust these numbers: rerun `scripts/bootstrap_ci.py` against them, or
|
| 92 |
+
score them with your own normalisation and see what changes.
|
hypotheses/hyp_b1n1yam__shook-medium-amharic-2k.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hypotheses/hyp_b1n1yam__shook-tiny-amharic-stage2-polish.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hypotheses/hyp_badrex__Ethio-ASR-amharic.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hypotheses/hyp_badrex__Ethio-ASR-multilingual-1B.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hypotheses/hyp_badrex__Ethio-ASR-multilingual-600M.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
results/bootstrap.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"n_clips": 1548,
|
| 3 |
+
"bootstrap_resamples": 2000,
|
| 4 |
+
"models": {
|
| 5 |
+
"badrex/Ethio-ASR-amharic": {
|
| 6 |
+
"cer": 0.0946085175823121,
|
| 7 |
+
"ci_low": 0.08959124115436702,
|
| 8 |
+
"ci_high": 0.09989462592202318
|
| 9 |
+
},
|
| 10 |
+
"badrex/Ethio-ASR-multilingual-600M": {
|
| 11 |
+
"cer": 0.0990624900009599,
|
| 12 |
+
"ci_low": 0.09391620100979643,
|
| 13 |
+
"ci_high": 0.10424305248945796
|
| 14 |
+
},
|
| 15 |
+
"b1n1yam/shook-medium-amharic-2k": {
|
| 16 |
+
"cer": 0.11470898793715803,
|
| 17 |
+
"ci_low": 0.10868228572892516,
|
| 18 |
+
"ci_high": 0.12021531100478469
|
| 19 |
+
},
|
| 20 |
+
"badrex/Ethio-ASR-multilingual-1B": {
|
| 21 |
+
"cer": 0.1307842447125076,
|
| 22 |
+
"ci_low": 0.12493081922903662,
|
| 23 |
+
"ci_high": 0.1365712318176798
|
| 24 |
+
},
|
| 25 |
+
"b1n1yam/shook-tiny-amharic-stage2-polish": {
|
| 26 |
+
"cer": 0.2735097430646658,
|
| 27 |
+
"ci_low": 0.264836532200352,
|
| 28 |
+
"ci_high": 0.2820246087866643
|
| 29 |
+
}
|
| 30 |
+
},
|
| 31 |
+
"pairs": [
|
| 32 |
+
{
|
| 33 |
+
"better": "badrex/Ethio-ASR-amharic",
|
| 34 |
+
"worse": "badrex/Ethio-ASR-multilingual-600M",
|
| 35 |
+
"mean_diff": -0.004456998889395945,
|
| 36 |
+
"ci_low": -0.0066792802631077675,
|
| 37 |
+
"ci_high": -0.002177747495908766,
|
| 38 |
+
"p_not_better": 0.0005,
|
| 39 |
+
"distinguishable": true
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"better": "badrex/Ethio-ASR-multilingual-600M",
|
| 43 |
+
"worse": "b1n1yam/shook-medium-amharic-2k",
|
| 44 |
+
"mean_diff": -0.015536286895762965,
|
| 45 |
+
"ci_low": -0.019368955129221502,
|
| 46 |
+
"ci_high": -0.012020175342536354,
|
| 47 |
+
"p_not_better": 0.0,
|
| 48 |
+
"distinguishable": true
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"better": "b1n1yam/shook-medium-amharic-2k",
|
| 52 |
+
"worse": "badrex/Ethio-ASR-multilingual-1B",
|
| 53 |
+
"mean_diff": -0.01614948122332857,
|
| 54 |
+
"ci_low": -0.020152906383583233,
|
| 55 |
+
"ci_high": -0.012007436864122284,
|
| 56 |
+
"p_not_better": 0.0,
|
| 57 |
+
"distinguishable": true
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"better": "badrex/Ethio-ASR-multilingual-1B",
|
| 61 |
+
"worse": "b1n1yam/shook-tiny-amharic-stage2-polish",
|
| 62 |
+
"mean_diff": -0.1427108125824523,
|
| 63 |
+
"ci_low": -0.14980525000317182,
|
| 64 |
+
"ci_high": -0.13608357372773008,
|
| 65 |
+
"p_not_better": 0.0,
|
| 66 |
+
"distinguishable": true
|
| 67 |
+
}
|
| 68 |
+
]
|
| 69 |
+
}
|
results/phase1_greedy.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"test_clips": 1548,
|
| 3 |
+
"test_hours": 4.722048335472743,
|
| 4 |
+
"decoding": "greedy",
|
| 5 |
+
"whisper_max_new_tokens": 440,
|
| 6 |
+
"models": {
|
| 7 |
+
"badrex/Ethio-ASR-multilingual-600M": {
|
| 8 |
+
"cer": 0.0990624900009599,
|
| 9 |
+
"wer": 0.2983765690376569,
|
| 10 |
+
"n": 1548,
|
| 11 |
+
"empty_hyp_rate": 0.0,
|
| 12 |
+
"kind": "ctc"
|
| 13 |
+
},
|
| 14 |
+
"badrex/Ethio-ASR-multilingual-1B": {
|
| 15 |
+
"cer": 0.1307842447125076,
|
| 16 |
+
"wer": 0.3893891213389121,
|
| 17 |
+
"n": 1548,
|
| 18 |
+
"empty_hyp_rate": 0.0,
|
| 19 |
+
"kind": "ctc"
|
| 20 |
+
},
|
| 21 |
+
"badrex/Ethio-ASR-amharic": {
|
| 22 |
+
"cer": 0.0946085175823121,
|
| 23 |
+
"wer": 0.28451882845188287,
|
| 24 |
+
"n": 1548,
|
| 25 |
+
"empty_hyp_rate": 0.0006459948320413437,
|
| 26 |
+
"kind": "ctc"
|
| 27 |
+
},
|
| 28 |
+
"b1n1yam/shook-medium-amharic-2k": {
|
| 29 |
+
"cer": 0.11470898793715803,
|
| 30 |
+
"wer": 0.29425941422594143,
|
| 31 |
+
"n": 1548,
|
| 32 |
+
"empty_hyp_rate": 0.0,
|
| 33 |
+
"kind": "whisper"
|
| 34 |
+
},
|
| 35 |
+
"b1n1yam/shook-tiny-amharic-stage2-polish": {
|
| 36 |
+
"cer": 0.2735097430646658,
|
| 37 |
+
"wer": 0.6200167364016737,
|
| 38 |
+
"n": 1548,
|
| 39 |
+
"empty_hyp_rate": 0.0,
|
| 40 |
+
"kind": "whisper"
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
scripts/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Scripts
|
| 2 |
+
|
| 3 |
+
| file | what it does |
|
| 4 |
+
|---|---|
|
| 5 |
+
| `bench_asr.py` | Runs each model over the test split and scores CER and WER |
|
| 6 |
+
| `bench_lm.py` | Builds an n-gram language model and re-decodes the CTC models |
|
| 7 |
+
| `bootstrap_ci.py` | Confidence intervals and paired significance tests |
|
| 8 |
+
| `geez_eval.py` | Ge'ez normalisation, taken from the corpus release |
|
| 9 |
+
|
| 10 |
+
`geez_eval.py` is the part that matters most for comparability. It folds Ge'ez
|
| 11 |
+
homophone families and strips Ethiopic punctuation, which lives in the same
|
| 12 |
+
Unicode block as letters and so is missed by generic punctuation classes.
|
| 13 |
+
Numbers produced with a different normaliser are not comparable to these.
|
| 14 |
+
|
| 15 |
+
Both benchmark scripts push results after **every model**, so a crash partway
|
| 16 |
+
through does not cost the models already scored. That is not defensive
|
| 17 |
+
programming for its own sake: it is the only reason five models survived a run
|
| 18 |
+
where every upload silently failed. See `../docs/FAILURES.md`.
|
scripts/bench_asr.py
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Phase 1+2: benchmark open ASR models on our own test set, then add a KenLM.
|
| 3 |
+
|
| 4 |
+
Our test set is worth using because of one property nothing else here has: the
|
| 5 |
+
labels are certain. A contributor read a known sentence, so the reference is not
|
| 6 |
+
a guess. And every model benchmarked below was published BEFORE our dataset
|
| 7 |
+
existed, so none of them can have trained on it.
|
| 8 |
+
|
| 9 |
+
Phase 1 each model, greedy decoding, CER and WER
|
| 10 |
+
Phase 2 CTC models again with a KenLM, alpha/beta tuned on VALIDATION
|
| 11 |
+
|
| 12 |
+
Results are pushed after every single model. A crash at model five must not cost
|
| 13 |
+
models one through four.
|
| 14 |
+
|
| 15 |
+
python bench_asr.py --push-to snapwre/amharic-asr-benchmark
|
| 16 |
+
"""
|
| 17 |
+
from __future__ import annotations
|
| 18 |
+
|
| 19 |
+
import argparse
|
| 20 |
+
import io
|
| 21 |
+
import json
|
| 22 |
+
import re
|
| 23 |
+
import subprocess
|
| 24 |
+
import sys
|
| 25 |
+
import time
|
| 26 |
+
import traceback
|
| 27 |
+
from pathlib import Path
|
| 28 |
+
|
| 29 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 30 |
+
|
| 31 |
+
import geez_eval # noqa: E402 the release's own normaliser
|
| 32 |
+
import jiwer # noqa: E402
|
| 33 |
+
import numpy as np # noqa: E402
|
| 34 |
+
import soundfile as sf # noqa: E402
|
| 35 |
+
import torch # noqa: E402
|
| 36 |
+
from huggingface_hub import HfApi, snapshot_download # noqa: E402
|
| 37 |
+
|
| 38 |
+
TEST_REPO = "snapwre/amharic-speech"
|
| 39 |
+
|
| 40 |
+
#: (id, kind, note). Order matters only for reading the log.
|
| 41 |
+
MODELS = [
|
| 42 |
+
("badrex/Ethio-ASR-multilingual-600M", "ctc",
|
| 43 |
+
"w2v-BERT 2.0. Best WAXAL average, 77,598 downloads. The one that matters."),
|
| 44 |
+
("badrex/Ethio-ASR-multilingual-1B", "ctc",
|
| 45 |
+
"MMS-based. What both our E01/E02 and Henok's corpus used."),
|
| 46 |
+
("badrex/Ethio-ASR-amharic", "ctc",
|
| 47 |
+
"Monolingual. Does multilingual training help Amharic or hurt it?"),
|
| 48 |
+
("b1n1yam/shook-medium-amharic-2k", "whisper",
|
| 49 |
+
"Whisper medium, ~2k hours. Our previous best at 0.091 CER."),
|
| 50 |
+
("b1n1yam/shook-tiny-amharic-stage2-polish", "whisper",
|
| 51 |
+
"37.8M params. If it is close, this is the on-device story."),
|
| 52 |
+
("openai/whisper-large-v3", "whisper",
|
| 53 |
+
"Baseline. Expected to be bad on Amharic; that is the point."),
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
LANG_TAG = re.compile(r"^\s*\[[A-Z]{2,4}\]\s*")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def log(m: str) -> None:
|
| 60 |
+
print(f"{time.strftime('%H:%M:%S')} {m}", flush=True)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def norm(t: str) -> str:
|
| 64 |
+
"""Scoring-side normalisation: fold Ge'ez homophones, strip punctuation.
|
| 65 |
+
|
| 66 |
+
Identical to the published eval.py so these numbers are comparable with
|
| 67 |
+
every figure the project has already put in public.
|
| 68 |
+
"""
|
| 69 |
+
return geez_eval.normalize(LANG_TAG.sub("", t or ""), fold_geez=True)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def score(refs: list[str], hyps: list[str]) -> dict:
|
| 73 |
+
"""CER and WER over the whole set, computed on concatenated text.
|
| 74 |
+
|
| 75 |
+
CER is the honest metric for Amharic: it is agglutinative, so one wrong affix
|
| 76 |
+
on a long word costs an entire word under WER and throws away most of the
|
| 77 |
+
signal. WER is reported anyway because it is what everyone else quotes.
|
| 78 |
+
"""
|
| 79 |
+
R = [norm(r) for r in refs]
|
| 80 |
+
H = [norm(h) for h in hyps]
|
| 81 |
+
pairs = [(r, h) for r, h in zip(R, H) if r]
|
| 82 |
+
if not pairs:
|
| 83 |
+
return {"cer": float("nan"), "wer": float("nan"), "n": 0}
|
| 84 |
+
R2 = [r for r, _ in pairs]
|
| 85 |
+
H2 = [h for _, h in pairs]
|
| 86 |
+
empty = sum(1 for h in H2 if not h.strip())
|
| 87 |
+
return {"cer": float(jiwer.cer(R2, H2)), "wer": float(jiwer.wer(R2, H2)),
|
| 88 |
+
"n": len(pairs), "empty_hyp_rate": empty / len(pairs)}
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def load_split(split: str, limit: int | None) -> list[dict]:
|
| 92 |
+
import pyarrow.parquet as pq
|
| 93 |
+
d = Path(snapshot_download(TEST_REPO, repo_type="dataset",
|
| 94 |
+
allow_patterns=[f"data/{split}-*.parquet"]))
|
| 95 |
+
rows: list[dict] = []
|
| 96 |
+
for f in sorted(d.glob(f"data/{split}-*.parquet")):
|
| 97 |
+
for b in pq.ParquetFile(f).iter_batches(batch_size=64):
|
| 98 |
+
for r in b.to_pylist():
|
| 99 |
+
rows.append(r)
|
| 100 |
+
if limit and len(rows) >= limit:
|
| 101 |
+
return rows
|
| 102 |
+
return rows
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def audio_of(row: dict) -> np.ndarray:
|
| 106 |
+
a, sr = sf.read(io.BytesIO(row["audio"]["bytes"]), dtype="float32")
|
| 107 |
+
if a.ndim > 1:
|
| 108 |
+
a = a.mean(axis=1)
|
| 109 |
+
assert sr == 16000, f"expected 16 kHz, got {sr}"
|
| 110 |
+
return a
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@torch.inference_mode()
|
| 114 |
+
def run_ctc(mid: str, rows: list[dict], bs: int, want_logits: bool = False):
|
| 115 |
+
"""CTC greedy. Optionally also return logits for later LM decoding."""
|
| 116 |
+
from transformers import AutoModelForCTC, AutoProcessor
|
| 117 |
+
proc = AutoProcessor.from_pretrained(mid)
|
| 118 |
+
model = AutoModelForCTC.from_pretrained(
|
| 119 |
+
mid, torch_dtype=torch.float16).to("cuda").eval()
|
| 120 |
+
out, logits_all = [], []
|
| 121 |
+
for i in range(0, len(rows), bs):
|
| 122 |
+
chunk = [audio_of(r) for r in rows[i:i + bs]]
|
| 123 |
+
inp = proc(chunk, sampling_rate=16000, return_tensors="pt", padding=True)
|
| 124 |
+
key = "input_features" if "input_features" in inp else "input_values"
|
| 125 |
+
lg = model(inp[key].to("cuda", torch.float16)).logits
|
| 126 |
+
out += proc.batch_decode(lg.argmax(-1).cpu().numpy())
|
| 127 |
+
if want_logits:
|
| 128 |
+
# float32 on CPU; pyctcdecode needs log-probs and fp16 underflows.
|
| 129 |
+
logits_all += [x for x in lg.float().cpu().numpy()]
|
| 130 |
+
if (i // bs) % 10 == 0:
|
| 131 |
+
log(f" {min(i + bs, len(rows))}/{len(rows)}")
|
| 132 |
+
vocab = proc.tokenizer.get_vocab() if hasattr(proc, "tokenizer") else {}
|
| 133 |
+
del model
|
| 134 |
+
torch.cuda.empty_cache()
|
| 135 |
+
return [t.strip() for t in out], logits_all, vocab
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
@torch.inference_mode()
|
| 139 |
+
def run_whisper(mid: str, rows: list[dict], bs: int) -> list[str]:
|
| 140 |
+
from transformers import WhisperForConditionalGeneration, WhisperProcessor
|
| 141 |
+
proc = WhisperProcessor.from_pretrained(mid)
|
| 142 |
+
model = WhisperForConditionalGeneration.from_pretrained(
|
| 143 |
+
mid, torch_dtype=torch.float16).to("cuda").eval()
|
| 144 |
+
out = []
|
| 145 |
+
for i in range(0, len(rows), bs):
|
| 146 |
+
chunk = [audio_of(r) for r in rows[i:i + bs]]
|
| 147 |
+
feats = proc(chunk, sampling_rate=16000,
|
| 148 |
+
return_tensors="pt").input_features
|
| 149 |
+
ids = model.generate(feats.to("cuda", torch.float16),
|
| 150 |
+
language="am", task="transcribe",
|
| 151 |
+
max_new_tokens=440, num_beams=1)
|
| 152 |
+
out += proc.batch_decode(ids, skip_special_tokens=True)
|
| 153 |
+
if (i // bs) % 10 == 0:
|
| 154 |
+
log(f" {min(i + bs, len(rows))}/{len(rows)}")
|
| 155 |
+
del model
|
| 156 |
+
torch.cuda.empty_cache()
|
| 157 |
+
return [t.strip() for t in out]
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def push(api: HfApi, repo: str, obj, path: str) -> None:
|
| 161 |
+
p = Path("/tmp") / Path(path).name
|
| 162 |
+
p.write_text(json.dumps(obj, ensure_ascii=False, indent=2)
|
| 163 |
+
if not isinstance(obj, str) else obj, encoding="utf-8")
|
| 164 |
+
try:
|
| 165 |
+
api.upload_file(path_or_fileobj=str(p), repo_id=repo,
|
| 166 |
+
repo_type="dataset", path_in_repo=path)
|
| 167 |
+
log(f" pushed {path}")
|
| 168 |
+
except Exception as exc: # noqa: BLE001
|
| 169 |
+
log(f" push failed for {path}: {exc}")
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def main() -> None:
|
| 173 |
+
ap = argparse.ArgumentParser()
|
| 174 |
+
ap.add_argument("--push-to", default="snapwre/amharic-asr-benchmark")
|
| 175 |
+
ap.add_argument("--limit", type=int, default=0)
|
| 176 |
+
ap.add_argument("--batch-size", type=int, default=16)
|
| 177 |
+
ap.add_argument("--out", type=Path, default=Path("bench"))
|
| 178 |
+
ap.add_argument("--skip-lm", action="store_true")
|
| 179 |
+
# Without this the script invented its own timestamp, so results.json landed
|
| 180 |
+
# in a different runs/ folder from the log and every other artefact of the
|
| 181 |
+
# same job. One run must mean one folder.
|
| 182 |
+
ap.add_argument("--run", default="")
|
| 183 |
+
args = ap.parse_args()
|
| 184 |
+
args.out.mkdir(parents=True, exist_ok=True)
|
| 185 |
+
|
| 186 |
+
# HfApi() with no token picks up the ambient HF_TOKEN, which here is the
|
| 187 |
+
# collaborator's READ token for the private audio repo. It cannot write to
|
| 188 |
+
# our namespace, so every push 404s with "Repository Not Found". Same
|
| 189 |
+
# ambient-token precedence bug that cost the download workers a day.
|
| 190 |
+
import os
|
| 191 |
+
api = HfApi(token=os.environ.get("HF_PUSH_TOKEN") or None)
|
| 192 |
+
import os
|
| 193 |
+
run = (args.run or os.environ.get("RUN_ID")
|
| 194 |
+
or time.strftime("%Y%m%dT%H%M%SZ", time.gmtime()))
|
| 195 |
+
log(f"run {run} torch {torch.__version__} cuda {torch.cuda.is_available()}")
|
| 196 |
+
|
| 197 |
+
test = load_split("test", args.limit or None)
|
| 198 |
+
refs = [r["sentence"] for r in test]
|
| 199 |
+
hours = sum(r["duration_s"] for r in test) / 3600
|
| 200 |
+
log(f"test split: {len(test)} clips, {hours:.2f} h")
|
| 201 |
+
|
| 202 |
+
results = {"run": run, "test_clips": len(test), "test_hours": hours,
|
| 203 |
+
"phase1": {}, "phase2": {}}
|
| 204 |
+
keep = {} # model -> (logits, vocab) for the LM phase
|
| 205 |
+
|
| 206 |
+
for mid, kind, note in MODELS:
|
| 207 |
+
log(f"== {mid} ({kind})")
|
| 208 |
+
t0 = time.time()
|
| 209 |
+
try:
|
| 210 |
+
if kind == "ctc":
|
| 211 |
+
hyps, logits, vocab = run_ctc(
|
| 212 |
+
mid, test, args.batch_size,
|
| 213 |
+
want_logits=not args.skip_lm)
|
| 214 |
+
if logits:
|
| 215 |
+
keep[mid] = (logits, vocab)
|
| 216 |
+
else:
|
| 217 |
+
hyps = run_whisper(mid, test, args.batch_size)
|
| 218 |
+
s = score(refs, hyps)
|
| 219 |
+
s.update(kind=kind, note=note, seconds=round(time.time() - t0, 1))
|
| 220 |
+
results["phase1"][mid] = s
|
| 221 |
+
log(f" CER {s['cer']:.4f} WER {s['wer']:.4f} "
|
| 222 |
+
f"empty {s['empty_hyp_rate']:.1%} {s['seconds']:.0f}s")
|
| 223 |
+
(args.out / f"hyp_{mid.replace('/', '__')}.json").write_text(
|
| 224 |
+
json.dumps({"model": mid, "hyps": hyps}, ensure_ascii=False))
|
| 225 |
+
except Exception as exc: # noqa: BLE001
|
| 226 |
+
log(f" FAILED: {type(exc).__name__}: {exc}")
|
| 227 |
+
traceback.print_exc()
|
| 228 |
+
results["phase1"][mid] = {"error": f"{type(exc).__name__}: {exc}",
|
| 229 |
+
"kind": kind, "note": note}
|
| 230 |
+
# Push after EVERY model. A crash at model five must not cost the rest.
|
| 231 |
+
push(api, args.push_to, results, f"runs/{run}/results.json")
|
| 232 |
+
|
| 233 |
+
(args.out / "results.json").write_text(json.dumps(results, indent=2))
|
| 234 |
+
log("phase 1 complete")
|
| 235 |
+
|
| 236 |
+
if args.skip_lm or not keep:
|
| 237 |
+
return
|
| 238 |
+
log("phase 2 would run here (kept logits for "
|
| 239 |
+
f"{len(keep)} CTC models)")
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
if __name__ == "__main__":
|
| 243 |
+
main()
|
scripts/bench_lm.py
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Phase 2: does an Amharic n-gram language model improve CTC decoding?
|
| 3 |
+
|
| 4 |
+
A CTC model emits a probability per character per frame and decides each frame
|
| 5 |
+
independently. It has no idea what an Amharic word is, so when the audio is
|
| 6 |
+
ambiguous it will happily emit a character sequence that is not a word. An
|
| 7 |
+
n-gram LM scores candidate hypotheses during beam search and pulls the output
|
| 8 |
+
toward sequences that are actually Amharic.
|
| 9 |
+
|
| 10 |
+
This applies to CTC only. Whisper is seq2seq with its own decoder and does not
|
| 11 |
+
take an external n-gram the same way.
|
| 12 |
+
|
| 13 |
+
Two rules that make the result honest:
|
| 14 |
+
|
| 15 |
+
1. Every test AND validation sentence is excluded from the LM training text.
|
| 16 |
+
An LM that has memorised the references makes the score fiction, and the
|
| 17 |
+
failure is silent: nothing errors, the number just comes out better.
|
| 18 |
+
2. alpha and beta are tuned on VALIDATION, never on test.
|
| 19 |
+
"""
|
| 20 |
+
from __future__ import annotations
|
| 21 |
+
|
| 22 |
+
import argparse
|
| 23 |
+
import io
|
| 24 |
+
import json
|
| 25 |
+
import re
|
| 26 |
+
import subprocess
|
| 27 |
+
import sys
|
| 28 |
+
import time
|
| 29 |
+
import unicodedata
|
| 30 |
+
from pathlib import Path
|
| 31 |
+
|
| 32 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 33 |
+
|
| 34 |
+
import geez_eval # noqa: E402
|
| 35 |
+
import jiwer # noqa: E402
|
| 36 |
+
import numpy as np # noqa: E402
|
| 37 |
+
import soundfile as sf # noqa: E402
|
| 38 |
+
import torch # noqa: E402
|
| 39 |
+
from huggingface_hub import HfApi, snapshot_download # noqa: E402
|
| 40 |
+
|
| 41 |
+
TEST_REPO = "snapwre/amharic-speech"
|
| 42 |
+
#: Addis AI's open Amharic text, 10.1M rows. Two orders of magnitude more than
|
| 43 |
+
#: our 660k words of prompts, and the single biggest upgrade available to the LM.
|
| 44 |
+
TEXT_REPOS = ["b1n1yam/amharic-combined-corpus"]
|
| 45 |
+
|
| 46 |
+
CTC_MODELS = [
|
| 47 |
+
"badrex/Ethio-ASR-multilingual-600M",
|
| 48 |
+
"badrex/Ethio-ASR-multilingual-1B",
|
| 49 |
+
"badrex/Ethio-ASR-amharic",
|
| 50 |
+
]
|
| 51 |
+
LANG_TAG = re.compile(r"^\s*\[[A-Z]{2,4}\]\s*")
|
| 52 |
+
PUNCT = re.compile(r"[።፡፣፤፥፦፧፨\.\,\?\!\:\;\"\'\(\)\[\]]")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def log(m: str) -> None:
|
| 56 |
+
print(f"{time.strftime('%H:%M:%S')} {m}", flush=True)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def norm(t: str) -> str:
|
| 60 |
+
return geez_eval.normalize(LANG_TAG.sub("", t or ""), fold_geez=True)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def cer_wer(refs, hyps):
|
| 64 |
+
R = [norm(r) for r in refs]
|
| 65 |
+
H = [norm(h) for h in hyps]
|
| 66 |
+
p = [(r, h) for r, h in zip(R, H) if r]
|
| 67 |
+
return (float(jiwer.cer([r for r, _ in p], [h for _, h in p])),
|
| 68 |
+
float(jiwer.wer([r for r, _ in p], [h for _, h in p])))
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def lm_text(held: set[str]) -> Path:
|
| 72 |
+
"""Amharic text for the LM, with every held-out sentence removed.
|
| 73 |
+
|
| 74 |
+
Exact whole-line matching is not enough and quietly reported 0 drops across
|
| 75 |
+
12.8M lines. Our prompts came from news text and this corpus is news and
|
| 76 |
+
wiki, so a test sentence sitting INSIDE a longer paragraph is a real risk,
|
| 77 |
+
and it is exactly the kind of leak that raises no error and silently makes
|
| 78 |
+
every downstream number better than the truth. Aho-Corasick finds them as
|
| 79 |
+
substrings in one pass.
|
| 80 |
+
"""
|
| 81 |
+
out = Path("lm_corpus.txt")
|
| 82 |
+
seen: set[str] = set()
|
| 83 |
+
n_lines = n_drop = 0
|
| 84 |
+
matcher = None
|
| 85 |
+
try:
|
| 86 |
+
import ahocorasick
|
| 87 |
+
matcher = ahocorasick.Automaton()
|
| 88 |
+
for h in held:
|
| 89 |
+
if len(h) >= 20: # short strings would match by coincidence
|
| 90 |
+
matcher.add_word(h, h)
|
| 91 |
+
matcher.make_automaton()
|
| 92 |
+
log(f" substring matcher armed with {len(matcher)} held-out sentences")
|
| 93 |
+
except Exception as exc: # noqa: BLE001
|
| 94 |
+
log(f" ahocorasick unavailable ({exc}); exact match only. "
|
| 95 |
+
"Treat contamination as UNVERIFIED.")
|
| 96 |
+
with out.open("w", encoding="utf-8") as fh:
|
| 97 |
+
for repo in TEXT_REPOS:
|
| 98 |
+
try:
|
| 99 |
+
d = Path(snapshot_download(repo, repo_type="dataset"))
|
| 100 |
+
except Exception as exc: # noqa: BLE001
|
| 101 |
+
log(f" could not fetch {repo}: {exc}")
|
| 102 |
+
continue
|
| 103 |
+
import pyarrow.parquet as pq
|
| 104 |
+
files = sorted(d.rglob("*.parquet"))
|
| 105 |
+
log(f" {repo}: {len(files)} parquet files")
|
| 106 |
+
for f in files:
|
| 107 |
+
try:
|
| 108 |
+
pf = pq.ParquetFile(f)
|
| 109 |
+
col = next((c for c in pf.schema_arrow.names
|
| 110 |
+
if c in ("text", "content", "sentence", "article")),
|
| 111 |
+
None)
|
| 112 |
+
if col is None:
|
| 113 |
+
continue
|
| 114 |
+
for b in pf.iter_batches(batch_size=2000, columns=[col]):
|
| 115 |
+
for t in b.to_pydict()[col]:
|
| 116 |
+
for line in (t or "").splitlines():
|
| 117 |
+
s = unicodedata.normalize("NFC", line).strip()
|
| 118 |
+
if s in held or (matcher is not None
|
| 119 |
+
and any(matcher.iter(s))):
|
| 120 |
+
n_drop += 1
|
| 121 |
+
continue
|
| 122 |
+
s = re.sub(r"\s+", " ", PUNCT.sub(" ", s)).strip()
|
| 123 |
+
if len(s) < 5 or s in seen:
|
| 124 |
+
continue
|
| 125 |
+
seen.add(s)
|
| 126 |
+
fh.write(s + "\n")
|
| 127 |
+
n_lines += 1
|
| 128 |
+
except Exception as exc: # noqa: BLE001
|
| 129 |
+
log(f" skip {f.name}: {exc}")
|
| 130 |
+
log(f" LM corpus: {n_lines:,} lines, {n_drop:,} lines dropped as "
|
| 131 |
+
f"containing a held-out sentence")
|
| 132 |
+
if matcher is not None and n_drop == 0:
|
| 133 |
+
log(" 0 drops with substring matching active: the corpus genuinely "
|
| 134 |
+
"does not contain our test sentences.")
|
| 135 |
+
return out
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def build_kenlm(corpus: Path, order: int = 5) -> Path:
|
| 139 |
+
arpa, binf = Path("am.arpa"), Path("am.bin")
|
| 140 |
+
# --skip_symbols: the corpus contains literal <unk> tokens and lmplz aborts
|
| 141 |
+
# on them rather than ignoring them. Without this the whole phase dies at
|
| 142 |
+
# "Special word <unk> is not allowed in the corpus".
|
| 143 |
+
subprocess.run(f"lmplz -o {order} --discount_fallback --skip_symbols "
|
| 144 |
+
f"-S 40% < {corpus} > {arpa}", shell=True, check=True)
|
| 145 |
+
subprocess.run(["build_binary", str(arpa), str(binf)], check=True)
|
| 146 |
+
log(f" KenLM built: {binf.stat().st_size / 1e6:.0f} MB")
|
| 147 |
+
return binf
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def audio_of(row):
|
| 151 |
+
a, sr = sf.read(io.BytesIO(row["audio"]["bytes"]), dtype="float32")
|
| 152 |
+
return a.mean(axis=1) if a.ndim > 1 else a
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def load_split(split, limit=None):
|
| 156 |
+
import pyarrow.parquet as pq
|
| 157 |
+
d = Path(snapshot_download(TEST_REPO, repo_type="dataset",
|
| 158 |
+
allow_patterns=[f"data/{split}-*.parquet"]))
|
| 159 |
+
rows = []
|
| 160 |
+
for f in sorted(d.glob(f"data/{split}-*.parquet")):
|
| 161 |
+
for b in pq.ParquetFile(f).iter_batches(batch_size=64):
|
| 162 |
+
for r in b.to_pylist():
|
| 163 |
+
rows.append(r)
|
| 164 |
+
if limit and len(rows) >= limit:
|
| 165 |
+
return rows
|
| 166 |
+
return rows
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
@torch.inference_mode()
|
| 170 |
+
def logits_for(mid, rows, bs):
|
| 171 |
+
from transformers import AutoModelForCTC, AutoProcessor
|
| 172 |
+
proc = AutoProcessor.from_pretrained(mid)
|
| 173 |
+
model = AutoModelForCTC.from_pretrained(
|
| 174 |
+
mid, torch_dtype=torch.float16).to("cuda").eval()
|
| 175 |
+
outs = []
|
| 176 |
+
for i in range(0, len(rows), bs):
|
| 177 |
+
chunk = [audio_of(r) for r in rows[i:i + bs]]
|
| 178 |
+
inp = proc(chunk, sampling_rate=16000, return_tensors="pt", padding=True)
|
| 179 |
+
key = "input_features" if "input_features" in inp else "input_values"
|
| 180 |
+
lg = model(inp[key].to("cuda", torch.float16)).logits.float().cpu().numpy()
|
| 181 |
+
outs += [x for x in lg]
|
| 182 |
+
if (i // bs) % 10 == 0:
|
| 183 |
+
log(f" logits {min(i + bs, len(rows))}/{len(rows)}")
|
| 184 |
+
v = proc.tokenizer.get_vocab()
|
| 185 |
+
del model
|
| 186 |
+
torch.cuda.empty_cache()
|
| 187 |
+
return outs, v
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def labels_from(vocab: dict) -> list[str]:
|
| 191 |
+
"""pyctcdecode wants labels by index, blank as '', word delimiter as ' '."""
|
| 192 |
+
out = [""] * (max(vocab.values()) + 1)
|
| 193 |
+
for tok, i in vocab.items():
|
| 194 |
+
if tok in ("<pad>", "<s>", "</s>", "<unk>"):
|
| 195 |
+
out[i] = ""
|
| 196 |
+
elif tok == "|":
|
| 197 |
+
out[i] = " "
|
| 198 |
+
else:
|
| 199 |
+
out[i] = tok
|
| 200 |
+
return out
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def main() -> None:
|
| 204 |
+
ap = argparse.ArgumentParser()
|
| 205 |
+
ap.add_argument("--push-to", default="snapwre/amharic-asr-benchmark")
|
| 206 |
+
ap.add_argument("--run", default=time.strftime("%Y%m%dT%H%M%SZ", time.gmtime()))
|
| 207 |
+
ap.add_argument("--batch-size", type=int, default=16)
|
| 208 |
+
ap.add_argument("--tune-n", type=int, default=400)
|
| 209 |
+
args = ap.parse_args()
|
| 210 |
+
# HfApi() with no token picks up the ambient HF_TOKEN, which here is the
|
| 211 |
+
# collaborator's READ token for the private audio repo. It cannot write to
|
| 212 |
+
# our namespace, so every push 404s with "Repository Not Found". Same
|
| 213 |
+
# ambient-token precedence bug that cost the download workers a day.
|
| 214 |
+
import os
|
| 215 |
+
api = HfApi(token=os.environ.get("HF_PUSH_TOKEN") or None)
|
| 216 |
+
|
| 217 |
+
test, val = load_split("test"), load_split("validation")
|
| 218 |
+
held = {unicodedata.normalize("NFC", r["sentence"]).strip()
|
| 219 |
+
for r in test + val}
|
| 220 |
+
log(f"test {len(test)}, validation {len(val)}, {len(held):,} held-out sentences")
|
| 221 |
+
|
| 222 |
+
log("building LM corpus")
|
| 223 |
+
corpus = lm_text(held)
|
| 224 |
+
lm = build_kenlm(corpus)
|
| 225 |
+
|
| 226 |
+
from pyctcdecode import build_ctcdecoder
|
| 227 |
+
tune = val[:args.tune_n]
|
| 228 |
+
out = {"run": args.run, "lm_corpus_lines": sum(1 for _ in corpus.open()),
|
| 229 |
+
"models": {}}
|
| 230 |
+
|
| 231 |
+
for mid in CTC_MODELS:
|
| 232 |
+
log(f"== {mid}")
|
| 233 |
+
try:
|
| 234 |
+
lg_t, vocab = logits_for(mid, test, args.batch_size)
|
| 235 |
+
labels = labels_from(vocab)
|
| 236 |
+
greedy = []
|
| 237 |
+
for x in lg_t:
|
| 238 |
+
ids = x.argmax(-1)
|
| 239 |
+
prev, s = -1, []
|
| 240 |
+
for i in ids:
|
| 241 |
+
if i != prev and labels[i]:
|
| 242 |
+
s.append(labels[i])
|
| 243 |
+
prev = i
|
| 244 |
+
greedy.append("".join(s))
|
| 245 |
+
g_cer, g_wer = cer_wer([r["sentence"] for r in test], greedy)
|
| 246 |
+
log(f" greedy CER {g_cer:.4f} WER {g_wer:.4f}")
|
| 247 |
+
|
| 248 |
+
lg_v, _ = logits_for(mid, tune, args.batch_size)
|
| 249 |
+
best = None
|
| 250 |
+
for a in (0.3, 0.5, 0.8):
|
| 251 |
+
for b in (0.5, 1.5):
|
| 252 |
+
dec = build_ctcdecoder(labels, str(lm), alpha=a, beta=b)
|
| 253 |
+
hy = [dec.decode(x) for x in lg_v]
|
| 254 |
+
c, _ = cer_wer([r["sentence"] for r in tune], hy)
|
| 255 |
+
log(f" tune a={a} b={b} val CER {c:.4f}")
|
| 256 |
+
if best is None or c < best[0]:
|
| 257 |
+
best = (c, a, b)
|
| 258 |
+
_, A, B = best
|
| 259 |
+
dec = build_ctcdecoder(labels, str(lm), alpha=A, beta=B)
|
| 260 |
+
hy = [dec.decode(x) for x in lg_t]
|
| 261 |
+
l_cer, l_wer = cer_wer([r["sentence"] for r in test], hy)
|
| 262 |
+
log(f" +KenLM CER {l_cer:.4f} WER {l_wer:.4f} "
|
| 263 |
+
f"(alpha={A}, beta={B})")
|
| 264 |
+
out["models"][mid] = {
|
| 265 |
+
"greedy_cer": g_cer, "greedy_wer": g_wer,
|
| 266 |
+
"lm_cer": l_cer, "lm_wer": l_wer, "alpha": A, "beta": B,
|
| 267 |
+
"cer_rel_gain": (g_cer - l_cer) / g_cer if g_cer else None,
|
| 268 |
+
"wer_rel_gain": (g_wer - l_wer) / g_wer if g_wer else None,
|
| 269 |
+
}
|
| 270 |
+
except Exception as exc: # noqa: BLE001
|
| 271 |
+
import traceback
|
| 272 |
+
traceback.print_exc()
|
| 273 |
+
out["models"][mid] = {"error": f"{type(exc).__name__}: {exc}"}
|
| 274 |
+
p = Path("/tmp/lm_results.json")
|
| 275 |
+
p.write_text(json.dumps(out, indent=2))
|
| 276 |
+
try:
|
| 277 |
+
api.upload_file(path_or_fileobj=str(p), repo_id=args.push_to,
|
| 278 |
+
repo_type="dataset",
|
| 279 |
+
path_in_repo=f"runs/{args.run}/lm_results.json")
|
| 280 |
+
log(" pushed lm_results.json")
|
| 281 |
+
except Exception as exc: # noqa: BLE001
|
| 282 |
+
log(f" push failed: {exc}")
|
| 283 |
+
|
| 284 |
+
try:
|
| 285 |
+
api.upload_file(path_or_fileobj=str(lm), repo_id=args.push_to,
|
| 286 |
+
repo_type="dataset", path_in_repo="kenlm/am-5gram.bin")
|
| 287 |
+
log("pushed the KenLM binary")
|
| 288 |
+
except Exception as exc: # noqa: BLE001
|
| 289 |
+
log(f"LM upload failed: {exc}")
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
if __name__ == "__main__":
|
| 293 |
+
main()
|
scripts/bootstrap_ci.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Bootstrap confidence intervals and paired significance for benchmark CERs.
|
| 3 |
+
|
| 4 |
+
A leaderboard that reports 0.0946 against 0.0991 without saying whether that gap
|
| 5 |
+
survives resampling is not a benchmark. And the naive check is wrong: marginal
|
| 6 |
+
confidence intervals for these two models OVERLAP, yet the difference is real,
|
| 7 |
+
because both are scored on the same clips. Pairing is what makes it visible.
|
| 8 |
+
"""
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import csv
|
| 12 |
+
import glob
|
| 13 |
+
import json
|
| 14 |
+
import random
|
| 15 |
+
import re
|
| 16 |
+
import sys
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 20 |
+
import geez_eval # noqa: E402
|
| 21 |
+
import jiwer # noqa: E402
|
| 22 |
+
|
| 23 |
+
TAG = re.compile(r"^\s*\[[A-Z]{2,4}\]\s*")
|
| 24 |
+
B = 2000
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def norm(t: str) -> str:
|
| 28 |
+
return geez_eval.normalize(TAG.sub("", t or ""), fold_geez=True)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def per_clip(refs, hyps):
|
| 32 |
+
"""Edit count and reference length per clip, so we resample clips."""
|
| 33 |
+
out = []
|
| 34 |
+
for r, h in zip(refs, hyps):
|
| 35 |
+
R, H = norm(r), norm(h)
|
| 36 |
+
if not R:
|
| 37 |
+
continue
|
| 38 |
+
out.append((float(jiwer.cer(R, H)) * len(R), len(R)))
|
| 39 |
+
return out
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def analyse(refs, model_hyps: dict[str, list[str]], seed: int = 11) -> dict:
|
| 43 |
+
models = {m: per_clip(refs, h) for m, h in model_hyps.items()}
|
| 44 |
+
cer = {m: sum(e for e, _ in v) / sum(n for _, n in v)
|
| 45 |
+
for m, v in models.items()}
|
| 46 |
+
order = sorted(cer, key=cer.get)
|
| 47 |
+
n = len(models[order[0]])
|
| 48 |
+
rng = random.Random(seed)
|
| 49 |
+
idx = [[rng.randrange(n) for _ in range(n)] for _ in range(B)]
|
| 50 |
+
samples = {m: [sum(models[m][i][0] for i in ix) / sum(models[m][i][1] for i in ix)
|
| 51 |
+
for ix in idx] for m in order}
|
| 52 |
+
|
| 53 |
+
out = {"n_clips": n, "bootstrap_resamples": B, "models": {}, "pairs": []}
|
| 54 |
+
for m in order:
|
| 55 |
+
s = sorted(samples[m])
|
| 56 |
+
out["models"][m] = {"cer": cer[m], "ci_low": s[int(.025 * B)],
|
| 57 |
+
"ci_high": s[int(.975 * B)]}
|
| 58 |
+
for a, b in zip(order, order[1:]):
|
| 59 |
+
d = sorted(x - y for x, y in zip(samples[a], samples[b]))
|
| 60 |
+
out["pairs"].append({
|
| 61 |
+
"better": a, "worse": b, "mean_diff": sum(d) / B,
|
| 62 |
+
"ci_low": d[int(.025 * B)], "ci_high": d[int(.975 * B)],
|
| 63 |
+
"p_not_better": sum(1 for x in d if x >= 0) / B,
|
| 64 |
+
"distinguishable": d[int(.975 * B)] < 0,
|
| 65 |
+
})
|
| 66 |
+
return out
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def main() -> None:
|
| 70 |
+
rel = Path(sys.argv[1] if len(sys.argv) > 1 else
|
| 71 |
+
"build/am-v0.2.0")
|
| 72 |
+
hyp_dir = sys.argv[2] if len(sys.argv) > 2 else "/tmp/benchres"
|
| 73 |
+
refs = [r["sentence"] for r in
|
| 74 |
+
csv.DictReader((rel / "metadata.csv").open(encoding="utf-8"))
|
| 75 |
+
if r["split"] == "test"]
|
| 76 |
+
hyps = {}
|
| 77 |
+
for f in sorted(glob.glob(f"{hyp_dir}/hyp*.json")):
|
| 78 |
+
d = json.load(open(f))
|
| 79 |
+
# A 440-token rerun supersedes the truncated pass for the same model.
|
| 80 |
+
if d["model"] in hyps and not Path(f).name.startswith("hyp440"):
|
| 81 |
+
continue
|
| 82 |
+
hyps[d["model"]] = d["hyps"]
|
| 83 |
+
res = analyse(refs, hyps)
|
| 84 |
+
Path(f"{hyp_dir}/bootstrap.json").write_text(json.dumps(res, indent=2))
|
| 85 |
+
print(json.dumps(res, indent=2)[:1500])
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
if __name__ == "__main__":
|
| 89 |
+
main()
|
scripts/geez_eval.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Official evaluation script for this dataset. Shipped inside the release.
|
| 3 |
+
|
| 4 |
+
Word error rate is only comparable between systems if everyone computes it the
|
| 5 |
+
same way, and for Ge'ez script that is not the default. Amharic and Tigrinya
|
| 6 |
+
write several distinct characters for one sound -- ሀ, ሐ and ኀ are all /hä/; ሰ and
|
| 7 |
+
ሠ are both /sä/; አ and ዐ are both /ʾä/; ጸ and ፀ are both /ṣä/. Which one a writer
|
| 8 |
+
picks is orthographic convention, not pronunciation, and different systems settle
|
| 9 |
+
on different variants. Scoring raw strings therefore charges a model for spelling
|
| 10 |
+
a sound the way its training data spelt it.
|
| 11 |
+
|
| 12 |
+
This script is the reference implementation. Quote the normalised figure; the raw
|
| 13 |
+
one is printed too, because normalising is a judgement call and hiding it would
|
| 14 |
+
make the benchmark unauditable.
|
| 15 |
+
|
| 16 |
+
pip install jiwer
|
| 17 |
+
python eval.py --predictions preds.jsonl
|
| 18 |
+
|
| 19 |
+
`preds.jsonl` has one JSON object per line: {"clip_id": ..., "text": ...}
|
| 20 |
+
Clip ids come from the test split of this dataset.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
from __future__ import annotations
|
| 24 |
+
|
| 25 |
+
import argparse
|
| 26 |
+
import json
|
| 27 |
+
import re
|
| 28 |
+
import sys
|
| 29 |
+
import unicodedata
|
| 30 |
+
|
| 31 |
+
# Each pair shifts one consonant family onto its homophone base. The Ethiopic
|
| 32 |
+
# block lays every consonant out as a contiguous run of vowel orders from a fixed
|
| 33 |
+
# base, so shifting the base and keeping the offset folds all orders at once --
|
| 34 |
+
# including the rare ones a hand-written character list would miss.
|
| 35 |
+
_GEEZ_FOLD_BASES = [
|
| 36 |
+
(0x1210, 0x1200), # ሐ -> ሀ
|
| 37 |
+
(0x1280, 0x1200), # ኀ -> ሀ
|
| 38 |
+
(0x1220, 0x1230), # ሠ -> ሰ
|
| 39 |
+
(0x12D0, 0x12A0), # ዐ -> አ
|
| 40 |
+
(0x1340, 0x1338), # ፀ -> ጸ
|
| 41 |
+
]
|
| 42 |
+
_ORDERS = 8
|
| 43 |
+
|
| 44 |
+
_GEEZ_MAP = {src + o: dst + o for src, dst in _GEEZ_FOLD_BASES for o in range(_ORDERS)}
|
| 45 |
+
_WS = re.compile(r"\s+")
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def normalize(text: str, *, fold_geez: bool = True) -> str:
|
| 49 |
+
text = unicodedata.normalize("NFC", text)
|
| 50 |
+
if fold_geez:
|
| 51 |
+
text = text.translate(_GEEZ_MAP)
|
| 52 |
+
# Ethiopic punctuation (። ፣ ፤) sits inside the same Unicode block as Ethiopic
|
| 53 |
+
# letters, so a character-range test cannot separate them. Ask Unicode.
|
| 54 |
+
text = "".join(" " if unicodedata.category(c)[0] in ("P", "S") else c for c in text)
|
| 55 |
+
return _WS.sub(" ", text.casefold()).strip()
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def evaluate(
|
| 59 |
+
references: dict[str, str], predictions: dict[str, str], *, fold_geez: bool = True
|
| 60 |
+
) -> dict:
|
| 61 |
+
import jiwer
|
| 62 |
+
|
| 63 |
+
missing = [k for k in references if k not in predictions]
|
| 64 |
+
empty = [k for k, v in predictions.items() if not (v or "").strip()]
|
| 65 |
+
|
| 66 |
+
# A clip with no prediction scores as a full deletion rather than being
|
| 67 |
+
# skipped. Dropping it would let a system improve its WER by declining to
|
| 68 |
+
# answer on the clips it finds hard.
|
| 69 |
+
ids = list(references)
|
| 70 |
+
refs = [references[i] for i in ids]
|
| 71 |
+
hyps = [predictions.get(i, "") for i in ids]
|
| 72 |
+
|
| 73 |
+
def measure(r, h):
|
| 74 |
+
pairs = [(a, b) for a, b in zip(r, h, strict=True) if a.strip()]
|
| 75 |
+
return (
|
| 76 |
+
jiwer.wer([p[0] for p in pairs], [p[1] for p in pairs]),
|
| 77 |
+
jiwer.cer([p[0] for p in pairs], [p[1] for p in pairs]),
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
raw_wer, raw_cer = measure(refs, hyps)
|
| 81 |
+
n_wer, n_cer = measure(
|
| 82 |
+
[normalize(r, fold_geez=fold_geez) for r in refs],
|
| 83 |
+
[normalize(h, fold_geez=fold_geez) for h in hyps],
|
| 84 |
+
)
|
| 85 |
+
return {
|
| 86 |
+
"clips": len(ids),
|
| 87 |
+
"wer": round(n_wer * 100, 2),
|
| 88 |
+
"cer": round(n_cer * 100, 2),
|
| 89 |
+
"wer_raw": round(raw_wer * 100, 2),
|
| 90 |
+
"cer_raw": round(raw_cer * 100, 2),
|
| 91 |
+
"missing_predictions": len(missing),
|
| 92 |
+
"empty_predictions": len(empty),
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def main() -> int:
|
| 97 |
+
p = argparse.ArgumentParser(description=__doc__)
|
| 98 |
+
p.add_argument(
|
| 99 |
+
"--predictions", required=True, help='JSONL of {"clip_id": ..., "text": ...}'
|
| 100 |
+
)
|
| 101 |
+
p.add_argument("--dataset", default="snapwre/amharic-speech")
|
| 102 |
+
p.add_argument("--split", default="test")
|
| 103 |
+
p.add_argument(
|
| 104 |
+
"--no-fold",
|
| 105 |
+
action="store_true",
|
| 106 |
+
help="score without homophone folding (not comparable)",
|
| 107 |
+
)
|
| 108 |
+
args = p.parse_args()
|
| 109 |
+
|
| 110 |
+
from datasets import load_dataset
|
| 111 |
+
|
| 112 |
+
ds = load_dataset(args.dataset, split=args.split)
|
| 113 |
+
references = {r["clip_id"]: r["sentence"] for r in ds}
|
| 114 |
+
|
| 115 |
+
predictions = {}
|
| 116 |
+
with open(args.predictions, encoding="utf-8") as fh:
|
| 117 |
+
for line in fh:
|
| 118 |
+
if line.strip():
|
| 119 |
+
row = json.loads(line)
|
| 120 |
+
predictions[row["clip_id"]] = row.get("text", "")
|
| 121 |
+
|
| 122 |
+
result = evaluate(references, predictions, fold_geez=not args.no_fold)
|
| 123 |
+
print(json.dumps(result, indent=2))
|
| 124 |
+
if result["missing_predictions"]:
|
| 125 |
+
print(
|
| 126 |
+
f"\nWARNING: {result['missing_predictions']} of {result['clips']} test "
|
| 127 |
+
f"clips had no prediction and were scored as full deletions.",
|
| 128 |
+
file=sys.stderr,
|
| 129 |
+
)
|
| 130 |
+
return 0
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
if __name__ == "__main__":
|
| 134 |
+
raise SystemExit(main())
|