aditii09 commited on
Commit
a69148f
1 Parent(s): 7705a87

Upload README (1).md

Browse files
Files changed (1) hide show
  1. README (1).md +138 -0
README (1).md ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Chadha
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
+ ## Spaces Demo
29
+ Check the spaces demo [here](https://huggingface.co/spaces/Harveenchadha/wav2vec2-vakyansh-hindi/tree/main)
30
+
31
+ ## Pretrained Model
32
+
33
+ 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.
34
+
35
+ **Note: The result from this model is without a language model so you may witness a higher WER in some cases.**
36
+
37
+ ## Dataset
38
+
39
+ This model was trained on 4200 hours of Hindi Labelled Data. The labelled data is not present in public domain as of now.
40
+
41
+ ## Training Script
42
+
43
+ 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).
44
+
45
+ In case you want to explore training logs on wandb they are [here](https://wandb.ai/harveenchadha/hindi_finetuning_multilingual?workspace=user-harveenchadha).
46
+
47
+
48
+ ## [Colab Demo](https://colab.research.google.com/github/harveenchadha/bol/blob/main/demos/hf/hindi/hf_hindi_him_4200_demo.ipynb)
49
+
50
+ ## Usage
51
+
52
+ The model can be used directly (without a language model) as follows:
53
+
54
+ ```python
55
+ import soundfile as sf
56
+ import torch
57
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
58
+ import argparse
59
+
60
+ def parse_transcription(wav_file):
61
+ # load pretrained model
62
+ processor = Wav2Vec2Processor.from_pretrained("Harveenchadha/vakyansh-wav2vec2-hindi-him-4200")
63
+ model = Wav2Vec2ForCTC.from_pretrained("Harveenchadha/vakyansh-wav2vec2-hindi-him-4200")
64
+
65
+ # load audio
66
+ audio_input, sample_rate = sf.read(wav_file)
67
+
68
+ # pad input values and return pt tensor
69
+ input_values = processor(audio_input, sampling_rate=sample_rate, return_tensors="pt").input_values
70
+
71
+ # INFERENCE
72
+ # retrieve logits & take argmax
73
+ logits = model(input_values).logits
74
+ predicted_ids = torch.argmax(logits, dim=-1)
75
+
76
+ # transcribe
77
+ transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
78
+ print(transcription)
79
+
80
+ ```
81
+
82
+
83
+ ## Evaluation
84
+ The model can be evaluated as follows on the hindi test data of Common Voice.
85
+
86
+ ```python
87
+
88
+ import torch
89
+ import torchaudio
90
+ from datasets import load_dataset, load_metric
91
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
92
+ import re
93
+
94
+ test_dataset = load_dataset("common_voice", "hi", split="test")
95
+ wer = load_metric("wer")
96
+
97
+ processor = Wav2Vec2Processor.from_pretrained("Harveenchadha/vakyansh-wav2vec2-hindi-him-4200")
98
+ model = Wav2Vec2ForCTC.from_pretrained("Harveenchadha/vakyansh-wav2vec2-hindi-him-4200")
99
+ model.to("cuda")
100
+
101
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
102
+
103
+ chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“]'
104
+
105
+ # Preprocessing the datasets.
106
+ # We need to read the aduio files as arrays
107
+ def speech_file_to_array_fn(batch):
108
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
109
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
110
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
111
+ return batch
112
+
113
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
114
+
115
+ # Preprocessing the datasets.
116
+ # We need to read the aduio files as arrays
117
+ def evaluate(batch):
118
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
119
+
120
+ with torch.no_grad():
121
+ logits = model(inputs.input_values.to("cuda")).logits
122
+
123
+ pred_ids = torch.argmax(logits, dim=-1)
124
+ batch["pred_strings"] = processor.batch_decode(pred_ids, skip_special_tokens=True)
125
+ return batch
126
+
127
+ result = test_dataset.map(evaluate, batched=True, batch_size=8)
128
+
129
+ print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
130
+
131
+ ```
132
+
133
+ **Test Result**: 33.17 %
134
+
135
+ [**Colab Evaluation**](https://colab.research.google.com/github/harveenchadha/bol/blob/main/demos/hf/hindi/hf_vakyansh_hindi_him_4200_evaluation_common_voice.ipynb)
136
+
137
+ ## Credits
138
+ Thanks to Ekstep Foundation for making this possible. The vakyansh team will be open sourcing speech models in all the Indic Languages.