marcel commited on
Commit
5608aa9
·
1 Parent(s): 48df8f4
Files changed (1) hide show
  1. README.md +36 -36
README.md CHANGED
@@ -50,15 +50,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
50
  # Preprocessing the datasets.
51
  # We need to read the aduio files as arrays
52
  def speech_file_to_array_fn(batch):
53
- \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
54
- \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
55
- \\treturn batch
56
 
57
  test_dataset = test_dataset.map(speech_file_to_array_fn)
58
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
59
 
60
  with torch.no_grad():
61
- \tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
62
 
63
  predicted_ids = torch.argmax(logits, dim=-1)
64
 
@@ -90,52 +90,52 @@ model.to("cuda")
90
 
91
  chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\”\�\カ\æ\無\ན\カ\臣\ѹ\…\«\»\ð\ı\„\幺\א\ב\比\ш\ע\)\ứ\в\œ\ч\+\—\ш\‚\נ\м\ń\乡\$\=\ש\ф\支\(\°\и\к\̇]'
92
  substitutions = {
93
- \t'e' : '[\ə\é\ě\ę\ê\ế\ế\ë\ė\е]',
94
- \t'o' : '[\ō\ô\ô\ó\ò\ø\ọ\ŏ\õ\ő\о]',
95
- \t'a' : '[\á\ā\ā\ă\ã\å\â\à\ą\а]',
96
- \t'c' : '[\č\ć\ç\с]',
97
- \t'l' : '[\ł]',
98
- \t'u' : '[\ú\ū\ứ\ů]',
99
- \t'und' : '[\&]',
100
- \t'r' : '[\ř]',
101
- \t'y' : '[\ý]',
102
- \t's' : '[\ś\š\ș\ş]',
103
- \t'i' : '[\ī\ǐ\í\ï\î\ï]',
104
- \t'z' : '[\ź\ž\ź\ż]',
105
- \t'n' : '[\ñ\ń\ņ]',
106
- \t'g' : '[\ğ]',
107
- \t'ss' : '[\ß]',
108
- \t't' : '[\ț\ť]',
109
- \t'd' : '[\ď\đ]',
110
- \t"'": '[\ʿ\་\’\`\´\ʻ\`\‘]',
111
- \t'p': '\р'
112
  }
113
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
114
 
115
  # Preprocessing the datasets.
116
  # We need to read the aduio files as arrays
117
  def speech_file_to_array_fn(batch):
118
- \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
119
- \tfor x in substitutions:
120
- \t\tbatch["sentence"] = re.sub(substitutions[x], x, batch["sentence"])
121
- \t\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
122
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
123
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
124
- \treturn batch
125
 
126
  test_dataset = test_dataset.map(speech_file_to_array_fn)
127
 
128
  # Preprocessing the datasets.
129
  # We need to read the aduio files as arrays
130
  def evaluate(batch):
131
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
132
 
133
- \twith torch.no_grad():
134
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
135
 
136
- \tpred_ids = torch.argmax(logits, dim=-1)
137
- \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
138
- \treturn batch
139
 
140
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
141
 
 
50
  # Preprocessing the datasets.
51
  # We need to read the aduio files as arrays
52
  def speech_file_to_array_fn(batch):
53
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
54
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
55
+ return batch
56
 
57
  test_dataset = test_dataset.map(speech_file_to_array_fn)
58
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
59
 
60
  with torch.no_grad():
61
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
62
 
63
  predicted_ids = torch.argmax(logits, dim=-1)
64
 
 
90
 
91
  chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\”\�\カ\æ\無\ན\カ\臣\ѹ\…\«\»\ð\ı\„\幺\א\ב\比\ш\ע\)\ứ\в\œ\ч\+\—\ш\‚\נ\м\ń\乡\$\=\ש\ф\支\(\°\и\к\̇]'
92
  substitutions = {
93
+ 'e' : '[\ə\é\ě\ę\ê\ế\ế\ë\ė\е]',
94
+ 'o' : '[\ō\ô\ô\ó\ò\ø\ọ\ŏ\õ\ő\о]',
95
+ 'a' : '[\á\ā\ā\ă\ã\å\â\à\ą\а]',
96
+ 'c' : '[\č\ć\ç\с]',
97
+ 'l' : '[\ł]',
98
+ 'u' : '[\ú\ū\ứ\ů]',
99
+ 'und' : '[\&]',
100
+ 'r' : '[\ř]',
101
+ 'y' : '[\ý]',
102
+ 's' : '[\ś\š\ș\ş]',
103
+ 'i' : '[\ī\ǐ\í\ï\î\ï]',
104
+ 'z' : '[\ź\ž\ź\ż]',
105
+ 'n' : '[\ñ\ń\ņ]',
106
+ 'g' : '[\ğ]',
107
+ 'ss' : '[\ß]',
108
+ 't' : '[\ț\ť]',
109
+ 'd' : '[\ď\đ]',
110
+ "'": '[\ʿ\་\’\`\´\ʻ\`\‘]',
111
+ 'p': '\р'
112
  }
113
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
114
 
115
  # Preprocessing the datasets.
116
  # We need to read the aduio files as arrays
117
  def speech_file_to_array_fn(batch):
118
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
119
+ for x in substitutions:
120
+ batch["sentence"] = re.sub(substitutions[x], x, batch["sentence"])
121
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
122
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
123
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
124
+ return batch
125
 
126
  test_dataset = test_dataset.map(speech_file_to_array_fn)
127
 
128
  # Preprocessing the datasets.
129
  # We need to read the aduio files as arrays
130
  def evaluate(batch):
131
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
132
 
133
+ with torch.no_grad():
134
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
135
 
136
+ pred_ids = torch.argmax(logits, dim=-1)
137
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
138
+ return batch
139
 
140
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
141