othrif commited on
Commit
321b578
1 Parent(s): dee4b00

save model card

Browse files

Files changed (1) hide show
  1. README.md +53 -0
README.md CHANGED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: ar
3
+ datasets:
4
+ - https://arabicspeech.org/
5
+ tags:
6
+ - audio
7
+ - automatic-speech-recognition
8
+ - speech
9
+ - xlsr-fine-tuning-week
10
+ license: apache-2.0
11
+ model-index:
12
+ - name: XLSR Wav2Vec2 Egyptian by Zaid Alyafeai and Othmane Rifki
13
+ results:
14
+ - task:
15
+ name: Speech Recognition
16
+ type: automatic-speech-recognition
17
+ dataset:
18
+ name: arabicspeech.org MGB-3
19
+ type: arabicspeech.org MGB-3
20
+ args: {lang_id}
21
+ metrics:
22
+ - name: Test WER
23
+ type: wer
24
+ value: 55.2
25
+ ---
26
+ # Wav2Vec2-Large-XLSR-53-Arabic
27
+ Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) in Egyptian using the [arabicspeech.org MGB-3](https://arabicspeech.org/mgb3-asr/)
28
+ When using this model, make sure that your speech input is sampled at 16kHz.
29
+ ## Usage
30
+ The model can be used directly (without a language model) as follows:
31
+ ```python
32
+ import torch
33
+ import torchaudio
34
+ from datasets import load_dataset
35
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
36
+ dataset = load_dataset("arabic_speech_corpus", split="test")
37
+ processor = Wav2Vec2Processor.from_pretrained("othrif/wav2vec_test")
38
+ model = Wav2Vec2ForCTC.from_pretrained("othrif/wav2vec_test")
39
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
40
+ # Preprocessing the datasets.
41
+ # We need to read the aduio files as arrays
42
+ def speech_file_to_array_fn(batch):
43
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
44
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
45
+ return batch
46
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
47
+ inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
48
+ with torch.no_grad():
49
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
50
+ predicted_ids = torch.argmax(logits, dim=-1)
51
+ print("Prediction:", processor.batch_decode(predicted_ids))
52
+ print("Reference:", test_dataset["sentence"][:2])
53
+ ```