gagan3012 commited on
Commit
818e573
1 Parent(s): 8680eca

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +17 -17
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- language: pa
3
  datasets:
4
  - common_voice
5
  metrics:
@@ -19,7 +19,7 @@ model-index:
19
  dataset:
20
  name: Common Voice pa
21
  type: common_voice
22
- args: pa
23
  metrics:
24
  - name: Test WER
25
  type: wer
@@ -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,30 +94,30 @@ 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
 
 
1
  ---
2
+ language: pa-IN
3
  datasets:
4
  - common_voice
5
  metrics:
 
19
  dataset:
20
  name: Common Voice pa
21
  type: common_voice
22
+ args: pa-IN
23
  metrics:
24
  - name: Test WER
25
  type: wer
 
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