fr dataset:common_voice audio automatic-speech-recognition speech xlsr-fine-tuning-week license:apache-2.0
.gitattributes README.md v0.1/config.json v0.1/preprocessor_config.json v0.1/pytorch_model.bin v0.1/special_tokens_map.json v0.1/tokenizer_config.json v0.1/vocab.json v1.0/config.json v1.0/preprocessor_config.json v1.0/pytorch_model.bin v1.0/results.txt v1.0/special_tokens_map.json v1.0/text.txt v1.0/tokenizer_config.json v1.0/trans.txt v1.0/vocab.json v2.0/config.json v2.0/preprocessor_config.json v2.0/pytorch_model.bin v2.0/results.txt v2.0/special_tokens_map.json v2.0/text.txt v2.0/tokenizer_config.json v2.0/trans.txt v2.0/vocab.json v3.0/config.json v3.0/preprocessor_config.json v3.0/pytorch_model.bin v3.0/results.txt v3.0/special_tokens_map.json v3.0/text.txt v3.0/tokenizer_config.json v3.0/trans.txt v3.0/vocab.json
---
language: fr
datasets:
- common_voice
tags:
- audio
- automatic-speech-recognition
- speech
- xlsr-fine-tuning-week
license: apache-2.0
model-index:
- name: wav2vec2-large-xlsr-53-French by Ilyes Rebai
  results:
  - task: 
      name: Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: Common Voice
      args: fr
    metrics:
       - name: Test WER
         type: wer
         value:  20.89%
---
## Evaluation on Common Voice FR Test
The script used for training and evaluation can be found here: https://github.com/irebai/wav2vec2


```python
import torch
import torchaudio
from datasets import load_dataset, load_metric
from transformers import (
    Wav2Vec2ForCTC,
    Wav2Vec2Processor,
)
import re

model_name = "Ilyes/wav2vec2-large-xlsr-53-french"



model = Wav2Vec2ForCTC.from_pretrained(model_name).to('cuda')
processor = Wav2Vec2Processor.from_pretrained(model_name)

ds = load_dataset("common_voice", "fr", split="test", cache_dir="./data/fr")



chars_to_ignore_regex = '[\,\?\.\!\;\:\"\“\%\‘\”\�\‘\’\’\’\‘\…\·\!\ǃ\?\«\‹\»\›“\”\\ʿ\ʾ\„\∞\\|\.\,\;\:\*\—\–\─\―\_\/\:\ː\;\,\=\«\»\→]'
def map_to_array(batch):
    speech, _ = torchaudio.load(batch["path"])
    batch["speech"] = resampler.forward(speech.squeeze(0)).numpy()
    batch["sampling_rate"] = resampler.new_freq
    batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().replace("’", "'")
    return batch
    
ds = ds.map(map_to_array)

resampler = torchaudio.transforms.Resample(48_000, 16_000)
def map_to_pred(batch):
    features = processor(batch["speech"], sampling_rate=batch["sampling_rate"][0], padding=True, return_tensors="pt")
    input_values = features.input_values.to(device)
    attention_mask = features.attention_mask.to(device)
    with torch.no_grad():
        logits = model(input_values, attention_mask=attention_mask).logits
    pred_ids = torch.argmax(logits, dim=-1)
    batch["predicted"] = processor.batch_decode(pred_ids)
    batch["target"] = batch["sentence"]
    return batch
    
result = ds.map(map_to_pred, batched=True, batch_size=16, remove_columns=list(ds.features.keys()))
wer = load_metric("wer")
print(wer.compute(predictions=result["predicted"], references=result["target"]))
```

## Results

# v0.1

WER=18.29%

SER=71.44%

# v1.0

WER=15.97%

CER=5.51%

# v2.0

WER=14.71%

CER=5.06%

# v3.0

WER=12.82%

CER=4.40%
