File size: 8,403 Bytes
5048e2a
177496d
 
472e548
42c5749
e559bdc
177496d
 
 
 
 
 
 
 
 
 
5048e2a
177496d
 
 
 
 
 
 
757523a
177496d
 
 
 
 
d6330eb
177496d
e782413
177496d
 
 
 
757523a
177496d
d6330eb
177496d
 
 
d6330eb
177496d
e782413
177496d
 
 
 
 
 
 
 
 
 
d6330eb
177496d
 
 
 
 
 
 
 
 
 
 
 
d6330eb
177496d
 
 
 
 
 
 
 
 
 
 
 
d6330eb
177496d
 
 
 
 
 
 
 
d6330eb
177496d
 
 
d6330eb
177496d
 
5048e2a
177496d
 
6ea2ed4
177496d
35d19d3
177496d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4aa20a
177496d
 
 
 
 
 
6f22a10
177496d
393d908
177496d
 
6f22a10
177496d
 
478b2d8
6f22a10
177496d
 
6f22a10
177496d
 
6f22a10
 
 
 
 
 
177496d
6f22a10
177496d
 
 
 
6f22a10
 
 
 
 
 
 
 
 
177496d
 
 
6f22a10
 
 
 
 
 
 
177496d
 
6f22a10
 
177496d
478b2d8
177496d
 
 
 
 
 
 
29953ad
177496d
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
---
language: es
datasets:
- ciempiess/ciempiess_light
- ciempiess/ciempiess_balance
- ciempiess/ciempiess_fem
- common_voice
- hub4ne_es_LDC98S74
- callhome_es_LDC96S35
tags:
- audio
- automatic-speech-recognition
- spanish
- xlrs-53-spanish
- ciempiess
- cimpiess-unam
license: cc-by-4.0
model-index:
- name: wav2vec2-large-xlsr-53-spanish-ep5-944h
  results:
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: Mozilla Common Voice 10.0 (Test)
      type: mozilla-foundation/common_voice_10_0
      split: test
      args: 
        language: es
    metrics:
    - name: WER
      type: wer
      value: 9.20
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: Mozilla Common Voice 10.0 (Dev)
      type: mozilla-foundation/common_voice_10_0
      split: validation
      args: 
        language: es
    metrics:
    - name: WER
      type: wer
      value: 8.02
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: CIEMPIESS-TEST
      type: ciempiess/ciempiess_test
      split: test
      args: 
        language: es
    metrics:
    - name: WER
      type: wer
      value: 11.17
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: 1997 Spanish Broadcast News Speech (HUB4-NE)
      type: HUB4NE_LDC98S74
      split: test
      args: 
        language: es
    metrics:
    - name: WER
      type: wer
      value: 7.48
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: CALLHOME Spanish Speech (Test)
      type: callhome_LDC96S35
      split: test
      args: 
        language: es
    metrics:
    - name: WER
      type: wer
      value: 39.12
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: CALLHOME Spanish Speech (Dev)
      type: callhome_LDC96S35
      split: validation
      args: 
        language: es
    metrics:
    - name: WER
      type: wer
      value: 40.39
---

# wav2vec2-large-xlsr-53-spanish-ep5-944h
**Paper:** [The state of end-to-end systems for Mexican Spanish speech recognition](http://journal.sepln.org/sepln/ojs/ojs/index.php/pln/article/viewFile/6485/3892)

The "wav2vec2-large-xlsr-53-spanish-ep5-944h" is an acoustic model suitable for Automatic Speech Recognition in Spanish. It is the result of fine-tuning the model "facebook/wav2vec2-large-xlsr-53" for 5 epochs with around 944 hours of Spanish data gathered or developed by the [CIEMPIESS-UNAM Project](https://huggingface.co/ciempiess) since 2012. Most of the data is available at the the CIEMPIESS-UNAM Project homepage http://www.ciempiess.org/. The rest can be found in public repositories such as [LDC](https://www.ldc.upenn.edu/) or [OpenSLR](https://openslr.org/)

The specific list of corpora used to fine-tune the model is:

- [CIEMPIESS-LIGHT (18h25m)](https://catalog.ldc.upenn.edu/LDC2017S23)
- [CIEMPIESS-BALANCE (18h20m)](https://catalog.ldc.upenn.edu/LDC2018S11)
- [CIEMPIESS-FEM (13h54m)](https://catalog.ldc.upenn.edu/LDC2019S07)
- [CHM150 (1h38m)](https://catalog.ldc.upenn.edu/LDC2016S04)
- [TEDX_SPANISH (24h29m)](https://openslr.org/67/)
- [LIBRIVOX_SPANISH (73h01m)](https://catalog.ldc.upenn.edu/LDC2020S01)
- [WIKIPEDIA_SPANISH (25h37m)](https://catalog.ldc.upenn.edu/LDC2021S07)
- [VOXFORGE_SPANISH (49h42m)](http://www.voxforge.org/es)
- [MOZILLA COMMON VOICE 10.0 (320h22m)](https://commonvoice.mozilla.org/es)
- [HEROICO (16h33m)](https://catalog.ldc.upenn.edu/LDC2006S37)
- [LATINO-40 (6h48m)](https://catalog.ldc.upenn.edu/LDC95S28)
- [CALLHOME_SPANISH (13h22m)](https://catalog.ldc.upenn.edu/LDC96S35)
- [HUB4NE_SPANISH (31h41m)](https://catalog.ldc.upenn.edu/LDC98S74)
- [FISHER_SPANISH (127h22m)](https://catalog.ldc.upenn.edu/LDC2010S01)
- [Chilean Spanish speech data set (7h08m)](https://openslr.org/71/)
- [Colombian Spanish speech data set (7h34m)](https://openslr.org/72/)
- [Peruvian Spanish speech data set (9h13m)](https://openslr.org/73/)
- [Argentinian Spanish speech data set (8h01m)](https://openslr.org/61/)
- [Puerto Rico Spanish speech data set (1h00m)](https://openslr.org/74/)
- [MediaSpeech Spanish (10h00m)](https://openslr.org/108/)
- [DIMEX100-LIGHT (6h09m)](https://turing.iimas.unam.mx/~luis/DIME/CORPUS-DIMEX.html)
- [DIMEX100-NIÑOS (08h09m)](https://turing.iimas.unam.mx/~luis/DIME/CORPUS-DIMEX.html)
- [GOLEM-UNIVERSUM (00h10m)](https://turing.iimas.unam.mx/~luis/DIME/CORPUS-DIMEX.html)
- [GLISSANDO (6h40m)](https://glissando.labfon.uned.es/es)
- TELE_con_CIENCIA (28h16m) **Unplished Material**
- UNSHAREABLE MATERIAL (118h22m) **Not available for sharing**
	
The fine-tuning process was performed during November (2022) in the servers of the Language and Voice Lab (https://lvl.ru.is/) at Reykjavík University (Iceland) by Carlos Daniel Hernández Mena.

# Evaluation
```python
import torch
from transformers import Wav2Vec2Processor
from transformers import Wav2Vec2ForCTC

#Load the processor and model.
MODEL_NAME="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-spanish-ep5-944h"
processor = Wav2Vec2Processor.from_pretrained(MODEL_NAME)
model = Wav2Vec2ForCTC.from_pretrained(MODEL_NAME)

#Load the dataset
from datasets import load_dataset, load_metric, Audio
ds=load_dataset("ciempiess/ciempiess_test", split="test")

#Downsample to 16kHz
ds = ds.cast_column("audio", Audio(sampling_rate=16_000))

#Process the dataset
def prepare_dataset(batch):
    audio = batch["audio"]
    #Batched output is "un-batched" to ensure mapping is correct
    batch["input_values"] = processor(audio["array"], sampling_rate=audio["sampling_rate"]).input_values[0]
    with processor.as_target_processor():
        batch["labels"] = processor(batch["normalized_text"]).input_ids
    return batch
ds = ds.map(prepare_dataset, remove_columns=ds.column_names,num_proc=1)

#Define the evaluation metric
import numpy as np
wer_metric = load_metric("wer")
def compute_metrics(pred):
    pred_logits = pred.predictions
    pred_ids = np.argmax(pred_logits, axis=-1)
    pred.label_ids[pred.label_ids == -100] = processor.tokenizer.pad_token_id
    pred_str = processor.batch_decode(pred_ids)
    #We do not want to group tokens when computing the metrics
    label_str = processor.batch_decode(pred.label_ids, group_tokens=False)
    wer = wer_metric.compute(predictions=pred_str, references=label_str)
    return {"wer": wer}

#Do the evaluation (with batch_size=1)
model = model.to(torch.device("cuda"))
def map_to_result(batch):
    with torch.no_grad():
        input_values = torch.tensor(batch["input_values"], device="cuda").unsqueeze(0)
        logits = model(input_values).logits
    pred_ids = torch.argmax(logits, dim=-1)
    batch["pred_str"] = processor.batch_decode(pred_ids)[0]
    batch["sentence"] = processor.decode(batch["labels"], group_tokens=False)
    return batch
results = ds.map(map_to_result,remove_columns=ds.column_names)

#Compute the overall WER now.
print("Test WER: {:.3f}".format(wer_metric.compute(predictions=results["pred_str"], references=results["sentence"])))
```
**Test Result**: 0.112
# BibTeX entry and citation info
*When publishing results based on these models please refer to:*
```bibtex
@misc{mena2022xlrs53spanish,
      title={Acoustic Model in Spanish: wav2vec2-large-xlsr-53-spanish-ep5-944h.}, 
      author={Hernandez Mena, Carlos Daniel},
      url={https://huggingface.co/carlosdanielhernandezmena/wav2vec2-large-xlsr-53-spanish-ep5-944h},
      year={2022}
}
```
# Acknowledgements

The author wants to thank to the social service program ["Desarrollo de Tecnologías del Habla"](http://profesores.fi-b.unam.mx/carlos_mena/servicio.html) at the [Facultad de Ingeniería (FI)](https://www.ingenieria.unam.mx/) of the [Universidad Nacional Autónoma de México (UNAM)](https://www.unam.mx/). He also thanks to the social service students for all the hard work.

Special thanks to Jón Guðnason, head of the Language and Voice Lab for providing computational power to make this model possible. The author also thanks to the "Language Technology Programme for Icelandic 2019-2023" which is managed and coordinated by Almannarómur, and it is funded by the Icelandic Ministry of Education, Science and Culture.