This model is a fine-tuned version of
facebook/wav2vec2-xls-r-300m on the spanish common_voice dataset thanks to the GPU credits generously given by the OVHcloud for the Speech Recognition challenge.
It achieves the following results on the evaluation set
The model can be used with n-gram (n=5) included in the processor as follows.
1import re
2from transformers import AutoModelForCTC,Wav2Vec2ProcessorWithLM
3import torch
4
5# Loading model and processor
6processor = Wav2Vec2ProcessorWithLM.from_pretrained("polodealvarado/xls-r-300m-es")
7model = AutoModelForCTC.from_pretrained("polodealvarado/xls-r-300m-es")
8
9# Cleaning characters
10def remove_extra_chars(batch):
11 chars_to_ignore_regex = '[^a-záéíóúñ ]'
12 text = batch["translation"][target_lang]
13 batch["text"] = re.sub(chars_to_ignore_regex, "", text.lower())
14 return batch
15
16# Preparing dataset
17def prepare_dataset(batch):
18 audio = batch["audio"]
19 batch["input_values"] = processor(audio["array"], sampling_rate=audio["sampling_rate"],return_tensors="pt",padding=True).input_values[0]
20 with processor.as_target_processor():
21 batch["labels"] = processor(batch["sentence"]).input_ids
22 return batch
23
24
25common_voice_test = load_dataset("mozilla-foundation/common_voice_8_0", "es", split="test",use_auth_token=True)
26common_voice_test = common_voice_test.remove_columns(["accent", "age", "client_id", "down_votes", "gender", "locale", "segment", "up_votes"])
27common_voice_test = common_voice_test.cast_column("audio", Audio(sampling_rate=16_000))
28common_voice_test = common_voice_test.map(remove_extra_chars, remove_columns=dataset.column_names)
29common_voice_test = common_voice_test.map(prepare_dataset)
30
31# Testing first sample
32inputs = torch_tensor(common_voice_test[0]["input_values"])
33
34with torch.no_grad():
35 logits = model(inputs).logits
36
37pred_ids = torch.argmax(logits, dim=-1)
38text = processor.batch_decode(logits.numpy()).text
39print(text) # 'bien y qué regalo vas a abrir primero'
40
1
2# To use GPU: --device 0
3
4$ python eval.py --model_id polodealvarado/xls-r-300m-es --dataset mozilla-foundation/common_voice_8_0 --config es --device 0 --split test
5