Darayut commited on
Commit
538019e
·
verified ·
1 Parent(s): 238579e

karna-char8: character 8-gram LM for Karna beam search

Browse files
Files changed (4) hide show
  1. README.md +117 -0
  2. assets/header.png +0 -0
  3. karna-char8.json +226 -0
  4. karna-char8.npz +3 -0
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-sa-4.0
3
+ language:
4
+ - km
5
+ - en
6
+ library_name: karna
7
+ tags:
8
+ - language-model
9
+ - n-gram
10
+ - character-level
11
+ - kneser-ney
12
+ - ctc-beam-search
13
+ - speech-recognition
14
+ - khmer
15
+ - english
16
+ - netra-lab
17
+ ---
18
+
19
+ <p align="center">
20
+ <img src="https://huggingface.co/Netra-Lab/karna-lm/resolve/main/assets/header.png" width="260" alt="Netra Lab" />
21
+ </p>
22
+
23
+ <hr>
24
+
25
+ <p align="center">
26
+ <a href="https://github.com/netra-ai-lab/Karna"><b>GitHub</b></a> |
27
+ <a href="https://pypi.org/project/netra-karna/"><b>PyPI</b></a> |
28
+ <a href="https://huggingface.co/Netra-Lab/karna-base"><b>Karna-base</b></a> |
29
+ <a href="https://huggingface.co/Netra-Lab/karna-large"><b>Karna-large</b></a>
30
+ </p>
31
+
32
+ # karna-lm
33
+
34
+ **A character language model of Khmer and English, for beam-search decoding of the Karna speech recognisers.** It is an interpolated modified Kneser-Ney character 8-gram, stored as numpy arrays (65 MB) and read by the `netra-karna` package with no other dependency. Fused into CTC prefix beam search, it lowers the error of [karna-base](https://huggingface.co/Netra-Lab/karna-base) and [karna-large](https://huggingface.co/Netra-Lab/karna-large) on read, noisy, far-field and live speech.
35
+
36
+ ## Results
37
+
38
+ CER for Khmer, WER for English, in %, lower is better; greedy decoding against beam search with this model. The sets are real-world proxies (`scripts/realworld_eval.py` in the GitHub repo): other recordings than the training data, and FLEURS-km / LibriSpeech test-other with background noise, reverberation, a far-field room, or a telephone channel. The beam settings were tuned on separate dev sets only.
39
+
40
+ | Set | karna-base greedy | karna-base + LM | karna-large greedy | karna-large + LM |
41
+ |---|---:|---:|---:|---:|
42
+ | OpenSLR 42 Khmer (test half), CER | 11.3 | **8.5** | 9.1 | **8.2** |
43
+ | kmcorpus (spontaneous Khmer), CER | 39.7 | **38.7** | 37.0 | **36.9** |
44
+ | FLEURS-km, CER | 15.5 | **13.0** | 10.5 | **9.2** |
45
+ | FLEURS-km + noise, CER | 29.7 | **25.6** | 19.1 | **17.2** |
46
+ | FLEURS-km far-field, CER | 60.7 | **56.1** | 47.6 | **46.1** |
47
+ | LibriSpeech test-other, WER | 23.3 | **17.4** | 13.3 | **11.0** |
48
+ | test-other + noise, WER | 40.9 | **33.0** | 24.9 | **20.6** |
49
+ | test-other telephone, WER | 44.6 | **36.7** | 26.1 | **21.8** |
50
+
51
+ - **Live transcription** (finals decoded with the beam, together with a more sensitive endpointer in `netra-karna` 1.2): karna-large on streamed FLEURS-km went from 10.7 to 9.4 CER (far-field 57.5 to 45.8), and on noisy English from 21.4 to 14.6 WER.
52
+ - **Cost:** 3–8 ms of one CPU core per second of audio, against about 145 ms for karna-base's network on a laptop CPU.
53
+ - **Where it doesn't help:** Common Voice Khmer (12 clips) went from 3.3 to 3.6 CER with karna-large.
54
+ - **Perplexity:** 2.06 bits per character on FLEURS-km dev, 1.99 on DDD dev, 2.80 on OpenSLR 42, 2.48 on kmcorpus, 1.88 on LibriSpeech dev-clean and 2.04 on FLEURS-en dev.
55
+
56
+ ## Usage
57
+
58
+ `netra-karna` 1.3 and later download this model on first load and use it for every transcription; `KARNA_LM=none` turns it off.
59
+
60
+ ```bash
61
+ pip install "netra-karna[cpu]"
62
+ ```
63
+
64
+ ```python
65
+ import karna
66
+
67
+ asr = karna.load_model("karna-large") # also fetches karna-lm once (65 MB)
68
+ asr.transcribe("audio.wav") # beam search with the LM
69
+ asr.transcribe("audio.wav", decoder="greedy") # without it
70
+ ```
71
+
72
+ With `netra-karna` 1.2, download it and point `KARNA_LM` at it:
73
+
74
+ ```bash
75
+ huggingface-cli download Netra-Lab/karna-lm --local-dir karna-lm
76
+ KARNA_LM=karna-lm/karna-char8.npz karna transcribe audio.wav --model karna-large
77
+ ```
78
+
79
+ The beam settings tuned for each Karna model are in `karna-char8.json` (`"beam"`) and are read from there.
80
+
81
+ ## How it was made
82
+
83
+ `scripts/build_char_lm.py` in the GitHub repo:
84
+
85
+ 1. **Text:** 124 M Khmer and 52 M English characters, sampled to a quota per source and deduplicated (sources below).
86
+ 2. **Normalisation:** the characters the Karna models can write, lowercased; one byte per character.
87
+ 3. **Held-out text removed:** every line sharing a 20-character span with an evaluation sentence (FLEURS, DDD dev and test, OpenSLR 42, kmcorpus, Common Voice, LibriSpeech dev and test, the golden test clips). This dropped 22 k lines of the parallel corpus, which contains FLoRes sentences.
88
+ 4. **Counts:** an 8-gram with interpolated modified Kneser-Ney smoothing; n-grams of orders 4–8 seen at most 1–4 times are pruned. 13.9 M n-grams are kept. Built in 134 s.
89
+
90
+ | Source | Language | Characters used |
91
+ |---|---|---:|
92
+ | Khmer web-text corpus | Khmer | 70.0 M |
93
+ | Khmer ASR text corpus | Khmer | 23.6 M |
94
+ | Khmer side of a Khmer–English parallel corpus | Khmer | 20.0 M |
95
+ | [DDD Khmer speech dataset](https://huggingface.co/datasets/Digital-Divide-Data/khmer-speech-dataset) train transcripts | Khmer | 9.1 M |
96
+ | [LibriSpeech](https://www.openslr.org/12) 960 h transcripts | English | 35.0 M |
97
+ | English side of the parallel corpus | English | 16.2 M |
98
+
99
+ ## Files
100
+
101
+ | File | Contents |
102
+ |---|---|
103
+ | `karna-char8.npz` | the model: per order, sorted uint64 n-gram keys with float16 log-probabilities and backoff weights, and a JSON header |
104
+ | `karna-char8.json` | the build manifest (sources, counts, discounts, perplexities, sha256) and the tuned beam settings per Karna model |
105
+ | `assets/` | the figure on this card |
106
+
107
+ ## Learn more
108
+
109
+ | | |
110
+ |---|---|
111
+ | [Usage](https://github.com/netra-ai-lab/Karna/blob/master/docs/USAGE.md#decoding) | Decoding options, `KARNA_LM`, building and tuning your own model |
112
+ | [Results](https://github.com/netra-ai-lab/Karna/blob/master/docs/RESULTS.md) | The real-world proxies in full (§8) |
113
+ | [Issues](https://github.com/netra-ai-lab/Karna/issues) | Bug reports and questions |
114
+
115
+ ## License
116
+
117
+ CC BY-SA 4.0. The model is derived from text including the DDD transcripts (CC BY-SA 4.0, whose ShareAlike terms carry over) and LibriSpeech (CC BY 4.0).
assets/header.png ADDED
karna-char8.json ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "sources": {
3
+ "ddd_train": {
4
+ "language": "km",
5
+ "quota_chars": 40000000,
6
+ "keep_probability": 0.773,
7
+ "lines": 451760,
8
+ "kept": 89375,
9
+ "chars": 9108644,
10
+ "sampled_out": 102281,
11
+ "foreign": 936,
12
+ "duplicate": 189111,
13
+ "eval_overlap": 70056,
14
+ "empty": 1,
15
+ "seconds": 5.7,
16
+ "description": "DDD Khmer speech dataset, train transcripts (CC BY-SA 4.0)"
17
+ },
18
+ "khmer_web": {
19
+ "language": "km",
20
+ "quota_chars": 70000000,
21
+ "keep_probability": 0.1381,
22
+ "lines": 4454652,
23
+ "kept": 573574,
24
+ "chars": 70000050,
25
+ "sampled_out": 3840346,
26
+ "foreign": 8552,
27
+ "duplicate": 115,
28
+ "eval_overlap": 32025,
29
+ "empty": 40,
30
+ "seconds": 15.8,
31
+ "description": "Khmer web-text corpus"
32
+ },
33
+ "khmer_asr_text": {
34
+ "language": "km",
35
+ "quota_chars": 25000000,
36
+ "keep_probability": 0.1119,
37
+ "lines": 2081979,
38
+ "kept": 202847,
39
+ "chars": 23605962,
40
+ "sampled_out": 1849117,
41
+ "foreign": 8401,
42
+ "duplicate": 131,
43
+ "eval_overlap": 21452,
44
+ "empty": 31,
45
+ "seconds": 6.2,
46
+ "description": "Khmer ASR text corpus"
47
+ },
48
+ "mt_khmer": {
49
+ "language": "km",
50
+ "quota_chars": 20000000,
51
+ "keep_probability": 0.0606,
52
+ "lines": 3809145,
53
+ "kept": 172116,
54
+ "chars": 20000165,
55
+ "sampled_out": 3577987,
56
+ "foreign": 8457,
57
+ "duplicate": 28614,
58
+ "eval_overlap": 21969,
59
+ "empty": 2,
60
+ "seconds": 16.4,
61
+ "description": "Khmer side of a Khmer-English parallel corpus"
62
+ },
63
+ "libri960": {
64
+ "language": "en",
65
+ "quota_chars": 60000000,
66
+ "keep_probability": 0.7095,
67
+ "lines": 281241,
68
+ "kept": 197883,
69
+ "chars": 35008883,
70
+ "sampled_out": 81670,
71
+ "foreign": 0,
72
+ "duplicate": 73,
73
+ "eval_overlap": 1614,
74
+ "empty": 1,
75
+ "seconds": 4.1,
76
+ "description": "LibriSpeech 960 h transcripts (CC BY 4.0)"
77
+ },
78
+ "mt_english": {
79
+ "language": "en",
80
+ "quota_chars": 30000000,
81
+ "keep_probability": 0.035,
82
+ "lines": 4314210,
83
+ "kept": 139156,
84
+ "chars": 16196729,
85
+ "sampled_out": 4163730,
86
+ "foreign": 8109,
87
+ "duplicate": 2772,
88
+ "eval_overlap": 386,
89
+ "empty": 57,
90
+ "seconds": 15.6,
91
+ "description": "English side of the Khmer-English parallel corpus"
92
+ }
93
+ },
94
+ "prune": [
95
+ 0,
96
+ 0,
97
+ 0,
98
+ 1,
99
+ 1,
100
+ 2,
101
+ 3,
102
+ 4
103
+ ],
104
+ "orders": {
105
+ "8": {
106
+ "unique": 28159380,
107
+ "kept": 3829172,
108
+ "discounts": [
109
+ 0.711,
110
+ 1.063,
111
+ 1.363
112
+ ],
113
+ "seconds": 9.6
114
+ },
115
+ "7": {
116
+ "unique": 17741088,
117
+ "kept": 3714885,
118
+ "discounts": [
119
+ 0.786,
120
+ 1.147,
121
+ 1.408
122
+ ],
123
+ "seconds": 9.1
124
+ },
125
+ "6": {
126
+ "unique": 9643199,
127
+ "kept": 3175746,
128
+ "discounts": [
129
+ 0.74,
130
+ 1.132,
131
+ 1.43
132
+ ],
133
+ "seconds": 7.7
134
+ },
135
+ "5": {
136
+ "unique": 4079290,
137
+ "kept": 2264454,
138
+ "discounts": [
139
+ 0.676,
140
+ 1.099,
141
+ 1.485
142
+ ],
143
+ "seconds": 6.3
144
+ },
145
+ "4": {
146
+ "unique": 1122546,
147
+ "kept": 737779,
148
+ "discounts": [
149
+ 0.614,
150
+ 1.031,
151
+ 1.436
152
+ ],
153
+ "seconds": 5.2
154
+ },
155
+ "3": {
156
+ "unique": 168310,
157
+ "kept": 168310,
158
+ "discounts": [
159
+ 0.547,
160
+ 1.028,
161
+ 1.481
162
+ ],
163
+ "seconds": 4.5
164
+ },
165
+ "2": {
166
+ "unique": 9689,
167
+ "kept": 9689,
168
+ "discounts": [
169
+ 0.464,
170
+ 0.933,
171
+ 1.588
172
+ ],
173
+ "seconds": 2.4
174
+ },
175
+ "1": {
176
+ "unique": 125,
177
+ "kept": 125,
178
+ "discounts": [
179
+ 0.5,
180
+ 1.0,
181
+ 1.5
182
+ ],
183
+ "seconds": 1.7
184
+ }
185
+ },
186
+ "gram_exclusion": [
187
+ 20,
188
+ 10
189
+ ],
190
+ "built": "2026-11-26 21:59:37",
191
+ "seed": 20261126,
192
+ "quota_scale": 1.0,
193
+ "file": "karna-char8.npz",
194
+ "bytes": 64867092,
195
+ "sha256": "c03e509d626e2245af83791acbd7171cfe833e7d40432de9b910980b968ef2cc",
196
+ "bits_per_char": {
197
+ "fleurs_km_dev": 2.0592,
198
+ "ddd_dev": 1.9872,
199
+ "test_slr42": 2.8043,
200
+ "test_kmcorpus": 2.4773,
201
+ "libri_dev-clean": 1.8814,
202
+ "fleurs_en_dev": 2.0366
203
+ },
204
+ "seconds": 134,
205
+ "beam": {
206
+ "karna-base": {
207
+ "lm_weight": 0.5,
208
+ "insertion_bonus": 2.5,
209
+ "insertion_bonus_latin": 0.5,
210
+ "beam": 8
211
+ },
212
+ "karna-large": {
213
+ "lm_weight": 0.5,
214
+ "insertion_bonus": 1.0,
215
+ "insertion_bonus_latin": 0.5,
216
+ "beam": 8
217
+ },
218
+ "default": {
219
+ "lm_weight": 0.5,
220
+ "insertion_bonus": 1.0,
221
+ "insertion_bonus_latin": 0.5,
222
+ "beam": 8
223
+ }
224
+ },
225
+ "beam_tuning": "scripts/tune_lm.py on the dev sets of scripts/realworld_eval.py (slr42_dev, kmcorpus_dev, FLEURS-km dev and LibriSpeech dev-clean under clean/noise/far), 2026-11-26: the lowest mean error relative to greedy among settings no worse than greedy on any dev set"
226
+ }
karna-char8.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c03e509d626e2245af83791acbd7171cfe833e7d40432de9b910980b968ef2cc
3
+ size 64867092