gagan3012 commited on
Commit
4d79dbc
1 Parent(s): 818e573

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -16
README.md CHANGED
@@ -52,15 +52,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
52
  # Preprocessing the datasets.
53
  # We need to read the aduio files as arrays
54
  def speech_file_to_array_fn(batch):
55
- \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
56
- \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
57
- \\treturn batch
58
 
59
  test_dataset = test_dataset.map(speech_file_to_array_fn)
60
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
61
 
62
  with torch.no_grad():
63
- \\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
64
 
65
  predicted_ids = torch.argmax(logits, dim=-1)
66
 
@@ -94,37 +94,37 @@ processor = Wav2Vec2Processor.from_pretrained("gagan3012/wav2vec2-xlsr-punjabi")
94
  model = Wav2Vec2ForCTC.from_pretrained("gagan3012/wav2vec2-xlsr-punjabi")
95
  model.to("cuda")
96
 
97
- chars_to_ignore_regex = '[\\\\\\\\,\\\\\\\\?\\\\\\\\.\\\\\\\\!\\\\\\\\-\\\\\\\\;\\\\\\\\:\\\\\\\\"\\\\\\\\“]' # TODO: adapt this list to include all special characters you removed from the data
98
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
99
 
100
  # Preprocessing the datasets.
101
  # We need to read the aduio files as arrays
102
  def speech_file_to_array_fn(batch):
103
- \\\\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
104
- \\\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
105
- \\\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
106
- \\\\treturn batch
107
 
108
  test_dataset = test_dataset.map(speech_file_to_array_fn)
109
 
110
  # Preprocessing the datasets.
111
  # We need to read the aduio files as arrays
112
  def evaluate(batch):
113
- \\\\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
114
 
115
- \\\\twith torch.no_grad():
116
- \\\\t\\\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
117
 
118
- \\\\tpred_ids = torch.argmax(logits, dim=-1)
119
- \\\\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
120
- \\\\treturn batch
121
 
122
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
123
 
124
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
125
  ```
126
 
127
- **Test Result**: 58.06 %
128
 
129
 
130
  ## Training
 
52
  # Preprocessing the datasets.
53
  # We need to read the aduio files as arrays
54
  def speech_file_to_array_fn(batch):
55
+ \\\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
56
+ \\\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
57
+ \\\\treturn batch
58
 
59
  test_dataset = test_dataset.map(speech_file_to_array_fn)
60
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
61
 
62
  with torch.no_grad():
63
+ \\\\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
64
 
65
  predicted_ids = torch.argmax(logits, dim=-1)
66
 
 
94
  model = Wav2Vec2ForCTC.from_pretrained("gagan3012/wav2vec2-xlsr-punjabi")
95
  model.to("cuda")
96
 
97
+ chars_to_ignore_regex = '[\\\\\\\\\\\\\\\\,\\\\\\\\\\\\\\\\?\\\\\\\\\\\\\\\\.\\\\\\\\\\\\\\\\!\\\\\\\\\\\\\\\\-\\\\\\\\\\\\\\\\;\\\\\\\\\\\\\\\\:\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\“]' # TODO: adapt this list to include all special characters you removed from the data
98
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
99
 
100
  # Preprocessing the datasets.
101
  # We need to read the aduio files as arrays
102
  def speech_file_to_array_fn(batch):
103
+ \\\\\\\\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
104
+ \\\\\\\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
105
+ \\\\\\\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
106
+ \\\\\\\\treturn batch
107
 
108
  test_dataset = test_dataset.map(speech_file_to_array_fn)
109
 
110
  # Preprocessing the datasets.
111
  # We need to read the aduio files as arrays
112
  def evaluate(batch):
113
+ \\\\\\\\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
114
 
115
+ \\\\\\\\twith torch.no_grad():
116
+ \\\\\\\\t\\\\\\\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
117
 
118
+ \\\\\\\\tpred_ids = torch.argmax(logits, dim=-1)
119
+ \\\\\\\\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
120
+ \\\\\\\\treturn batch
121
 
122
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
123
 
124
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
125
  ```
126
 
127
+ **Test Result**: 58.05 %
128
 
129
 
130
  ## Training