Automatic Speech Recognition
Transformers
Safetensors
Malagasy
wav2vec2-bert
speech
malagasy
madagascar
w2v-bert-2.0
ctc
low-resource
african-languages
Eval Results (legacy)
Run this model with HF Jobs
Run Flo976/w2v-bert-malagasy on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Flo976/w2v-bert-malagasy. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Flo976/w2v-bert-malagasy on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use Flo976/w2v-bert-malagasy with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Flo976/w2v-bert-malagasy with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="Flo976/w2v-bert-malagasy")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForCTC processor = AutoProcessor.from_pretrained("Flo976/w2v-bert-malagasy") model = AutoModelForCTC.from_pretrained("Flo976/w2v-bert-malagasy", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Publication initiale
Browse filesFiles changed (8)
- README.mdAdded+221
- added_tokens.jsonAdded+4
- config.jsonAdded+81
- model.safetensorsAdded+3
- preprocessor_config.jsonAdded+11
- special_tokens_map.jsonAdded+30
- tokenizer_config.jsonAdded+49
- vocab.jsonAdded+43
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221---language:- mglicense: cc-by-4.0library_name: transformerspipeline_tag: automatic-speech-recognitionbase_model: badrex/w2v-bert-2.0-malagasy-asrdatasets:- badrex/malagasy-speech-fullmetrics:- wer- certags:- automatic-speech-recognition- speech- malagasy- madagascar- w2v-bert-2.0- ctc- low-resource- african-languagesmodel-index:- name: w2v-bert-malagasy results: - task: type: automatic-speech-recognition name: Speech Recognition dataset: name: Malagasy Speech Full — test, short utterances (2–8 s) type: badrex/malagasy-speech-full split: test metrics: - type: wer value: 13.40 name: WER (KenLM 4-gram + apostrophe rule) - type: wer value: 14.33 name: WER (greedy) - type: cer value: 3.76 name: CER (greedy) - task: type: automatic-speech-recognition name: Speech Recognition dataset: name: Malagasy Speech Full — test, full-length clips type: badrex/malagasy-speech-full split: test metrics: - type: wer value: 10.60 name: WER (KenLM 4-gram) - type: wer value: 12.01 name: WER (greedy) - type: cer value: 2.85 name: CER (greedy)---
# w2v-BERT 2.0 — Malagasy speech recognition, robust on short utterances
**13.4 % word error rate on short Malagasy utterances (2–8 s), against 21.5 % for a Whisper medium fine-tuned on the same data** — and 5× faster on GPU.
This CTC model transcribes Malagasy speech. It is built for voice assistants and dictation, where speech arrives as short segments cut by voice-activity detection. Most Malagasy ASR models are trained and measured on 15–30 s recordings, and make about 65 % more errors on short segments; this one was trained on both.
**Try it:** [Flo976/malagasy-asr-demo](https://huggingface.co/spaces/Flo976/malagasy-asr-demo) · **Language model:** [Flo976/malagasy-kenlm-4gram](https://huggingface.co/Flo976/malagasy-kenlm-4gram)
> **Résumé en français.** Modèle de reconnaissance vocale malgache (w2v-BERT 2.0, CTC), entraîné pour rester fiable sur les énoncés courts d'un assistant vocal. Sur 11 625 énoncés de 2 à 8 s jamais vus à l'entraînement, il fait 13,4 % d'erreurs de mots avec le modèle de langue, contre 21,5 % pour un Whisper medium fine-tuné sur les mêmes données, et répond 5 fois plus vite. Il ne régresse pas sur les extraits longs (10,6 %). Sortie en minuscules, sans ponctuation.
## Results
### Short utterances (2–8 s) — the voice-assistant regime
11,625 utterances (16.0 h, 94 speakers), cut from the test split by forced alignment at word boundaries. No test speaker appears in training.
| Model | Decoding | WER | CER || --- | --- | --- | --- || **this model** | KenLM 4-gram + apostrophe rule | **13.40 %** | 3.74 % || **this model** | KenLM 4-gram | 13.63 % | 3.76 % || **this model** | greedy | 14.33 % | 3.76 % || [badrex/w2v-bert-2.0-malagasy-asr](https://huggingface.co/badrex/w2v-bert-2.0-malagasy-asr) | KenLM 4-gram | 17.77 % | 5.45 % || [badrex/w2v-bert-2.0-malagasy-asr](https://huggingface.co/badrex/w2v-bert-2.0-malagasy-asr) | greedy | 19.87 % | 5.79 % || [Flo976/whisper-malagasy-medium](https://huggingface.co/Flo976/whisper-malagasy-medium) | greedy | 21.49 % | 8.97 % |
Each comparison quoted on this card is significant at 95 % (paired bootstrap on the same utterances, 2,000 resamples). Against the Whisper medium, this model gains 8.1 points (95 % CI [−8.64, −7.64]). At equal decoding this model beats its starting point badrex by 5.5 points greedy (95 % CI [−5.76, −5.34]) and by 4.1 points with the language model ([−4.34, −3.93]).
WER by utterance length, greedy decoding:
| Length | Utterances | this model | badrex | Whisper medium (Flo976) || --- | --- | --- | --- | --- || under 3 s | 587 | **17.4 %** | 27.3 % | 32.4 % || 3–5 s | 4,363 | **14.6 %** | 20.1 % | 21.6 % || 5–8 s | 6,675 | **14.1 %** | 19.4 % | 21.0 % |
### Full-length clips — no regression
The 3,101 original test clips (16.5 h, median 18 s).
| Model | Decoding | WER | CER || --- | --- | --- | --- || **this model** | KenLM 4-gram | **10.60 %** | 2.65 % || badrex/w2v-bert-2.0-malagasy-asr | KenLM 4-gram | 10.86 % | 2.67 % || **this model** | greedy | 12.01 % | 2.85 % || badrex/w2v-bert-2.0-malagasy-asr | greedy | 12.20 % | 2.88 % || Flo976/whisper-malagasy-medium | greedy | 13.07 % | 3.48 % |
### Speed
One utterance at a time (2–8 s), as a voice assistant receives them:
| Model | Hardware | Median latency | 90th percentile || --- | --- | --- | --- || this model, greedy | RTX 5070 Ti | 52 ms | 65 ms || this model, with KenLM | RTX 5070 Ti | 74 ms | 92 ms || Whisper medium (Flo976) | RTX 5070 Ti | 259 ms | 648 ms || this model, greedy | 2 CPU cores (Intel Core Ultra 7 265K) | 1.45 s | 1.53 s |
A CTC model reads the audio in one pass; Whisper writes its output token by token, so its latency grows with the sentence. On CPU the acoustic model dominates: the language model adds no measurable time. Set PyTorch's thread count to the cores actually allotted (`torch.set_num_threads`): in a container, the default host count oversubscribes the CPU and triples latency.
## Usage
Output is lowercase, without punctuation, with numbers written as digits. Audio must be 16 kHz mono.
### Greedy decoding
```pythonimport librosaimport torchfrom transformers import AutoModelForCTC, AutoProcessor
processor = AutoProcessor.from_pretrained("Flo976/w2v-bert-malagasy")model = AutoModelForCTC.from_pretrained("Flo976/w2v-bert-malagasy").eval()
audio, _ = librosa.load("audio.wav", sr=16000, mono=True)inputs = processor(audio, sampling_rate=16000, return_tensors="pt")with torch.no_grad(): logits = model(**inputs).logitsprint(processor.batch_decode(logits.argmax(-1))[0])```
### With the Malagasy language model (recommended)
```bashpip install pyctcdecode https://github.com/kpu/kenlm/archive/master.zip```
```pythonimport refrom huggingface_hub import hf_hub_downloadfrom pyctcdecode import build_ctcdecoder
tok = processor.tokenizervocab = tok.get_vocab()labels = ["" if t == tok.pad_token else " " if t == tok.word_delimiter_token else "⁇" if t == tok.unk_token else t for t in sorted(vocab, key=vocab.get)]lm_repo = "Flo976/malagasy-kenlm-4gram"unigrams = [w.strip() for w in open(hf_hub_download(lm_repo, "unigrams.txt"), encoding="utf-8") if w.strip()]decoder = build_ctcdecoder(labels, kenlm_model_path=hf_hub_download(lm_repo, "mg_4gram.bin"), unigrams=unigrams, alpha=0.3, beta=-1.0) # beta=0.0 for clips over 10 s
text = decoder.decode(logits[0].numpy(), beam_width=100)text = re.sub(r"'\s+", "'", re.sub(r"\s+'", "'", text)) # "amin' ny" -> "amin'ny"print(text)```
The parameters were tuned on the validation split: α = 0.3 with β = −1.0 for utterances of 10 s or less, β = 0.0 for longer clips. A spell-checking pass on top of the language model was measured and **hurts** (+0.17 point); it helps only without the language model (−0.38 point).
Recordings longer than about 30 s are best split at pauses; see `app.py` in the demo for a simple approach.
## Training
| | || --- | --- || Starting point | [badrex/w2v-bert-2.0-malagasy-asr](https://huggingface.co/badrex/w2v-bert-2.0-malagasy-asr), itself fine-tuned from [facebook/w2v-bert-2.0](https://huggingface.co/facebook/w2v-bert-2.0) || Data | train split of [badrex/malagasy-speech-full](https://huggingface.co/datasets/badrex/malagasy-speech-full): 28,168 full clips (147.7 h) + 105,284 short segments (144.0 h) cut from those same clips || Short segments | CTC forced alignment of the reference transcript, cut at word boundaries into 2–8 s pieces || Objective | CTC, character vocabulary (a–z, 0–9, apostrophe, hyphen) || Schedule | learning rate 1e-5, cosine, 500 warm-up steps; up to 400 s of audio per optimizer step || Regularization | SpecAugment, time mask 0.05, feature mask 0.10 || Precision | bfloat16, gradient checkpointing || Length | best checkpoint at step 3,200 (0.65 epoch); stopped at step 4,800 after four evaluations without improvement || Hardware | one RTX 5070 Ti (16 GB), about 3.5 hours |
The gain comes from the short segments: continuing badrex's training on full-length clips alone, with the same recipe, gave no improvement on validation over 0.75 epoch.
## Evaluation protocol
- **Speaker-disjoint splits**: 56 speakers in train, 95 in validation, 94 in test, no overlap (verified).- **Shared normalization** of references and hypotheses: Unicode NFC, lowercase, punctuation removed, apostrophes and hyphens kept inside words.- **Choices on validation only**: checkpoint selection, language-model parameters (tuned on half the speakers, checked on the other half) and post-processing rules. The test split was used once per frozen configuration.- **Significance**: paired bootstrap on the same utterances; a difference is reported only when its 95 % confidence interval excludes zero.
## Limitations
- **Short utterances are a proxy.** They are cut from read descriptions of images, not conversational speech captured by a microphone and a voice-activity detector. Results on real assistant traffic may differ.- **Segment boundaries come from badrex's alignment**, which may slightly favour models of the same family over Whisper on the short-utterance set.- **Under 3 s remains the weakest regime**: 15.9 % WER with the language model.- **Single training run**: run-to-run variance was not measured.- **Domain and dialect**: the training data is read speech, mostly official Malagasy (Merina). Coastal dialects and noisy environments are not evaluated.- **No punctuation or casing**, numbers as digits.
## License and attribution
This model is released under **CC-BY-4.0**. It is a derivative of [badrex/w2v-bert-2.0-malagasy-asr](https://huggingface.co/badrex/w2v-bert-2.0-malagasy-asr) by Badr al-Absi (CC-BY-4.0), itself derived from [facebook/w2v-bert-2.0](https://huggingface.co/facebook/w2v-bert-2.0) (MIT). Please credit both when you reuse it.
The training data, [badrex/malagasy-speech-full](https://huggingface.co/datasets/badrex/malagasy-speech-full), does not declare a license or a source on the Hub. The language model is published separately under CC-BY-SA-3.0, because it is built from Malagasy Wikipedia.
## Citation
```bibtex@misc{w2v-bert-malagasy-2026, author = {Florent Didelot}, title = {w2v-BERT 2.0 for Malagasy speech recognition, robust on short utterances}, year = {2026}, publisher = {Hugging Face}, url = {https://huggingface.co/Flo976/w2v-bert-malagasy}}```
Developed for [Milo Voice](https://github.com/Flo976/milo), a Malagasy voice assistant, by [Flo976](https://huggingface.co/Flo976) — Florent Didelot / [Sooatek](https://sooatek.com). Questions and feedback, especially from native speakers, are welcome in the [discussions](https://huggingface.co/Flo976/w2v-bert-malagasy/discussions).1234{ "</s>": 42, "<s>": 41}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081{ "activation_dropout": 0.0, "adapter_act": "relu", "adapter_kernel_size": 3, "adapter_stride": 2, "add_adapter": true, "apply_spec_augment": false, "architectures": [ "Wav2Vec2BertForCTC" ], "attention_dropout": 0.0, "bos_token_id": 1, "classifier_proj_size": 768, "codevector_dim": 768, "conformer_conv_dropout": 0.1, "contrastive_logits_temperature": 0.1, "conv_depthwise_kernel_size": 31, "ctc_loss_reduction": "mean", "ctc_zero_infinity": true, "diversity_loss_weight": 0.1, "dtype": "float32", "eos_token_id": 2, "feat_proj_dropout": 0.0, "feat_quantizer_dropout": 0.0, "feature_projection_input_dim": 160, "final_dropout": 0.1, "hidden_act": "swish", "hidden_dropout": 0.0, "hidden_size": 1024, "initializer_range": 0.02, "intermediate_size": 4096, "layer_norm_eps": 1e-05, "layerdrop": 0.0, "left_max_position_embeddings": 64, "mask_feature_length": 10, "mask_feature_min_masks": 0, "mask_feature_prob": 0.1, "mask_time_length": 10, "mask_time_min_masks": 2, "mask_time_prob": 0.05, "max_source_positions": 5000, "model_type": "wav2vec2-bert", "num_adapter_layers": 1, "num_attention_heads": 16, "num_codevector_groups": 2, "num_codevectors_per_group": 320, "num_hidden_layers": 24, "num_negatives": 100, "output_hidden_size": 1024, "pad_token_id": 40, "position_embeddings_type": "relative_key", "proj_codevector_dim": 768, "right_max_position_embeddings": 8, "rotary_embedding_base": 10000, "tdnn_dilation": [ 1, 2, 3, 1, 1 ], "tdnn_dim": [ 512, 512, 512, 512, 1500 ], "tdnn_kernel": [ 5, 3, 3, 1, 1 ], "transformers_version": "4.57.1", "use_intermediate_ffn_before_adapter": false, "use_weighted_layer_sum": false, "vocab_size": 43, "xvector_output_dim": 512}123version https://git-lfs.github.com/spec/v1oid sha256:274fa482f420b8fb6aa16ab01a00d8bd6ca37bb28e7a197f2116b80fff45502esize 24229950601234567891011{ "feature_extractor_type": "SeamlessM4TFeatureExtractor", "feature_size": 80, "num_mel_bins": 80, "padding_side": "right", "padding_value": 1, "processor_class": "Wav2Vec2BertProcessor", "return_attention_mask": true, "sampling_rate": 16000, "stride": 2}123456789101112131415161718192021222324252627282930{ "bos_token": { "content": "<s>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "eos_token": { "content": "</s>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "pad_token": { "content": "[PAD]", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false }, "unk_token": { "content": "[UNK]", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849{ "added_tokens_decoder": { "39": { "content": "[UNK]", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": false }, "40": { "content": "[PAD]", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": false }, "41": { "content": "<s>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "42": { "content": "</s>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true } }, "bos_token": "<s>", "clean_up_tokenization_spaces": false, "do_lower_case": false, "eos_token": "</s>", "extra_special_tokens": {}, "model_max_length": 1000000000000000019884624838656, "pad_token": "[PAD]", "processor_class": "Wav2Vec2BertProcessor", "replace_word_delimiter_char": " ", "target_lang": null, "tokenizer_class": "Wav2Vec2CTCTokenizer", "unk_token": "[UNK]", "word_delimiter_token": "|"}12345678910111213141516171819202122232425262728293031323334353637383940414243{ "'": 1, "-": 2, "0": 3, "1": 4, "2": 5, "3": 6, "4": 7, "5": 8, "6": 9, "7": 10, "8": 11, "9": 12, "[PAD]": 40, "[UNK]": 39, "a": 13, "b": 14, "c": 15, "d": 16, "e": 17, "f": 18, "g": 19, "h": 20, "i": 21, "j": 22, "k": 23, "l": 24, "m": 25, "n": 26, "o": 27, "p": 28, "q": 29, "r": 30, "s": 31, "t": 32, "u": 33, "v": 34, "w": 35, "x": 36, "y": 37, "z": 38, "|": 0}README.mdAdded+221
added_tokens.jsonAdded+4
config.jsonAdded+81
model.safetensorsAdded+3
preprocessor_config.jsonAdded+11
special_tokens_map.jsonAdded+30
tokenizer_config.jsonAdded+49
vocab.jsonAdded+43