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