netra-karna 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. netra_karna-0.2.0/LICENSE +199 -0
  2. netra_karna-0.2.0/PKG-INFO +338 -0
  3. netra_karna-0.2.0/README.md +302 -0
  4. netra_karna-0.2.0/karna/__init__.py +30 -0
  5. netra_karna-0.2.0/karna/__main__.py +3 -0
  6. netra_karna-0.2.0/karna/asr.py +64 -0
  7. netra_karna-0.2.0/karna/audio.py +52 -0
  8. netra_karna-0.2.0/karna/cli.py +90 -0
  9. netra_karna-0.2.0/karna/inference/__init__.py +16 -0
  10. netra_karna-0.2.0/karna/inference/hub.py +101 -0
  11. netra_karna-0.2.0/karna/inference/recognizer.py +77 -0
  12. netra_karna-0.2.0/karna/inference/session.py +187 -0
  13. netra_karna-0.2.0/karna/models.py +78 -0
  14. netra_karna-0.2.0/karna/server/__init__.py +23 -0
  15. netra_karna-0.2.0/karna/server/app.py +132 -0
  16. netra_karna-0.2.0/karna/server/jobs.py +190 -0
  17. netra_karna-0.2.0/karna/server/settings.py +30 -0
  18. netra_karna-0.2.0/karna/server/static/app.css +100 -0
  19. netra_karna-0.2.0/karna/server/static/brand/symbol.svg +1 -0
  20. netra_karna-0.2.0/karna/server/static/brand/wordmark-latin.svg +7 -0
  21. netra_karna-0.2.0/karna/server/static/favicon.svg +1 -0
  22. netra_karna-0.2.0/karna/server/static/fonts/Figtree-latin.woff2 +0 -0
  23. netra_karna-0.2.0/karna/server/static/fonts/KantumruyPro-Bold.woff2 +0 -0
  24. netra_karna-0.2.0/karna/server/static/fonts/KantumruyPro-Regular.woff2 +0 -0
  25. netra_karna-0.2.0/karna/server/static/fonts/OFL-Figtree.txt +93 -0
  26. netra_karna-0.2.0/karna/server/static/fonts/OFL-KantumruyPro.txt +93 -0
  27. netra_karna-0.2.0/karna/server/static/index.html +71 -0
  28. netra_karna-0.2.0/karna/server/static/js/main.js +247 -0
  29. netra_karna-0.2.0/karna/server/static/js/record.js +54 -0
  30. netra_karna-0.2.0/karna/server/static/tokens.css +31 -0
  31. netra_karna-0.2.0/karna/text.py +100 -0
  32. netra_karna-0.2.0/karna/vocab.json +1 -0
  33. netra_karna-0.2.0/netra_karna.egg-info/PKG-INFO +338 -0
  34. netra_karna-0.2.0/netra_karna.egg-info/SOURCES.txt +42 -0
  35. netra_karna-0.2.0/netra_karna.egg-info/dependency_links.txt +1 -0
  36. netra_karna-0.2.0/netra_karna.egg-info/entry_points.txt +2 -0
  37. netra_karna-0.2.0/netra_karna.egg-info/requires.txt +23 -0
  38. netra_karna-0.2.0/netra_karna.egg-info/top_level.txt +1 -0
  39. netra_karna-0.2.0/pyproject.toml +53 -0
  40. netra_karna-0.2.0/setup.cfg +4 -0
  41. netra_karna-0.2.0/tests/test_api.py +83 -0
  42. netra_karna-0.2.0/tests/test_cli.py +35 -0
  43. netra_karna-0.2.0/tests/test_golden.py +19 -0
  44. netra_karna-0.2.0/tests/test_server.py +122 -0
@@ -0,0 +1,199 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+
177
+ Copyright 2026 Nhem Darayut
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License");
180
+ you may not use this file except in compliance with the License.
181
+ You may obtain a copy of the License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software
186
+ distributed under the License is distributed on an "AS IS" BASIS,
187
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
+ See the License for the specific language governing permissions and
189
+ limitations under the License.
190
+
191
+ --------------------------------------------------------------------------------
192
+ Third-party code
193
+
194
+ training/karna_train/hardconcrete.py is ported from DiariZen
195
+ (https://github.com/BUTSpeechFIT/DiariZen, diarizen/models/module/wav2vec2/hardconcrete.py),
196
+ released under the MIT License; see that repository for its copyright notice.
197
+
198
+ The model weights are derived from Meta's Omnilingual ASR CTC checkpoints
199
+ (https://github.com/facebookresearch/omnilingual-asr).
@@ -0,0 +1,338 @@
1
+ Metadata-Version: 2.4
2
+ Name: netra-karna
3
+ Version: 0.2.0
4
+ Summary: Compact Khmer and English speech recognition on ONNX Runtime: Omnilingual ASR CTC models structurally pruned to 80% sparsity.
5
+ Author-email: Nhem Darayut <darayutnhem009@gmail.com>
6
+ License: Apache-2.0
7
+ Project-URL: Repository, https://github.com/netra-ai-lab/Karna
8
+ Project-URL: Model Download, https://huggingface.co/Netra-Lab/karna-base
9
+ Project-URL: Docker, https://github.com/netra-ai-lab/Karna/pkgs/container/karna
10
+ Keywords: speech-recognition,asr,khmer,english,ctc,pruning,onnx,omnilingual-asr
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy
18
+ Requires-Dist: soundfile
19
+ Requires-Dist: soxr
20
+ Requires-Dist: huggingface_hub>=0.20
21
+ Provides-Extra: cpu
22
+ Requires-Dist: onnxruntime>=1.20; extra == "cpu"
23
+ Provides-Extra: gpu
24
+ Requires-Dist: onnxruntime-gpu>=1.20; extra == "gpu"
25
+ Provides-Extra: server
26
+ Requires-Dist: fastapi; extra == "server"
27
+ Requires-Dist: uvicorn[standard]; extra == "server"
28
+ Requires-Dist: python-multipart; extra == "server"
29
+ Provides-Extra: full
30
+ Requires-Dist: netra-karna[cpu,server]; extra == "full"
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest; extra == "dev"
33
+ Requires-Dist: httpx; extra == "dev"
34
+ Requires-Dist: build; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ <div align="center">
38
+ <img src="https://raw.githubusercontent.com/netra-ai-lab/Karna/master/assets/symbol.png" height="72" alt="Netra Lab" style="vertical-align: middle; margin-right: 24px;" />
39
+ <img src="https://raw.githubusercontent.com/netra-ai-lab/Karna/master/assets/wordmark-latin.png" height="56" alt="Netra" style="vertical-align: middle;" />
40
+ </div>
41
+
42
+ <hr>
43
+
44
+ <p align="center">
45
+ <a href="https://github.com/netra-ai-lab/Karna"><b>GitHub</b></a> |
46
+ <a href="https://github.com/netra-ai-lab/Karna/pkgs/container/karna"><b>Docker Image</b></a> |
47
+ <a href="https://pypi.org/project/netra-karna/"><b>PyPI</b></a> |
48
+ <a href="https://huggingface.co/Netra-Lab/karna-base"><b>Karna-base</b></a> |
49
+ <a href="https://huggingface.co/Netra-Lab/karna-large"><b>Karna-large</b></a> |
50
+ <a href="https://huggingface.co/Darayut/omniASR-CTC-1B-km-en"><b>Fine-tuned 1B</b></a> |
51
+ <a href="https://huggingface.co/Darayut/omniASR-CTC-300M-km-en"><b>Fine-tuned 300M</b></a> |
52
+ <a href="https://huggingface.co/datasets/Digital-Divide-Data/khmer-speech-dataset"><b>Khmer Dataset</b></a>
53
+ </p>
54
+
55
+ <p align="center">
56
+ <img src="https://img.shields.io/badge/license-Apache--2.0-e75f1b?labelColor=4f2724" alt="License: Apache-2.0" />
57
+ <img src="https://img.shields.io/badge/python-3.10%2B-e75f1b?labelColor=4f2724&logo=python&logoColor=f5efe5" alt="Python 3.10+" />
58
+ <a href="https://huggingface.co/Netra-Lab/karna-base"><img src="https://img.shields.io/badge/params-71M%20%7C%20217M-e75f1b?labelColor=4f2724&logo=huggingface&logoColor=f5efe5" alt="71M and 217M parameters" /></a>
59
+ <a href="https://pypi.org/project/netra-karna/"><img src="https://img.shields.io/badge/pypi-netra--karna-e75f1b?labelColor=4f2724&logo=pypi&logoColor=f5efe5" alt="PyPI: netra-karna" /></a>
60
+ <a href="https://github.com/netra-ai-lab/Karna/pkgs/container/karna"><img src="https://img.shields.io/badge/docker-ghcr.io-e75f1b?labelColor=4f2724&logo=docker&logoColor=f5efe5" alt="Docker image" /></a>
61
+ <img src="https://img.shields.io/badge/runs%20on-CPU,%20offline-e75f1b?labelColor=4f2724" alt="Runs on CPU, offline" />
62
+ </p>
63
+
64
+ <h2>
65
+ <p align="center">
66
+ Karna: Structured Pruning of Omnilingual ASR for Khmer and English
67
+ </p>
68
+ </h2>
69
+
70
+ <p align="center">
71
+ Khmer and English speech in, text out. Two compact models, 71M and 217M parameters, pruned from Meta's Omnilingual ASR.
72
+ </p>
73
+
74
+ <p align="center">
75
+ <img src="https://raw.githubusercontent.com/netra-ai-lab/Karna/master/assets/results.png" width="1000" alt="Test error of the stock, fine-tuned and pruned models at both sizes on DDD, FLEURS-km and LibriSpeech" />
76
+ </p>
77
+
78
+ <p align="center">
79
+ <em>Test error for each size: the stock Omnilingual model, our fine-tuned teacher and the pruned Karna model. Lower is better. On DDD, the pruned models beat both larger models; on LibriSpeech they keep 1.7–1.9× the teacher's error.</em>
80
+ </p>
81
+
82
+ ## 1. Abstract
83
+
84
+ This repository presents Karna, a pair of **71M- and 217M-parameter** CTC speech recognisers for Khmer and English. They are built by structurally pruning Meta's Omnilingual ASR CTC models (`omniASR_CTC_300M` and `omniASR_CTC_1B`) to **about 80% encoder sparsity**. The recipe follows *Fine-tune Before Structured Pruning*:
85
+ 1. The full model is fine-tuned on the target languages.
86
+ 2. Hard Concrete L0 gates remove attention heads and FFN units while the model is distilled to that fine-tuned teacher.
87
+ 3. The pruned model recovers with CTC plus distillation of the teacher's output distribution.
88
+
89
+ On the DDD test set, the 217M model reaches **1.33% CER**, against 1.22% for its 975M teacher and 5.95% for the stock 1B, at a quarter of the compute (12.9 against 50.3 GMAC per second of audio). The 71M model reaches **1.94% CER**, against its 325M teacher's 1.47%, at 5.8 GMAC/s. These are the v2 models; the first release and what changed are in [docs/RESULTS.md](docs/RESULTS.md).
90
+
91
+ ## 2. Dataset
92
+
93
+ Karna was trained on about **2,034 hours** of speech, mixed 50/50 between Khmer and English by audio seconds. FLEURS is fixed at 20% of each language's audio and repeated as needed.
94
+
95
+ ### Sources
96
+
97
+ | Dataset | Type | Size | Domains |
98
+ | :--- | :--- | ---: | :--- |
99
+ | [DDD Khmer Speech](https://huggingface.co/datasets/Digital-Divide-Data/khmer-speech-dataset) | Khmer speech | 1,058 h | Cambodian culture, 61 topics, native speakers |
100
+ | [FLEURS](https://huggingface.co/datasets/google/fleurs) km_kh train | Khmer read speech | 7.1 h | Wikipedia sentences |
101
+ | [LibriSpeech](https://www.openslr.org/12) train-clean-100 + 360 + other-500 | English read speech | 961 h | Audiobooks |
102
+ | [FLEURS](https://huggingface.co/datasets/google/fleurs) en_us train | English read speech | 7.5 h | Wikipedia sentences |
103
+ | **Total** | | **2,034 h** | |
104
+
105
+ ### Preprocessing
106
+
107
+ 1. **Held-out sets.** The DDD test set, a DDD dev pool and an exclude list are removed from DDD training at the shard-row level.
108
+ 2. **Duration filter.** Utterances shorter than 1 s or longer than 25 s are dropped.
109
+ 3. **Resampling.** Audio is resampled to 16 kHz mono, which affects some 48 kHz DDD rows.
110
+ 4. **Text normalisation.**
111
+ - NFC, with zero-width characters removed and whitespace collapsed; English is lowercased.
112
+ - Text is filtered to the Omnilingual character vocabulary, which has no Khmer punctuation such as `។`. This drops 1.2% of DDD characters.
113
+ 5. **Loudness normalisation.** Each utterance is normalised to zero mean and unit variance, as in Omnilingual ASR.
114
+
115
+ ## 3. Model Architecture
116
+
117
+ <p align="center">
118
+ <img src="https://raw.githubusercontent.com/netra-ai-lab/Karna/master/assets/architecture.png" width="420" alt="Karna's architecture, reading upwards from 16 kHz audio to the CTC head, with one transformer layer opened up" />
119
+ </p>
120
+
121
+ <p><em>Figure 1: The model, reading upwards, with one transformer layer opened up: 16 kHz audio, a feature extractor of 7 convolutional layers giving one frame every 20 ms, a convolutional position encoder added back to the frames, 48 pre-LayerNorm transformer layers of width 1,280, a final LayerNorm and a CTC head over 9,812 characters. Every attention head and every FFN unit has its own Hard Concrete gate z. The cells in the opened layer are layer 12 of karna-large: 11 of 16 heads and 3,788 of 5,120 FFN units kept; which ones are kept is schematic.</em></p>
122
+
123
+ **The base model.** A wav2vec2-style encoder:
124
+ - a 7-layer CNN feature extractor (20 ms frames);
125
+ - a convolutional position encoder;
126
+ - pre-LayerNorm transformer layers;
127
+ - a linear CTC head over Omnilingual's 9,812-character vocabulary.
128
+
129
+ **What pruning removes.** Each encoder layer keeps only the attention heads and FFN units that the L0 gates leave open, so every layer has its own width. The model dimension, the CNN front end and the CTC head stay intact.
130
+
131
+ <p align="center">
132
+ <img src="https://raw.githubusercontent.com/netra-ai-lab/Karna/master/assets/pruning.png" width="1000" alt="The fine-tuned omniASR CTC-1B before structured pruning and karna-large after: CNN and CTC head kept, attention heads and FFN units removed" />
133
+ </p>
134
+
135
+ <p><em>Figure 2: Structured pruning removes whole attention heads (MHA) and FFN units from every transformer layer, chosen by one Hard Concrete gate each; the CNN front end is kept. Each cell is a quarter of a layer's heads or FFN units: layer 12 of karna-large keeps 11 of 16 heads and 3,788 of 5,120 FFN units, and layer 40 keeps no heads and 264 FFN units. Training runs in five steps: fine-tune, prune, cut, distil with the mask frozen, and recover with CTC and logit distillation ([docs/DESIGN.md](docs/DESIGN.md)).</em></p>
136
+
137
+ <p align="center">
138
+ <img src="https://raw.githubusercontent.com/netra-ai-lab/Karna/master/assets/inference_time.png" width="560" alt="Inference time for 60 s of audio at 0% and 80% encoder sparsity, for the base and large models" />
139
+ </p>
140
+
141
+ <p><em>Figure 3: Inference time before and after pruning, for one 60 s utterance (batch 1, bf16, median of 20 runs on one machine; `training/scripts/07_time_inference.py`). At about 80% encoder sparsity karna-base runs 1.6× faster than its teacher and karna-large 2.2× faster. Over the batched test sets (the Speed column below) the speed-ups are 1.8× and 2.4×.</em></p>
142
+
143
+ | Feature | Detail |
144
+ | :--- | :--- |
145
+ | Pruned units | Attention heads and FFN intermediate units (Hard Concrete L0 gates) |
146
+ | Sparsity control | Augmented Lagrangian; target ramps 0 → 80% over the first 50% of Stage 2 |
147
+ | Distillation | L1 − cosine on hidden states at 5 layers (Stages 2 and 2b); frame-level KL on outputs (Stage 3) |
148
+ | Decoding | Greedy CTC, no language model |
149
+
150
+ | Hyperparameter | karna-base | karna-large |
151
+ | :--- | ---: | ---: |
152
+ | Pruned from | omniASR CTC-300M | omniASR CTC-1B |
153
+ | Encoder layers × model dim | 24 × 1024 | 48 × 1280 |
154
+ | Heads kept (of 384 / 768) | 91 | 198 |
155
+ | FFN units kept (of 98,304 / 245,760) | 11,740 | 41,045 |
156
+ | Encoder sparsity | 80.6% | 78.7% |
157
+ | Stage 1 / 2 / 2b / 3 steps | 62k / 12k / 5k / 24k | 62k / 12k / 5k / 24k |
158
+ | Compute (GMAC / s of audio) | 5.8 | 12.9 |
159
+ | Total parameters | 71M | 217M |
160
+
161
+ ## 4. Evaluation
162
+
163
+ | Model | Params | Speed | DDD (CER) | FLEURS-km (CER) | LibriSpeech (WER) |
164
+ | :--- | ---: | ---: | ---: | ---: | ---: |
165
+ | omniASR CTC-1B (stock) | 975M | 1.0× | 5.95 | 11.26 | 4.40 |
166
+ | Fine-tuned 1B (teacher) | 975M | 1.0× | 1.22 | 7.77 | 3.54 |
167
+ | **karna-large (ours)** | **217M** | **2.4×** | **1.33** | **10.20** | **5.44** |
168
+ | omniASR CTC-300M (stock) | 325M | 1.0× | 9.65 | 16.26 | 6.53 |
169
+ | Fine-tuned 300M (teacher) | 325M | 1.0× | 1.47 | 9.95 | 5.57 |
170
+ | **karna-base (ours)** | **71M** | **1.8×** | **1.94** | **15.20** | **10.96** |
171
+
172
+ - **Scoring.** Greedy decoding, error rates in %, on the full test sets:
173
+
174
+ | Test set | Utterances |
175
+ | :--- | ---: |
176
+ | DDD | 1,993 |
177
+ | FLEURS-km | 771 |
178
+ | LibriSpeech test-clean | 2,620 |
179
+
180
+ - **Speed.** Inference speed relative to the unpruned model of the same size, measured as the real-time factor on one machine.
181
+ - **In-domain.** FLEURS-km train is in the training mix, so its test set is in-domain.
182
+ - **Teachers.** The teachers here are the v2 fine-tuned models (a full pass over the training mix). The teachers on Hugging Face are still the first release's, which score 2.47 (1B) and 3.68 (300M) on DDD.
183
+ - **More results.** [docs/RESULTS.md](docs/RESULTS.md) adds FLEURS-en and LibriSpeech test-other, the first release against v2, and the ablations behind the recipe: pruning without fine-tuning first, and Stage 3 without distillation or with a shorter schedule.
184
+
185
+ ## 5. Quick start
186
+
187
+ The quickest way in is the Docker image: a web app and REST API with both models inside.
188
+
189
+ 1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) for Windows, Mac or Linux. In its settings, give it at least 4 GB of memory.
190
+ 2. Open a terminal (PowerShell on Windows, Terminal on Mac) and run:
191
+
192
+ ```bash
193
+ docker run -d --name karna -p 8000:8000 -v karna-data:/data ghcr.io/netra-ai-lab/karna
194
+ ```
195
+
196
+ 3. Open http://localhost:8000. Drop an audio file on the page, or record from the microphone.
197
+
198
+ > **The page won't open?** The app needs port 8000, which `-p 8000:8000` sets up. If you start the image from Docker Desktop's *Images* tab instead, open *Optional settings* and set *Host port* to `8000`. The models load in the background for the first few seconds, and the header says *Ready* once they have.
199
+
200
+ | | |
201
+ | :--- | :--- |
202
+ | Platforms | Windows and Linux PCs (x86-64) and ARM64, including Apple Silicon Macs |
203
+ | GPU | Not needed; runs on the CPU |
204
+ | Download | <!-- TODO: measure the pushed image (compressed / unpacked) -->, both models included |
205
+ | Memory | <!-- TODO: measure with docker stats (idle / transcribing with karna-large) --> |
206
+ | Speed | karna-base 8.7 s and karna-large 17.0 s per minute of audio (16-thread AMD Zen 3 laptop CPU, batch 8) |
207
+ | Internet | Not needed after the download. Audio never leaves your computer. |
208
+ | Input | wav, flac, ogg or mp3 of Khmer or English speech, up to 30 s per file |
209
+ | Output | Lowercase text without punctuation, as txt or json |
210
+
211
+ **Python package.** For scripts and pipelines, install from PyPI. Inference runs on [ONNX Runtime](https://onnxruntime.ai), so PyTorch isn't needed.
212
+
213
+ ```bash
214
+ pip install "netra-karna[cpu]" # or [gpu] for CUDA, [full] for the web app too
215
+ ```
216
+
217
+ | Extra | Adds |
218
+ | --- | --- |
219
+ | *(none)* | The `karna` library and command: numpy, soundfile, soxr, huggingface_hub. Add one runtime below. |
220
+ | `cpu` | ONNX Runtime for the CPU |
221
+ | `gpu` | ONNX Runtime with CUDA (instead of `cpu`) |
222
+ | `server` | The web app and REST API (`karna serve`): fastapi, uvicorn |
223
+ | `full` | `cpu` and `server` |
224
+
225
+ The first run downloads the ONNX model from [Hugging Face](https://huggingface.co/Netra-Lab/karna-base) and caches it under `~/.cache/huggingface` (`HF_HOME`): karna-base is 287 MB and karna-large 871 MB. `karna download` fetches them ahead of time, for offline use.
226
+
227
+ ## 6. Usage
228
+
229
+ **Python.** Two lines to a transcript. Load a model once, then transcribe files, arrays or batches of either.
230
+
231
+ ```python
232
+ import karna
233
+
234
+ asr = karna.load_model("karna-base") # or "karna-large", a Hugging Face id, a local folder
235
+ print(asr.transcribe("speech.wav")) # one file -> one string
236
+ print(asr.transcribe(["a.wav", "b.flac"])) # a list -> a list, batched
237
+ print(asr.transcribe((waveform, 44100))) # a numpy array with its sample rate
238
+ ```
239
+
240
+ **Command line.** Each file prints as one line: the path, a tab, then the text.
241
+
242
+ ```bash
243
+ karna transcribe speech.wav other.flac --model karna-large # --format txt|json, --device cpu|cuda
244
+ karna models # list the released models
245
+ karna download karna-base karna-large # fetch now, run offline later
246
+ karna serve --port 8000 # the web app and REST API ([server] extra)
247
+ ```
248
+
249
+ **REST API.** Upload, then poll, or wait for the text in one call. Interactive docs are at `http://localhost:8000/docs`.
250
+
251
+ ```bash
252
+ curl -F file=@speech.wav "http://localhost:8000/v1/transcribe?wait=true" # the finished job, with result.text
253
+ curl -F file=@speech.wav -F model=karna-large http://localhost:8000/v1/transcribe # -> 202, the queued job
254
+ curl http://localhost:8000/v1/jobs/<id> # until "status": "done"
255
+ curl -o speech.txt "http://localhost:8000/v1/jobs/<id>/export?format=txt" # or json
256
+ ```
257
+
258
+ | Setting | Default | Meaning |
259
+ | :--- | :--- | :--- |
260
+ | `KARNA_API_KEY` | *(unset)* | Require `X-API-Key` / `Authorization: Bearer` on `/v1/*`. Set it before exposing the port beyond your machine. |
261
+ | `KARNA_MODEL` | `karna-base` | The model loaded at start; the other loads on first use |
262
+ | `KARNA_MAX_SECONDS` | `30` | Longer audio is refused with HTTP 422 |
263
+
264
+ [docs/USAGE.md](docs/USAGE.md) lists every flag, route, environment variable and device.
265
+
266
+ **Train it yourself.** One script runs the whole recipe: data, conversion, fine-tune, prune, distil, recover, evaluate and export to ONNX. It resumes where it stopped. Training is a separate package in `training/`, with PyTorch.
267
+
268
+ ```bash
269
+ pip install -e . -e training # or: bash training/setup.sh
270
+ cp training/local.env.example training/local.env # point it at your data
271
+ training/run.sh base # or: training/run.sh large
272
+ ```
273
+
274
+ | Reference | |
275
+ | --- | --- |
276
+ | [Usage](docs/USAGE.md) | Python API, CLI flags, REST routes, environment variables, devices |
277
+ | [Training](docs/TRAINING.md) | `run.sh` step by step, data layout, environment variables, checkpoints and resuming |
278
+ | [Design](docs/DESIGN.md) | The pruning recipe, each decision and how it departs from DiariZen, the code map |
279
+ | [Results](docs/RESULTS.md) | All test and dev numbers, the ablations, the pruning run step by step |
280
+ | [Releasing](docs/RELEASING.md) | Exporting to ONNX, uploading, PyPI and Docker releases |
281
+
282
+ ## 7. Limitations
283
+
284
+ - **English is the weak side.** Pruning to about 80% costs English far more than Khmer, at 1.5–2× the teacher's WER. Use `karna-large`, or a fine-tuned teacher, when English accuracy matters.
285
+ - **No punctuation or casing.** Output is lowercase with no punctuation, because the Omnilingual character vocabulary has no Khmer punctuation.
286
+ - **Greedy decoding only.** There is no language model or beam search.
287
+ - **One pass per file.** Each file is decoded in a single pass, so split long recordings into utterances first. Training used clips of 1–25 s, and the web app and REST API refuse files over 30 s (`KARNA_MAX_SECONDS`).
288
+ - **Two languages only.** The models were trained and tested on Khmer and English only; other languages Omnilingual supports will have degraded.
289
+ - **The Khmer corpus is a manual download.** [DDD](https://huggingface.co/datasets/Digital-Divide-Data/khmer-speech-dataset) is public, but `training/run.sh` doesn't fetch it, and it reads DDD through its own shard index (see [docs/TRAINING.md](docs/TRAINING.md)).
290
+
291
+ ## 8. Licensing
292
+
293
+ This project is released under the Apache License 2.0 (see [LICENSE](LICENSE)); [THIRD_PARTY_LICENSES.md](THIRD_PARTY_LICENSES.md) lists what it builds on.
294
+ - **Weights:** derived from Meta's Omnilingual ASR CTC models, released under Apache 2.0.
295
+ - **`training/karna_train/hardconcrete.py`:** ported from DiariZen, which is MIT-licensed.
296
+ - **Training data:** DDD is CC BY-SA 4.0 ([Digital Divide Data](https://huggingface.co/datasets/Digital-Divide-Data/khmer-speech-dataset)), LibriSpeech is CC BY 4.0, and FLEURS is CC BY 4.0.
297
+
298
+ ## References
299
+
300
+ 1. **Omnilingual ASR: Open-Source Multilingual Speech Recognition for 1600+ Languages**
301
+ *Omnilingual ASR team, Meta AI*
302
+ 2025.
303
+ [facebookresearch/omnilingual-asr](https://github.com/facebookresearch/omnilingual-asr)
304
+
305
+ 2. **Fine-tune Before Structured Pruning: Towards Compact and Accurate Self-Supervised Models for Speaker Diarization**
306
+ *Jiangyu Han et al.*
307
+ Interspeech 2025.
308
+ [arXiv:2505.24111](https://arxiv.org/abs/2505.24111)
309
+
310
+ 3. **Efficient and Generalizable Speaker Diarization via Structured Pruning of Self-Supervised Models**
311
+ *Jiangyu Han et al.*
312
+ 2025.
313
+ [arXiv:2506.18623](https://arxiv.org/abs/2506.18623)
314
+
315
+ 4. **DPHuBERT: Joint Distillation and Pruning of Self-Supervised Speech Models**
316
+ *Yifan Peng, Yui Sudo, Shakeel Muhammad, Shinji Watanabe*
317
+ Interspeech 2023.
318
+ [arXiv:2305.17651](https://arxiv.org/abs/2305.17651)
319
+
320
+ 5. **Learning Sparse Neural Networks through L0 Regularization**
321
+ *Christos Louizos, Max Welling, Diederik P. Kingma*
322
+ ICLR 2018.
323
+ [arXiv:1712.01312](https://arxiv.org/abs/1712.01312)
324
+
325
+ 6. **FLEURS: Few-shot Learning Evaluation of Universal Representations of Speech**
326
+ *Alexis Conneau et al.*
327
+ SLT 2022.
328
+ [arXiv:2205.12446](https://arxiv.org/abs/2205.12446)
329
+
330
+ 7. **LibriSpeech: an ASR corpus based on public domain audio books**
331
+ *Vassil Panayotov, Guoguo Chen, Daniel Povey, Sanjeev Khudanpur*
332
+ ICASSP 2015.
333
+ [OpenSLR 12](https://www.openslr.org/12)
334
+
335
+ 8. **Khmer ASR Cultural Dataset**
336
+ *Digital Divide Data*
337
+ Hugging Face Datasets.
338
+ [Digital-Divide-Data/khmer-speech-dataset](https://huggingface.co/datasets/Digital-Divide-Data/khmer-speech-dataset)