enabled lm
Browse files- README.md +150 -98
- preprocessor_config.json +1 -0
README.md
CHANGED
@@ -1,105 +1,157 @@
|
|
1 |
---
|
2 |
-
language:
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
tags:
|
|
|
6 |
- automatic-speech-recognition
|
7 |
-
-
|
8 |
-
- generated_from_trainer
|
9 |
-
datasets:
|
10 |
- common_voice
|
|
|
|
|
|
|
11 |
model-index:
|
12 |
-
- name:
|
13 |
-
results:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language: lg
|
3 |
+
datasets:
|
4 |
+
- mozilla-foundation/common_voice_7_0
|
5 |
+
metrics:
|
6 |
+
- wer
|
7 |
tags:
|
8 |
+
- audio
|
9 |
- automatic-speech-recognition
|
10 |
+
- speech
|
|
|
|
|
11 |
- common_voice
|
12 |
+
- lg
|
13 |
+
- robust-speech-event
|
14 |
+
license: apache-2.0
|
15 |
model-index:
|
16 |
+
- name: Wav2Vec2 Luganda by Indonesian-NLP
|
17 |
+
results:
|
18 |
+
- task:
|
19 |
+
name: Speech Recognition
|
20 |
+
type: automatic-speech-recognition
|
21 |
+
dataset:
|
22 |
+
name: Common Voice lg
|
23 |
+
type: common_voice
|
24 |
+
args: lg
|
25 |
+
metrics:
|
26 |
+
- name: Test WER
|
27 |
+
type: wer
|
28 |
+
value: 7.53
|
29 |
+
- task:
|
30 |
+
name: Automatic Speech Recognition
|
31 |
+
type: automatic-speech-recognition
|
32 |
+
dataset:
|
33 |
+
name: Common Voice 7
|
34 |
+
type: mozilla-foundation/common_voice_7_0
|
35 |
+
args: tr
|
36 |
+
metrics:
|
37 |
+
- name: Test WER
|
38 |
+
type: wer
|
39 |
+
value: 8.147
|
40 |
+
- name: Test CER
|
41 |
+
type: cer
|
42 |
+
value: 2.802
|
43 |
---
|
44 |
|
45 |
+
# Automatic Speech Recognition for Luganda
|
46 |
+
|
47 |
+
This is the model built for the
|
48 |
+
[Mozilla Luganda Automatic Speech Recognition competition](https://zindi.africa/competitions/mozilla-luganda-automatic-speech-recognition).
|
49 |
+
It is a fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53)
|
50 |
+
model on the [Luganda Common Voice dataset](https://huggingface.co/datasets/common_voice) version 7.0.
|
51 |
+
|
52 |
+
We also provide a [live demo](https://huggingface.co/spaces/indonesian-nlp/luganda-asr) to test the model.
|
53 |
+
|
54 |
+
When using this model, make sure that your speech input is sampled at 16kHz.
|
55 |
+
|
56 |
+
## Usage
|
57 |
+
The model can be used directly (without a language model) as follows:
|
58 |
+
```python
|
59 |
+
import torch
|
60 |
+
import torchaudio
|
61 |
+
from datasets import load_dataset
|
62 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
63 |
+
|
64 |
+
test_dataset = load_dataset("common_voice", "lg", split="test[:2%]")
|
65 |
+
|
66 |
+
processor = Wav2Vec2Processor.from_pretrained("indonesian-nlp/wav2vec2-luganda")
|
67 |
+
model = Wav2Vec2ForCTC.from_pretrained("indonesian-nlp/wav2vec2-luganda")
|
68 |
+
|
69 |
+
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
70 |
+
|
71 |
+
# Preprocessing the datasets.
|
72 |
+
# We need to read the aduio files as arrays
|
73 |
+
def speech_file_to_array_fn(batch):
|
74 |
+
if "audio" in batch:
|
75 |
+
speech_array = torch.tensor(batch["audio"]["array"])
|
76 |
+
else:
|
77 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
78 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
79 |
+
return batch
|
80 |
+
|
81 |
+
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
82 |
+
inputs = processor(test_dataset[:2]["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
83 |
+
|
84 |
+
with torch.no_grad():
|
85 |
+
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
86 |
+
|
87 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
88 |
+
|
89 |
+
print("Prediction:", processor.batch_decode(predicted_ids))
|
90 |
+
print("Reference:", test_dataset[:2]["sentence"])
|
91 |
+
```
|
92 |
+
|
93 |
+
|
94 |
+
## Evaluation
|
95 |
+
|
96 |
+
The model can be evaluated as follows on the Indonesian test data of Common Voice.
|
97 |
+
|
98 |
+
```python
|
99 |
+
import torch
|
100 |
+
import torchaudio
|
101 |
+
from datasets import load_dataset, load_metric
|
102 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
103 |
+
import re
|
104 |
+
|
105 |
+
test_dataset = load_dataset("common_voice", "lg", split="test")
|
106 |
+
wer = load_metric("wer")
|
107 |
+
|
108 |
+
processor = Wav2Vec2Processor.from_pretrained("indonesian-nlp/wav2vec2-luganda")
|
109 |
+
model = Wav2Vec2ForCTC.from_pretrained("indonesian-nlp/wav2vec2-luganda")
|
110 |
+
model.to("cuda")
|
111 |
+
|
112 |
+
chars_to_ignore = [",", "?", ".", "!", "-", ";", ":", '""', "%", "'", '"', "�", "‘", "’", "’"]
|
113 |
+
chars_to_ignore_regex = f'[{"".join(chars_to_ignore)}]'
|
114 |
+
|
115 |
+
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
116 |
+
|
117 |
+
# Preprocessing the datasets.
|
118 |
+
# We need to read the audio files as arrays
|
119 |
+
def speech_file_to_array_fn(batch):
|
120 |
+
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
121 |
+
if "audio" in batch:
|
122 |
+
speech_array = torch.tensor(batch["audio"]["array"])
|
123 |
+
else:
|
124 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
125 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
126 |
+
return batch
|
127 |
+
|
128 |
+
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
129 |
+
|
130 |
+
# Preprocessing the datasets.
|
131 |
+
# We need to read the audio files as arrays
|
132 |
+
def evaluate(batch):
|
133 |
+
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
134 |
+
|
135 |
+
with torch.no_grad():
|
136 |
+
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
137 |
+
|
138 |
+
pred_ids = torch.argmax(logits, dim=-1)
|
139 |
+
batch["pred_strings"] = processor.batch_decode(pred_ids)
|
140 |
+
return batch
|
141 |
+
|
142 |
+
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
143 |
+
|
144 |
+
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
145 |
+
```
|
146 |
+
|
147 |
+
WER without KenLM: 15.38 %
|
148 |
+
|
149 |
+
WER With KenLM:
|
150 |
+
|
151 |
+
**Test Result**: 7.53 %
|
152 |
+
|
153 |
+
## Training
|
154 |
+
|
155 |
+
The Common Voice `train`, `validation`, and ... datasets were used for training as well as ... and ... # TODO
|
156 |
+
|
157 |
+
The script used for training can be found [here](https://github.com/indonesian-nlp/luganda-asr)
|
preprocessor_config.json
CHANGED
@@ -5,5 +5,6 @@
|
|
5 |
"padding_side": "right",
|
6 |
"padding_value": 0.0,
|
7 |
"return_attention_mask": true,
|
|
|
8 |
"sampling_rate": 16000
|
9 |
}
|
|
|
5 |
"padding_side": "right",
|
6 |
"padding_value": 0.0,
|
7 |
"return_attention_mask": true,
|
8 |
+
"processor_class": "Wav2Vec2ProcessorWithLM",
|
9 |
"sampling_rate": 16000
|
10 |
}
|