sumedh commited on
Commit
fbeb9ca
1 Parent(s): f592023

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +18 -15
README.md CHANGED
@@ -42,13 +42,13 @@ model = Wav2Vec2ForCTC.from_pretrained("sumedh/wav2vec2-large-xlsr-marathi")
42
  resampler = torchaudio.transforms.Resample(48_000, 16_000) #first arg - input sample, second arg - output sample
43
  # Preprocessing the datasets. We need to read the aduio files as arrays
44
  def speech_file_to_array_fn(batch):
45
- \tspeech_array, sampling_rate = torchaudio.load(batch["path_in_folder"])
46
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
47
- \treturn batch
48
  mr_test_dataset_new = mr_test_dataset_new.map(speech_file_to_array_fn)
49
  inputs = processor(mr_test_dataset_new["speech"][:5], sampling_rate=16_000, return_tensors="pt", padding=True)
50
  with torch.no_grad():
51
- \tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
52
  predicted_ids = torch.argmax(logits, dim=-1)
53
  print("Prediction:", processor.batch_decode(predicted_ids))
54
  print("Reference:", mr_test_dataset_new["actual_text"][:5])
@@ -67,22 +67,22 @@ processor = Wav2Vec2Processor.from_pretrained("sumedh/wav2vec2-large-xlsr-marath
67
  model = Wav2Vec2ForCTC.from_pretrained("sumedh/wav2vec2-large-xlsr-marathi")
68
  model.to("cuda")
69
 
70
- chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]'
71
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
72
  # Preprocessing the datasets. We need to read the aduio files as arrays
73
  def speech_file_to_array_fn(batch):
74
- \tbatch["actual_text"] = re.sub(chars_to_ignore_regex, '', batch["actual_text"]).lower()
75
- \tspeech_array, sampling_rate = torchaudio.load(batch["path_in_folder"])
76
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
77
- \treturn batch
78
  mr_test_dataset_new = mr_test_dataset_new.map(speech_file_to_array_fn)
79
  def evaluate(batch):
80
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
81
- \twith torch.no_grad():
82
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
83
- \t\tpred_ids = torch.argmax(logits, dim=-1)
84
- \t\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
85
- \treturn batch
86
  result = mr_test_dataset_new.map(evaluate, batched=True, batch_size=8)
87
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["actual_text"])))
88
  ```
@@ -90,3 +90,6 @@ print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"],
90
  ## Training
91
  Train-Test ratio was 90:10.
92
  The colab notebook used for training can be found [here](https://colab.research.google.com/drive/1wX46fjExcgU5t3AsWhSPTipWg_aMDg2f?usp=sharing).
 
 
 
 
42
  resampler = torchaudio.transforms.Resample(48_000, 16_000) #first arg - input sample, second arg - output sample
43
  # Preprocessing the datasets. We need to read the aduio files as arrays
44
  def speech_file_to_array_fn(batch):
45
+ \\tspeech_array, sampling_rate = torchaudio.load(batch["path_in_folder"])
46
+ \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
47
+ \\treturn batch
48
  mr_test_dataset_new = mr_test_dataset_new.map(speech_file_to_array_fn)
49
  inputs = processor(mr_test_dataset_new["speech"][:5], sampling_rate=16_000, return_tensors="pt", padding=True)
50
  with torch.no_grad():
51
+ \\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
52
  predicted_ids = torch.argmax(logits, dim=-1)
53
  print("Prediction:", processor.batch_decode(predicted_ids))
54
  print("Reference:", mr_test_dataset_new["actual_text"][:5])
 
67
  model = Wav2Vec2ForCTC.from_pretrained("sumedh/wav2vec2-large-xlsr-marathi")
68
  model.to("cuda")
69
 
70
+ chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]'
71
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
72
  # Preprocessing the datasets. We need to read the aduio files as arrays
73
  def speech_file_to_array_fn(batch):
74
+ \\tbatch["actual_text"] = re.sub(chars_to_ignore_regex, '', batch["actual_text"]).lower()
75
+ \\tspeech_array, sampling_rate = torchaudio.load(batch["path_in_folder"])
76
+ \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
77
+ \\treturn batch
78
  mr_test_dataset_new = mr_test_dataset_new.map(speech_file_to_array_fn)
79
  def evaluate(batch):
80
+ \\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
81
+ \\twith torch.no_grad():
82
+ \\t\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
83
+ \\t\\tpred_ids = torch.argmax(logits, dim=-1)
84
+ \\t\\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
85
+ \\treturn batch
86
  result = mr_test_dataset_new.map(evaluate, batched=True, batch_size=8)
87
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["actual_text"])))
88
  ```
 
90
  ## Training
91
  Train-Test ratio was 90:10.
92
  The colab notebook used for training can be found [here](https://colab.research.google.com/drive/1wX46fjExcgU5t3AsWhSPTipWg_aMDg2f?usp=sharing).
93
+
94
+ ## Training Config and Summary
95
+ weights-and-biases run profile [here](https://wandb.ai/wandb/xlsr/runs/3itdhtb8/overview?workspace=user-sumedhkhodke)