kingabzpro commited on
Commit
a075b97
1 Parent(s): f188709

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +85 -10
README.md CHANGED
@@ -5,11 +5,45 @@ tags:
5
  - generated_from_trainer
6
  metrics:
7
  - wer
 
8
  model-index:
9
  - name: wav2vec2-large-xls-r-300m-hi
10
- results: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  ---
12
-
13
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
14
  should probably proofread and complete it, then remove this comment. -->
15
 
@@ -21,20 +55,61 @@ It achieves the following results on the evaluation set:
21
  - Wer: 0.2992
22
  - Cer: 0.0786
23
 
24
- ## Model description
25
 
26
- More information needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- ## Intended uses & limitations
 
 
 
29
 
30
- More information needed
 
31
 
32
- ## Training and evaluation data
 
 
33
 
34
- More information needed
35
 
36
- ## Training procedure
 
37
 
 
 
 
38
  ### Training hyperparameters
39
 
40
  The following hyperparameters were used during training:
@@ -65,4 +140,4 @@ The following hyperparameters were used during training:
65
  - Transformers 4.33.0
66
  - Pytorch 2.0.0
67
  - Datasets 2.1.0
68
- - Tokenizers 0.13.3
 
5
  - generated_from_trainer
6
  metrics:
7
  - wer
8
+ - cer
9
  model-index:
10
  - name: wav2vec2-large-xls-r-300m-hi
11
+ results:
12
+ - task:
13
+ name: Automatic Speech Recognition
14
+ type: automatic-speech-recognition
15
+ dataset:
16
+ name: Common Voice 15
17
+ type: mozilla-foundation/common_voice_15_0
18
+ args: hi
19
+ metrics:
20
+ - name: Test WER
21
+ type: wer
22
+ value: 0.2934
23
+ - name: Test CER
24
+ type: cer
25
+ value: 0.0786
26
+ - task:
27
+ name: Automatic Speech Recognition
28
+ type: automatic-speech-recognition
29
+ dataset:
30
+ name: Common Voice 8
31
+ type: mozilla-foundation/common_voice_8_0
32
+ args: hi
33
+ metrics:
34
+ - name: Test WER
35
+ type: wer
36
+ value: 0.5209
37
+ - name: Test CER
38
+ type: cer
39
+ value: 0.1790
40
+ datasets:
41
+ - mozilla-foundation/common_voice_15_0
42
+ language:
43
+ - hi
44
+ library_name: transformers
45
+ pipeline_tag: automatic-speech-recognition
46
  ---
 
47
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
48
  should probably proofread and complete it, then remove this comment. -->
49
 
 
55
  - Wer: 0.2992
56
  - Cer: 0.0786
57
 
 
58
 
59
+ ## Evaluation
60
+
61
+ ```python
62
+ import torch
63
+ from datasets import load_dataset, load_metric
64
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
65
+ import librosa
66
+ import unicodedata
67
+ import re
68
+
69
+
70
+ test_dataset = load_dataset("mozilla-foundation/common_voice_8_0", "hi", split="test")
71
+ wer = load_metric("wer")
72
+ cer = load_metric("cer")
73
+
74
+ processor = Wav2Vec2Processor.from_pretrained("kingabzpro/wav2vec2-large-xls-r-300m-hi")
75
+ model = Wav2Vec2ForCTC.from_pretrained("kingabzpro/wav2vec2-large-xls-r-300m-hi")
76
+ model.to("cuda")
77
+
78
+
79
+ # Preprocessing the datasets.
80
+ def speech_file_to_array_fn(batch):
81
+ chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�\’\'\|\&\–]'
82
+ remove_en = '[A-Za-z]'
83
+ batch["sentence"] = re.sub(chars_to_ignore_regex, "", batch["sentence"].lower())
84
+ batch["sentence"] = re.sub(remove_en, "", batch["sentence"]).lower()
85
+ batch["sentence"] = unicodedata.normalize("NFKC", batch["sentence"])
86
+
87
+ speech_array, sampling_rate = librosa.load(batch["path"], sr=16_000)
88
+ batch["speech"] = speech_array
89
+ return batch
90
+
91
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
92
 
93
+ # Preprocessing the datasets.
94
+ # We need to read the aduio files as arrays
95
+ def evaluate(batch):
96
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
97
 
98
+ with torch.no_grad():
99
+ logits = model(inputs.input_values.to("cuda")).logits
100
 
101
+ pred_ids = torch.argmax(logits, dim=-1)
102
+ batch["pred_strings"] = processor.batch_decode(pred_ids, skip_special_tokens=True)
103
+ return batch
104
 
105
+ result = test_dataset.map(evaluate, batched=True, batch_size=8)
106
 
107
+ print("WER: {}".format(wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
108
+ print("CER: {}".format(cer.compute(predictions=result["pred_strings"], references=result["sentence"])))
109
 
110
+ ```
111
+ **WER: 0.5209850206372026**
112
+ **CER: 0.17902923538230883**
113
  ### Training hyperparameters
114
 
115
  The following hyperparameters were used during training:
 
140
  - Transformers 4.33.0
141
  - Pytorch 2.0.0
142
  - Datasets 2.1.0
143
+ - Tokenizers 0.13.3