Harveenchadha commited on
Commit
3a6bb54
·
1 Parent(s): 268af19

Updating Metadata

Browse files
Files changed (1) hide show
  1. README.md +131 -0
README.md ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: hi
3
+ #datasets:
4
+ #- Interspeech 2021
5
+ metrics:
6
+ - wer
7
+ tags:
8
+ - audio
9
+ - automatic-speech-recognition
10
+ - speech
11
+ license: MIT
12
+ model-index:
13
+ - name: Wav2Vec2 Vakyansh Hindi Model by Harveen
14
+ results:
15
+ - task:
16
+ name: Speech Recognition
17
+ type: automatic-speech-recognition
18
+ dataset:
19
+ name: Common Voice hi
20
+ type: common_voice
21
+ args: hi
22
+ metrics:
23
+ - name: Test WER
24
+ type: wer
25
+ value: 33.17
26
+ ---
27
+
28
+ ## Pretrained Model
29
+
30
+ Fine-tuned on Multilingual Pretrained Model [CLSRIL-23](https://arxiv.org/abs/2107.07402). The original fairseq checkpoint is present [here](https://github.com/Open-Speech-EkStep/vakyansh-models). When using this model, make sure that your speech input is sampled at 16kHz.
31
+
32
+ **Note: The result from this model is without a language model so you may witness a higher WER in some cases.**
33
+
34
+ ## Dataset
35
+
36
+ This model was trained on 4200 hours of Hindi Labelled Data. The labelled data is not present in public domain as of now.
37
+
38
+ ## Training Script
39
+
40
+ Models were trained using experimental platform setup by Vakyansh team at Ekstep. Here is the [training repository](https://github.com/Open-Speech-EkStep/vakyansh-wav2vec2-experimentation)
41
+
42
+
43
+ ## Usage
44
+
45
+ The model can be used directly (without a language model) as follows:
46
+
47
+ ```python
48
+ import soundfile as sf
49
+ import torch
50
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
51
+ import argparse
52
+
53
+ def parse_transcription(checkpoint_path, wav_file):
54
+ # load pretrained model
55
+ processor = Wav2Vec2Processor.from_pretrained(checkpoint_path)
56
+ model = Wav2Vec2ForCTC.from_pretrained(checkpoint_path)
57
+
58
+ # load audio
59
+ audio_input, sample_rate = sf.read(wav_file)
60
+
61
+ # pad input values and return pt tensor
62
+ input_values = processor(audio_input, sampling_rate=sample_rate, return_tensors="pt").input_values
63
+
64
+ # INFERENCE
65
+ # retrieve logits & take argmax
66
+ logits = model(input_values).logits
67
+ predicted_ids = torch.argmax(logits, dim=-1)
68
+
69
+ # transcribe
70
+ transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
71
+ print(transcription)
72
+
73
+ ```
74
+
75
+
76
+ ## Evaluation
77
+ The model can be evaluated as follows on the hindi test data of Common Voice.
78
+
79
+ ```python
80
+
81
+ import torch
82
+ import torchaudio
83
+ from datasets import load_dataset, load_metric
84
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
85
+ import re
86
+
87
+ test_dataset = load_dataset("common_voice", "hi", split="test")
88
+ wer = load_metric("wer")
89
+
90
+ processor = Wav2Vec2Processor.from_pretrained("Harveenchadha/vakyansh-wav2vec2-hindi-him-4200")
91
+ model = Wav2Vec2ForCTC.from_pretrained("Harveenchadha/vakyansh-wav2vec2-hindi-him-4200")
92
+ model.to("cuda")
93
+
94
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
95
+
96
+ chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“]'
97
+
98
+ # Preprocessing the datasets.
99
+ # We need to read the aduio files as arrays
100
+ def speech_file_to_array_fn(batch):
101
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
102
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
103
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
104
+ return batch
105
+
106
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
107
+
108
+ # Preprocessing the datasets.
109
+ # We need to read the aduio files as arrays
110
+ def evaluate(batch):
111
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
112
+
113
+ with torch.no_grad():
114
+ logits = model(inputs.input_values.to("cuda")).logits
115
+
116
+ pred_ids = torch.argmax(logits, dim=-1)
117
+ batch["pred_strings"] = processor.batch_decode(pred_ids, skip_special_tokens=True)
118
+ return batch
119
+
120
+ result = test_dataset.map(evaluate, batched=True, batch_size=8)
121
+
122
+ print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
123
+
124
+ ```
125
+
126
+ **Test Result**: 33.17 %
127
+
128
+ [**Colab Demo**](https://colab.research.google.com/github/harveenchadha/bol/blob/main/demos/hf/hindi/hf_vakyansh_hindi_him_4200_evaluation_common_voice.ipynb)
129
+
130
+ ## Credits
131
+ Thanks to Ekstep Foundation for making this possible. The vakyansh team will be open sourcing speech models in all the Indic Languages.