Views
No views yet
| Dialect | Coverage |
|---|---|
| Egyptian Arabic | ✅ Primary |
| Modern Standard Arabic (MSA) | ✅ Supported |
| Gulf / Levantine | ✅ Supported |
1from transformers import pipeline
2
3asr = pipeline("automatic-speech-recognition", model="IbrahimAmin/egyptian-arabic-wav2vec2-xlsr-53")
4asr("path/to/audio.wav")
5
6# Long-Form Transcription: https://huggingface.co/blog/asr-chunking
7asr = pipeline("automatic-speech-recognition", model="IbrahimAmin/egyptian-arabic-wav2vec2-xlsr-53", chunk_length_s=30)
8asr("path/to/audio.wav")1from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
2import torch
3import torchaudio
4
5model = Wav2Vec2ForCTC.from_pretrained("IbrahimAmin/egyptian-arabic-wav2vec2-xlsr-53")
6processor = Wav2Vec2Processor.from_pretrained("IbrahimAmin/egyptian-arabic-wav2vec2-xlsr-53")
7
8# Load audio (must be mono, 16kHz)
9waveform, sr = torchaudio.load("path/to/audio.wav")
10
11# Convert to mono if not already
12if waveform.shape[0] > 1:
13 waveform = torch.mean(waveform, dim=0, keepdim=True)
14
15# Resample if needed to 16 kHz
16if sr != 16000:
17 resampler = torchaudio.transforms.Resample(orig_freq=sr, new_freq=16000)
18 waveform = resampler(waveform)
19
20inputs = processor(waveform.squeeze(), sampling_rate=16000, return_tensors="pt")
21
22with torch.inference_mode():
23 logits = model(**inputs).logits
24
25predicted_ids = torch.argmax(logits, dim=-1)
26transcription = processor.batch_decode(predicted_ids)
27print(transcription)1import torch
2import torchaudio
3import re
4from datasets import load_dataset
5from evaluate import load
6from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
7
8# Device setup
9device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
10
11# 🔑 Replace with your Hugging Face token and the desired Wav2Vec2-based model ID
12HF_TOKEN = "your_hf_token"
13MODEL_NAME = "your_model_name_or_path"
14
15# Load the Common Voice 17.0 Arabic test split
16test_dataset = load_dataset(
17 "mozilla-foundation/common_voice_17_0",
18 "ar",
19 split="test",
20 token=HF_TOKEN
21)
22
23# Load WER metric
24wer = load("wer")
25
26# Load processor and model
27processor = Wav2Vec2Processor.from_pretrained(MODEL_NAME, token=HF_TOKEN)
28model = Wav2Vec2ForCTC.from_pretrained(MODEL_NAME, token=HF_TOKEN).to(device)
29
30# Define regex for cleaning up unwanted characters
31CHARS_TO_IGNORE_REGEX = r'[\؛\—\_get\«\»\ـ\,\?\.\!\-\;\:"\“\%\‘\”\�\#\،\☭,\؟]'
32
33def preprocess(batch):
34 """Removes unwanted characters and resamples audio to 16kHz."""
35 batch["sentence"] = re.sub(CHARS_TO_IGNORE_REGEX, "", batch["sentence"])
36 speech_array, sampling_rate = torchaudio.load(batch["path"])
37 resampler = torchaudio.transforms.Resample(orig_freq=sampling_rate, new_freq=16_000)
38 batch["speech"] = resampler(speech_array).squeeze().numpy()
39 return batch
40
41# Apply preprocessing
42test_dataset = test_dataset.map(preprocess)
43
44def predict(batch):
45 """Runs inference and decodes predicted text."""
46 inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
47
48 with torch.inference_mode():
49 logits = model(
50 input_values=inputs["input_values"].to(device),
51 attention_mask=inputs["attention_mask"].to(device)
52 ).logits
53
54 predicted_ids = torch.argmax(logits, dim=-1)
55 batch["pred_strings"] = processor.batch_decode(predicted_ids)
56 return batch
57
58# Run prediction
59result = test_dataset.map(predict, batched=True, batch_size=8)
60
61# Compute and print Word Error Rate
62wer_score = wer.compute(predictions=result["pred_strings"], references=result["sentence"])
63print(f"WER: {wer_score * 100:.2f}%")| Model | WER (%) |
|---|---|
IbrahimAmin/egyptian-arabic-wav2vec2-xlsr-53 | 27.20 |
jonatasgrosman/wav2vec2-large-xlsr-53-arabic | 45.55 |
AndrewMcDowell/wav2vec2-xls-r-300m-arabic | 47.22 |
openai/whisper-large-v3* | 52.36 |
Ahmed107/hamsa-v0.6Q* | 53.27 |
nadsoft/hamsa-v0.1-beta* | 65.60 |
openai/whisper-medium* | 67.75 |
openai/whisper-small* | 74.16 |
omarxadel/wav2vec2-large-xlsr-53-arabic-egyptian | 91.82 |
arbml/wav2vec2-large-xlsr-53-arabic-egyptian | 93.92 |
mboushaba/whisper-large-v3-turbo-arabic* | 96.90 |
beam_size = 5) and evaluated using BasicTextNormalizer with remove_diacritics=False and split_letters=False, applied to both predictions and reference text.1@misc{amin2025egyptianasr,
2 title={Egyptian Arabic ASR with wav2vec2 XLSR 53},
3 author={Ibrahim Amin},
4 year={2025},
5 howpublished={\url{https://huggingface.co/IbrahimAmin/egyptian-arabic-wav2vec2-xlsr-53}},
6}