Instructions to use KrorngAI/TrorYongASR2-tiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use KrorngAI/TrorYongASR2-tiny with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="KrorngAI/TrorYongASR2-tiny")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("KrorngAI/TrorYongASR2-tiny", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 17,390 Bytes
35ad74c c388200 35ad74c c388200 35ad74c c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 9c4cc7f c388200 e6cd652 c388200 9c4cc7f c388200 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | ---
library_name: transformers
license: other
license_name: modified-mit
datasets:
- Digital-Divide-Data/khmer-speech-dataset
- openslr/librispeech_asr
- KrorngAI/openslr-librispeech_asr-clean100-00000-19999-km-translate
- KrorngAI/DDD-Cambodia-khmer-speech-dataset-parquet-000-159-en-translate
- W4ng1204/Nonspeech7k
language:
- km
- en
metrics:
- wer
- cer
- ter
pipeline_tag: automatic-speech-recognition
---
<div align="center">
<picture>
<img src="https://kimang18.github.io/krorngai-blog/logo_black_v2.png" width="30%" alt="KrorngAI">
</picture>
</div>
<hr>
<!--
<div align="center" style="line-height:1">
<a href="https://www.facebook.com/profile.php?id=61582509385293" target="_blank"><img alt="Homepage" src="https://img.shields.io/badge/Homepage-Krorng%20AI-white?logoColor=white"/></a>
</div>
-->
<div align="center" style="line-height: 1;">
<a href="https://huggingface.co/KrorngAI" target="_blank"><img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Krorng%20AI-ffc107?color=ffc107&logoColor=white"/></a>
<a href="https://youtube.com/@krorngai" target="_blank"><img alt="YouTube Channel" src="https://img.shields.io/badge/Youtube-Krorng%20AI-red?logoColor=red"/></a>
<a href="https://www.facebook.com/profile.php?id=61582509385293" target="_blank"><img alt="Homepage" src="https://img.shields.io/badge/Facebook-Krorng%20AI-blue?logoColor=blue"/></a>
<a href="https://kimang18.github.io" target="_blank"><img alt="Personal" src="https://img.shields.io/badge/KHUN-white?logoColor=white"/></a>
</div>
<div align="center" style="line-height: 1;">
<a href="https://huggingface.co/Kimang18/TrorYongASR2-tiny/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/License-Modified_MIT-f5de53?&color=f5de53"/></a>
</div>
# TrorYongASR2
> [!Note]
> This repository contains model weights and configuration files for the pre-trained model.
>
## Model Details
### Model Description
**TrorYongASR2**, an update to [TrorYongASR1](https://huggingface.co/KrorngAI/TrorYongASR-tiny), augments the auditory-lingual decoder to 1) improve speech-text alignment, 2) enhance the expressivity of rotary position embedding, 3) ameliorate the expressivity of multi-head attention, and 4) speed up training and inference times.
For speech-text alignment, Length-Aware RoPE (LARoPE) is implemented in the cross-attention to enhance monotonic structure alignment.
In addition, the lowest frequencies of RoPE in the context-position attention and LARoPE in speech-text alignment are removed to create robust semantic channels.
To improve multi-head attention, a gating mechanism is integrated in the self-attention and the cross-attention layers of the auditory-lingual decoder: apply a head-specific sigmoid gate after the scaled dot-product attention.
This introduces non-linearity upon the low-rank mapping in the softmax attention which mitigates 'massive activation' and 'attention sink'.
Finally, the auditory-lingual decoder adopts point-wise dynamic rescaled Gaussian cumulative distribution function (Derf) in place of normalization layers to save compute, hence accelerating training speed and inference process.
[Figure 1](#fig-archit) provides an overview of the TrorYongASR2's architecture.
<figure>
<div style="text-align: center;"><a name='fig-archit' ><img src="https://kimang18.github.io/krorngai-blog/TrorYongASR2/figures/architecture6.png" width="100%" /></a></div>
<figcaption>
Figure 1: TrorYongASR2 architecture. Dropout layers are omitted due to space constraints, [B], [L], [T], [E], and [P] are begin-of-sequence, language, task, end-of-sequence, and pad tokens respectively.
This figure presents the case having 16 distinct target prediction positions.
The auditory-lingual decoder is just a single normalization-free Transformer where the standard normalization layers are replaced by point-wise Dynamic rescaled Gaussian cumulative distribution function (Derf).
All projections in attention layers are explicitly shown here because specific to TrorYongASR2, the single position basis \\( \boldsymbol{p} \\) is used for each position to directly form query vectors (differently from the standard decoder, the linear layer for query projection is not required) while context vectors are the token embeddings multiplied by the position basis and are projected into key and value vectors.
With gated mechanism, masked multi-head attention (Masked MHA) generates gate score from context vectors while MHA for speech-text alignment computes gate score from the hidden state, the output of Masked MHA.
Inspired by QK-normalization, a Derf activation is applied to the query and key vectors of Masked MHA right before \\( p \\)-RoPE transformation.
For the cross-attention layer, the query and key vectors are transformed by first Derf and then \\( p \\)-LARoPE.
Attention masks are generated from randomly chosen permutations and are used only for the context-position attention.
The last linear layer outputs logits over the vocabulary set.
These logits are then used to compute cross-entropy loss.
The audio encoder is simply Whisper's Audio Encoder, but it can process audio of arbitrary length that is shorter than 30 seconds.</figcaption>
</figure>
- **Developed by:** KHUN Kimang (Ph.D.)
- **Shared by:** KrorngAI
- **Model type:** ASR (Automatic Speech Recognition)
- **Language(s) (NLP):** Khmer and English
### Model Sources
<!-- Provide the basic links for the model. -->
- **Blog Post:** [https://kimang18.github.io/krorngai-blog/TrorYongASR2/](https://kimang18.github.io/krorngai-blog/TrorYongASR2/)
- **Demo:** TBA
- **Repository:** https://github.com/Kimang18/KrorngAI/tree/main/tror-yong-asr
## Evaluation
### Dataset
The evaluation assesses transcription capability on two datasets: 1) [`google/fleurs`](https://huggingface.co/datasets/Kimang18/google-fleurs-km-kh) for Khmer and 2) [`openslr/librispeech_asr`](https://huggingface.co/datasets/openslr/librispeech_asr) for English.
All results are from the **test split** of each dataset.
| Dataset | Language | Testing samples | Description |
|-----------------------|------------|------------------|---------------------------------------------------|
| **google/fleurs** | Khmer | 765 | Multi-lingual dataset with Khmer language samples |
| **librispeech_asr.clean** | English | 2611 | Clean speech dataset for English transcription |
Audio longer than 30 seconds are excluded from the evaluation (that is why `google/fleurs` has 765 samples instead of 771 and `librispeech_asr.clean` has 2611 instead of 2620).
### Metrics
For transcription task, 3 metrics below are used
- **Token Error Rate (TER)**: Proportion of incorrectly predicted tokens
- **Character Error Rate (CER)**: Proportion of characters that are incorrect
- **Word Error Rate (WER)**: Proportion of words that are incorrect
TER measures model's capability in predicting the next token given the audio input and the current sequence of tokens.
This metric is weaker than WER and CER because it doesn't account for insertions, deletions, substitutions, and autoregression as comprehensively.
### Results
| Model | Metric | Khmer (`fleurs`) | English (`librispeech_asr.clean`) |
|-----------|--------|------------------|-------------------------------|
| **Tiny** | WER | 57.07% | 20.35% |
| | CER | 43.95% | 12.42% |
| | TER | 49% | 11% |
| **Small** | WER | 36.70% | 10.12% |
| | CER | 29.26% | 6.05% |
| | TER | 38% | 5% |
Both configurations performance well on English language.
However, Khmer language remains a challenge.
**Note:** To compute `CER` and `WER`, whitespaces are added between words in Khmer text (Khmer text does not have word boundaries like English text). To do so, `khmercut` PyPI package is used to tokenize Khmer text into words, and then the words are joined back together with whitespaces.
It is due to no-boundary Khmer words that Token Error Rate is utilized as one of the metrics.
**Comparison with TrorYongASR1 and Whisper:**
| Size | Model | Parameters | Khmer (`fleurs`) | English (`librispeech_asr.clean`) |
| -------- | ------------ | ---------- | --------------------------- | ----------------------------- |
| **Tiny** | **TrorYongASR2** | 29M | **57.07%** | 20.35% |
| | TrorYongASR1 | 29M | 75.88% | 54.33% |
| | Whisper | 39M | 100.6% | **7.6%** |
| | | | | |
| **Small**| **TrorYongASR2** | 136M | **36.70%** | 10.12% |
| | TrorYongASR1 | 135M | 50.46% | 21.75% |
| | Whisper | 244M | 104.4% | **3.4%** |
**Key Observations:**
- As mentioned above, TrorYongASR2 clearly outperforms TrorYongASR1 and requires just a small increase in the number of parameters (the increase comes from additional length predictor and gate projection layers)
- Whisper has the highest number of parameters for comparable configuration (39M vs 29M for `tiny`, and 244M vs 136M for `small`)
- Whisper shows significantly lower word error rates on English (7.6% for `tiny`, 3.4% for `small`)
- TrorYongASR2 performs best on Khmer dataset (57.07% for `tiny`, and 36.70% for `small`)
**Note:** `WER` data of Whisper is taken directly from their [paper](https://arxiv.org/abs/2212.04356).
**Note on Translation Task:** According to [KrorngAI](https://huggingface.co/KrorngAI), the 2 translation datasets above are built using the API of [TranslateKH](https://translatekh.mptc.gov.kh/) which, in turn, uses an AI model for the translation (Khmer to English and vice-versa).
Without any means to check the correctness of the translation over 209 hours of audio, TrorYongASR2 is not evaluated on any translation datasets.
It can be assumed that the translation performance of TrorYongASR2 is upper bounded by the AI model used in the backend of [TranslateKH](https://translatekh.mptc.gov.kh/).
## Training
TrorYongASR2 is trained on 5 datasets:
- 234 hours of `Digital-Divide-Data/khmer-speech-dataset` (the whole dataset contains 727.94 hours) for Khmer audio and Khmer text (transcription)
- `train.360` split of `openslr/librispeech_asr` for English audio and English text (transcription)
- `KrorngAI/DDD-Cambodia-khmer-speech-dataset-parquet-000-159-en-translate` for Khmer audio and English text (translation)
- `KrorngAI/openslr-librispeech_asr-clean100-00000-19999-km-translate` for English audio and Khmer text (translation)
- `nospeech7k` for no speech audio (voice activity detection)
So, there are around 804 hours of audio in the training dataset.
TrorYongASR2 has 2 configurations as the following
| **Model Size** | Tiny | Small |
|:-----------------:|:-----------------:|:-------------------:|
| **Audio Encoder** | 4 layers, 6 heads | 12 layers, 12 heads |
| **Audio Context** | 1500 | 1500 |
| **Auditory-lingual Decoder** | 1 layer, 12 heads | 1 layer, 24 heads |
| **Text Context** | 448 | 448 |
| **Embedding Dimension** | 384 | 768 |
| **Parameters** | 29M | 136M |
The audio array is processed to log-mel spectrogram with 80 mel bins (the same as Whisper models of the same size).
These configurations are the same as the ones of TrorYongASR1.
The training hyperparameters are listed below:
- **Training regime:** 16-mixed precision training using `LightningAI` package
- **Number of epochs:** roughly 2 epochs
- **Optimizer:** MuonAdamW (custom implementation [here](https://github.com/Kimang18/adam_muon_optimizer))
- **Effective Batch size:** 64
- **Number of optimizer steps:** 10149
- **Learning rate:** Linear Warmup (153 optimizer steps) + CosineAnnealing (9996 optimizer steps)
- **Gradient Clip Value:** 0.5 (only for parameters trained by AdamW)
To underline the gain from architectural improvement, TrorYongASR1 is retrained on the same 5 datasets above using the same set of hyperparameters.
[Figure 2](#fig-loss) shows the training history of `tiny` configuration.
TrorYongASR2 has smaller training and validation losses, and higher validation token accuracy.
This shows the effectiveness of the new architectural design in TrorYongASR2.
<figure>
<div style="text-align: center;"><a name='fig-loss' ><img src="https://kimang18.github.io/krorngai-blog/TrorYongASR2/figures/train_val.png" width="100%" /></a></div>
<figcaption>
Figure 2: Training history of TrorYongASR1 and TrorYongASR2 using the same training configuration.
TrorYongASR1 is represented by the blue color and TrorYongASR2 is represented by the red one.
The first row shows the training loss and the second one describes validation performance.
The top right plot shows the moving average of training loss.
All plots suggest that TrorYongASR2 has better performance compared to TrorYongASR1.
</figcaption>
</figure>
## How to Get Started with TrorYongASR2
First, install `tror-yong-asr` PyPI package:
```bash
pip install tror-yong-asr >= 0.2.0
```
Then, you can use TrorYongASR2 for `transcribe` or `translate` via the code below.
```python
from transformers import AutoProcessor
from tror_yong_asr import TrorYongASRModel, transcribe, translate, identify_language
model_id = "KrorngAI/TrorYongASR2-tiny"
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
model = TrorYongASRModel.from_pretrained(model_id, trust_remote_code=True)
result1 = identify_language('/path/to/audio_file.mp3', model, processor)
print(result1)
result2 = transcribe('/path/to/audio_file.mp3', model, processor, max_tokens=64)
print(result2)
result3 = translate('/path/to/audio_file.mp3', model, processor, max_tokens=64)
print(result3)
```
## Fine-tuning
You can follow this notebook below to learn to fine-tune TrorYongASR2.
[](https://colab.research.google.com/#fileId=https://huggingface.co/KrorngAI/TrorYongASR2-tiny/blob/main/fine_tune_TrorYongASR2.ipynb)
## Uses
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
### Direct Use
The model can be used directly for:
- **Speech-to-text transcription**: transcribe Khmer and English audio
- **Speech-to-text translation**: translate Khmer audio to English text and English audio to Khmer text
- **Language identification**: identify if the spoken language in the audio is Khmer or English
- **Edge computing**: Deploy on mobile devices, IoT devices, and embedded systems due to its small size (29M parameters for tiny or 136M for small)
- **Real-time applications**: Low latency inference suitable for real-time speech interfaces
### Downstream Use
The model can be integrated into:
- **Mobile applications**: Android/iOS apps with speech recognition
- **Web applications**: Browser-based speech-to-text using WebAssembly
- **IoT devices**: Smart speakers, voice assistants
- **Larger ASR systems**: As a component in multi-language ASR pipelines
## Bias, Risks, and Limitations
**Technical Limitations:**
- **No timestamp output**: The model does not support timestamp output
- **Noise robustness**: Performance may degrade in noisy environments
**Sociotechnical Limitations:**
- **Accent variability**: May not perform well on diverse Khmer accents
- **Background noise**: Limited robustness to background noise and reverberation
- **Speaker variability**: May struggle with different speaking styles and rates
## Citation
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
**BibTeX:**
```bibtex
@online{khun2026,
author = {Khun, Kimang},
title = {TrorYongASR2: {Permuted} {Language} {Modeling} with
{Monotonic} {Alignment,} {Gated} {Attention,} and
{Normalization-free} {Design}},
date = {2026-10-19},
url = {https://kimang18.github.io/krorngai-blog/TrorYongASR2/},
langid = {en}
}
```
## Model Card Author
- ឈ្មោះ: បណ្ឌិត ឃុន គីមអាង
- Name: KHUN Kimang (Ph.D.)
## Acknowledgement
Both models are trained thanks to the free credits from Kaggle, and `Google Colab`.
Thanks to [`KrorngAI`](https://huggingface.co/KrorngAI), [`openslr`](https://openslr.org), and [Mozilla Data Collective](https://mozilladatacollective.com/datasets/cml9h5vgc01bxmn075sjeftek) for their publicly available dataset.
## Model Card Contact
If you have any questions, please reach out at [Facebook Page](https://www.facebook.com/profile.php?id=61582509385293). |