tabs
Browse files
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 |
-
|
54 |
-
|
55 |
-
|
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 |
-
|
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 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
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 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
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 |
-
|
132 |
|
133 |
-
|
134 |
-
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
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 |
|