gagan3012 commited on
Commit
86d2f21
1 Parent(s): 825a167

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -16
README.md CHANGED
@@ -11,7 +11,7 @@ tags:
11
  - xlsr-fine-tuning-week
12
  license: apache-2.0
13
  model-index:
14
- - name: wav2vec2-xlsr-chuvash
15
  results:
16
  - task:
17
  name: Speech Recognition
@@ -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
 
@@ -98,30 +98,30 @@ model.to("cuda")
98
 
99
 
100
 
101
- chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]' # TODO: adapt this list to include all special characters you removed from the data
102
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
103
 
104
  # Preprocessing the datasets.
105
  # We need to read the aduio files as arrays
106
  def speech_file_to_array_fn(batch):
107
- \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
108
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
109
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
110
- \treturn batch
111
 
112
  test_dataset = test_dataset.map(speech_file_to_array_fn)
113
 
114
  # Preprocessing the datasets.
115
  # We need to read the aduio files as arrays
116
  def evaluate(batch):
117
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
118
 
119
- \twith torch.no_grad():
120
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
121
 
122
- \tpred_ids = torch.argmax(logits, dim=-1)
123
- \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
124
- \treturn batch
125
 
126
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
127
 
 
11
  - xlsr-fine-tuning-week
12
  license: apache-2.0
13
  model-index:
14
+ - name: wav2vec2-xlsr-chuvash by Gagan Bhatia
15
  results:
16
  - task:
17
  name: Speech Recognition
 
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
 
 
98
 
99
 
100
 
101
+ chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]' # TODO: adapt this list to include all special characters you removed from the data
102
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
103
 
104
  # Preprocessing the datasets.
105
  # We need to read the aduio files as arrays
106
  def speech_file_to_array_fn(batch):
107
+ \\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
108
+ \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
109
+ \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
110
+ \\treturn batch
111
 
112
  test_dataset = test_dataset.map(speech_file_to_array_fn)
113
 
114
  # Preprocessing the datasets.
115
  # We need to read the aduio files as arrays
116
  def evaluate(batch):
117
+ \\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
118
 
119
+ \\twith torch.no_grad():
120
+ \\t\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
121
 
122
+ \\tpred_ids = torch.argmax(logits, dim=-1)
123
+ \\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
124
+ \\treturn batch
125
 
126
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
127