Arabic Phoneme ASR v3 (wav2vec2 + CTC)
This model listens to Arabic speech and writes down the sounds (phonemes) it hears, not the words. It is built for Modern Standard Arabic and Quranic recitation, and is useful for pronunciation checking.
v3 was trained starting from the previous version (v2) in this repo.
If you still need v2, load it with revision="v2":
Wav2Vec2ForCTC.from_pretrained("MostafaMaroof/wav2vec2-arabic-phoneme-asr", revision="v2")
What is new in v3
- Cleaner output. v2 put a
|between every phoneme. v3 outputs the phonemes only, separated by spaces. - Cleaner training data. 3,353 clips whose transcript did not match the audio were removed (for example, a 4-sound label on a clip that contains a whole verse).
- More robust training. During training the audio was randomly sped up or slowed down, had light noise added, and had short parts masked, so the model copes better with different voices and recordings.
- Training data used: Arabic Speech Corpus (3.5 hours) and Iqra_train (75.1 hours, after cleaning).
Results
PER is the percentage of phonemes the model gets wrong. Lower is better. Both models were tested the same way, so v2's numbers here are lower than on its old card, which had a decoding bug.
| Test set | Clips | v2 | v3 |
|---|---|---|---|
iqra_dev | 2,588 | 10.97% | 9.33% |
asc_test | 95 | 4.40% | 3.41% |
- iqra_dev is the main test. Its transcripts were generated automatically, so a few of them are wrong, and some of the "errors" counted here are really mistakes in the transcript.
- asc_test is studio-quality speech. v2 saw these clips during training, so treat this number as a rough guide.
How to use
import torch, soundfile as sf
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
repo = "MostafaMaroof/wav2vec2-arabic-phoneme-asr"
processor = Wav2Vec2Processor.from_pretrained(repo)
model = Wav2Vec2ForCTC.from_pretrained(repo).eval()
id2tok = {i: t for t, i in processor.tokenizer.get_vocab().items()}
skip = {"|", "[UNK]", "[PAD]", "<s>", "</s>"}
audio, sr = sf.read("sample.wav", dtype="float32") # 16 kHz, mono
inputs = processor(audio, sampling_rate=16000, return_tensors="pt")
with torch.no_grad():
ids = model(**inputs).logits.argmax(-1)[0].tolist()
phonemes, prev = [], None
for i in ids:
if i != prev and id2tok[i] not in skip:
phonemes.append(id2tok[i])
prev = i
print(" ".join(phonemes))
Important: read the output token by token as shown above. The usual processor.batch_decode joins the phonemes without spaces (f ii h becomes fiih).
If you run several clips of different lengths in one batch, cut each output to its real length before reading it:
model._get_feat_extract_output_lengths(attention_mask.sum(-1)).
Limitations
- Works on Modern Standard Arabic and Quranic-style reading. Dialects and casual speech are not supported.
- Most remaining mistakes are short vowels (fatha, kasra, damma).
- The output is a phoneme sequence in the Halabi style, not Arabic text.
Training
- Base model:
facebook/wav2vec2-large-xlsr-53, continued from v2. - 16,086 training steps, about 2 minutes of audio per step, learning rate 5e-5 decreasing to zero.
- One Kaggle T4 GPU, about 6 hours.