Maverick1713 commited on
Commit
1420ab0
·
verified ·
1 Parent(s): e911c31

Add README.md

Browse files
Files changed (1) hide show
  1. README.md +351 -199
README.md CHANGED
@@ -1,199 +1,351 @@
1
- ---
2
- library_name: transformers
3
- tags: []
4
- ---
5
-
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
-
11
-
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Wav2Vec2-Large-XLSR-53-Hindi
2
+
3
+ Fine-tuned [facebook/wav2vec2-base-960h] on Hindi using the following datasets:
4
+
5
+ - [Common Voice](https://huggingface.co/datasets/common_voice),
6
+
7
+ - [Indic TTS- IITM](https://www.iitm.ac.in/donlab/tts/index.php) and
8
+
9
+ - [IIITH - Indic Speech Datasets](http://speech.iiit.ac.in/index.php/research-svl/69.html)
10
+
11
+ The Indic datasets are well balanced across gender and accents. However the CommonVoice dataset is skewed towards male voices
12
+
13
+ Fine-tuned on facebook/wav2vec2-large-xlsr-53 using Hindi dataset :: 60 epochs >> 17.05% WER
14
+
15
+ When using this model, make sure that your speech input is sampled at 16kHz.
16
+
17
+ ## Usage
18
+
19
+ The model can be used directly (without a language model) as follows:
20
+
21
+ ```python
22
+
23
+ import torch
24
+
25
+ import torchaudio
26
+
27
+ from datasets import load_dataset
28
+
29
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
30
+
31
+ test_dataset = load_dataset("common_voice", "hi", split="test")
32
+
33
+
34
+
35
+ processor = Wav2Vec2Processor.from_pretrained("Maverick1713/Hindi-ASR")
36
+
37
+ model = Wav2Vec2ForCTC.from_pretrained("Maverick1713/Hindi-ASR")
38
+
39
+
40
+
41
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
42
+
43
+
44
+
45
+ # Preprocessing the datasets.
46
+
47
+ # We need to read the aduio files as arrays
48
+
49
+ def speech_file_to_array_fn(batch):
50
+
51
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
52
+
53
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
54
+
55
+ return batch
56
+
57
+
58
+
59
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
60
+
61
+ inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
62
+
63
+
64
+
65
+ with torch.no_grad():
66
+
67
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
68
+
69
+
70
+
71
+ predicted_ids = torch.argmax(logits, dim=-1)
72
+
73
+ print("Prediction:", processor.batch_decode(predicted_ids))
74
+
75
+ print("Reference:", test_dataset["sentence"][:2])
76
+
77
+ ```
78
+
79
+ ## Predictions
80
+
81
+ _Some good ones ..... _
82
+
83
+ | Predictions | Reference |
84
+
85
+ |-------|-------|
86
+
87
+ |फिर वो सूरज तारे पहाड बारिश पदछड़ दिन रात शाम नदी बर्फ़ समुद्र धुंध हवा कुछ भी हो सकती है | फिर वो सूरज तारे पहाड़ बारिश पतझड़ दिन रात शाम नदी बर्फ़ समुद्र धुंध हवा कुछ भी हो सकती है |
88
+
89
+ | इस कारण जंगल में बडी दूर स्थित राघव के आश्रम में लोघ कम आने लगे और अधिकांश भक्त सुंदर के आश्रम में जाने लगे | इस कारण जंगल में बड़ी दूर स्थित राघव के आश्रम में लोग कम आने लगे और अधिकांश भक्त सुन्दर के आश्रम में जाने लगे |
90
+
91
+ | अपने बचन के अनुसार शुभमूर्त पर अनंत दक्षिणी पर्वत गया और मंत्रों का जप करके सरोवर में उतरा | अपने बचन के अनुसार शुभमुहूर्त पर अनंत दक्षिणी पर्वत गया और मंत्रों का जप करके सरोवर में उतरा |
92
+
93
+ _Some crappy stuff .... _
94
+
95
+ | Predictions | Reference |
96
+
97
+ |-------|-------|
98
+
99
+ | वस गनिल साफ़ है। | उसका दिल साफ़ है। |
100
+
101
+ | चाय वा एक कुछ लैंगे हब | चायवाय कुछ लेंगे आप |
102
+
103
+ | टॉम आधे है स्कूल हें है | टॉम अभी भी स्कूल में है |
104
+
105
+ ## Evaluation
106
+
107
+ The model can be evaluated as follows on the following two datasets:
108
+
109
+ 1. Custom dataset created from 20% of Indic, IIITH and CV (test): WER 17.xx%
110
+
111
+ 2. CommonVoice Hindi test dataset: WER 56.xx%
112
+
113
+ Links to the datasets are provided above (check the links at the start of the README)
114
+
115
+ train-test csv files are shared on the following gdrive links:
116
+
117
+ a. IIITH [train](https://storage.googleapis.com/indic-dataset/train_test_splits/iiit_hi_train.csv) [test](https://storage.googleapis.com/indic-dataset/train_test_splits/iiit_hi_test.csv)
118
+
119
+ b. Indic TTS [train](https://storage.googleapis.com/indic-dataset/train_test_splits/indic_train_full.csv) [test](https://storage.googleapis.com/indic-dataset/train_test_splits/indic_test_full.csv)
120
+
121
+ Update the audio_path as per your local file structure.
122
+
123
+ ```python
124
+
125
+ import torch
126
+
127
+ import torchaudio
128
+
129
+ from datasets import load_dataset, load_metric
130
+
131
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
132
+
133
+ import re
134
+
135
+
136
+
137
+ ## Load the datasets
138
+
139
+ test_dataset = load_dataset("common_voice", "hi", split="test")
140
+
141
+
142
+
143
+ indic = load_dataset("csv", data_files= {'train':"/workspace/data/hi2/indic_train_full.csv",
144
+
145
+ "test": "/workspace/data/hi2/indic_test_full.csv"}, download_mode="force_redownload")
146
+
147
+ iiith = load_dataset("csv", data_files= {"train": "/workspace/data/hi2/iiit_hi_train.csv",
148
+
149
+ "test": "/workspace/data/hi2/iiit_hi_test.csv"}, download_mode="force_redownload")
150
+
151
+
152
+
153
+ ## Pre-process datasets and concatenate to create test dataset
154
+
155
+ # Drop columns of common_voice
156
+
157
+ split = ['train', 'test', 'validation', 'other', 'invalidated']
158
+
159
+
160
+
161
+ for sp in split:
162
+
163
+ common_voice[sp] = common_voice[sp].remove_columns(['client_id', 'up_votes', 'down_votes', 'age', 'gender', 'accent', 'locale', 'segment'])
164
+
165
+
166
+
167
+ common_voice = common_voice.rename_column('path', 'audio_path')
168
+
169
+ common_voice = common_voice.rename_column('sentence', 'target_text')
170
+
171
+
172
+
173
+ train_dataset = datasets.concatenate_datasets([indic['train'], iiith['train'], common_voice['train']])
174
+
175
+ test_dataset = datasets.concatenate_datasets([indic['test'], iiith['test'], common_voice['test'], common_voice['validation']])
176
+
177
+
178
+
179
+ ## Load model from HF hub
180
+
181
+
182
+
183
+ wer = load_metric("wer")
184
+
185
+
186
+
187
+ processor = Wav2Vec2Processor.from_pretrained("Maverick1713/Hindi-ASR")
188
+
189
+ model = Wav2Vec2ForCTC.from_pretrained("Maverick1713/Hindi-ASR")
190
+
191
+ model.to("cuda")
192
+
193
+
194
+
195
+ chars_to_ignore_regex = '[\,\?\.\!\-\'\;\:\"\“\%\‘\”\�Utrnle\_]'
196
+
197
+ unicode_ignore_regex = r'[dceMaWpmFui\xa0\u200d]' # Some unwanted unicode chars
198
+
199
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
200
+
201
+
202
+
203
+ # Preprocessing the datasets.
204
+
205
+ # We need to read the aduio files as arrays
206
+
207
+
208
+
209
+ def speech_file_to_array_fn(batch):
210
+
211
+ batch["target_text"] = re.sub(chars_to_ignore_regex, '', batch["target_text"])
212
+
213
+ batch["target_text"] = re.sub(unicode_ignore_regex, '', batch["target_text"])
214
+
215
+
216
+
217
+ speech_array, sampling_rate = torchaudio.load(batch["audio_path"])
218
+
219
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
220
+
221
+ return batch
222
+
223
+
224
+
225
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
226
+
227
+
228
+
229
+ # Preprocessing the datasets.
230
+
231
+ # We need to read the aduio files as arrays
232
+
233
+
234
+
235
+ def evaluate(batch):
236
+
237
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
238
+
239
+ with torch.no_grad():
240
+
241
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
242
+
243
+ pred_ids = torch.argmax(logits, dim=-1)
244
+
245
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
246
+
247
+ return batch
248
+
249
+
250
+
251
+ result = test_dataset.map(evaluate, batched=True, batch_size=8)
252
+
253
+ print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
254
+
255
+ ```
256
+
257
+ **Test Result on custom dataset**: 17.23 %
258
+
259
+ ```python
260
+
261
+ import torch
262
+
263
+ import torchaudio
264
+
265
+ from datasets import load_dataset, load_metric
266
+
267
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
268
+
269
+ import re
270
+
271
+
272
+
273
+ test_dataset = load_dataset("common_voice", "hi", split="test")
274
+
275
+ wer = load_metric("wer")
276
+
277
+
278
+
279
+ processor = Wav2Vec2Processor.from_pretrained("Maverick1713/Hindi-ASR")
280
+
281
+ model = Wav2Vec2ForCTC.from_pretrained("Maverick1713/Hindi-ASR")
282
+
283
+ model.to("cuda")
284
+
285
+
286
+
287
+ chars_to_ignore_regex = '[\,\?\.\!\-\'\;\:\"\“\%\‘\”\�Utrnle\_]'
288
+
289
+ unicode_ignore_regex = r'[dceMaWpmFui\xa0\u200d]' # Some unwanted unicode chars
290
+
291
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
292
+
293
+
294
+
295
+ # Preprocessing the datasets.
296
+
297
+ # We need to read the aduio files as arrays
298
+
299
+
300
+
301
+ def speech_file_to_array_fn(batch):
302
+
303
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).sub(unicode_ignore_regex, '', batch["sentence"])
304
+
305
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
306
+
307
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
308
+
309
+ return batch
310
+
311
+
312
+
313
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
314
+
315
+
316
+
317
+ # Preprocessing the datasets.
318
+
319
+ # We need to read the aduio files as arrays
320
+
321
+
322
+
323
+ def evaluate(batch):
324
+
325
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
326
+
327
+ with torch.no_grad():
328
+
329
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
330
+
331
+ pred_ids = torch.argmax(logits, dim=-1)
332
+
333
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
334
+
335
+ return batch
336
+
337
+
338
+
339
+ result = test_dataset.map(evaluate, batched=True, batch_size=8)
340
+
341
+ print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
342
+
343
+ ```
344
+
345
+ **Test Result on CommonVoice**: 56.46 %
346
+
347
+ ## Training
348
+
349
+ The Common Voice `train`, `validation`, datasets were used for training as well as
350
+
351
+ The script used for training & wandb dashboard can be found [here](https://wandb.ai/thinkevolve/huggingface/reports/Project-Hindi-XLSR-Large--Vmlldzo2MTI2MTQ)