upd readme
Browse files
README.md
CHANGED
@@ -48,15 +48,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
48 |
# Preprocessing the datasets.
|
49 |
# We need to read the aduio files as arrays
|
50 |
def speech_file_to_array_fn(batch):
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
56 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
57 |
|
58 |
with torch.no_grad():
|
59 |
-
|
60 |
|
61 |
predicted_ids = torch.argmax(logits, dim=-1)
|
62 |
|
@@ -92,30 +92,30 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
92 |
# We need to read the aduio files as arrays
|
93 |
# Note: this models is trained ignoring accents on letters as below
|
94 |
def speech_file_to_array_fn(batch):
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
|
106 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
107 |
|
108 |
# Preprocessing the datasets.
|
109 |
# We need to read the aduio files as arrays
|
110 |
def evaluate(batch):
|
111 |
-
|
112 |
|
113 |
-
|
114 |
-
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
|
120 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
121 |
|
|
|
48 |
# Preprocessing the datasets.
|
49 |
# We need to read the aduio files as arrays
|
50 |
def speech_file_to_array_fn(batch):
|
51 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
52 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
53 |
+
return batch
|
54 |
|
55 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
56 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
57 |
|
58 |
with torch.no_grad():
|
59 |
+
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
60 |
|
61 |
predicted_ids = torch.argmax(logits, dim=-1)
|
62 |
|
|
|
92 |
# We need to read the aduio files as arrays
|
93 |
# Note: this models is trained ignoring accents on letters as below
|
94 |
def speech_file_to_array_fn(batch):
|
95 |
+
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().strip()
|
96 |
+
batch["sentence"] = re.sub(re.compile('[äá]'), 'a', batch['sentence'])
|
97 |
+
batch["sentence"] = re.sub(re.compile('[öó]'), 'o', batch['sentence'])
|
98 |
+
batch["sentence"] = re.sub(re.compile('[èé]'), 'e', batch['sentence'])
|
99 |
+
batch["sentence"] = re.sub(re.compile("[ïí]"), 'i', batch['sentence'])
|
100 |
+
batch["sentence"] = re.sub(re.compile("[üů]"), 'u', batch['sentence'])
|
101 |
+
batch['sentence'] = re.sub(' ', ' ', batch['sentence'])
|
102 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
103 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
104 |
+
return batch
|
105 |
|
106 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
107 |
|
108 |
# Preprocessing the datasets.
|
109 |
# We need to read the aduio files as arrays
|
110 |
def evaluate(batch):
|
111 |
+
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
112 |
|
113 |
+
with torch.no_grad():
|
114 |
+
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
115 |
|
116 |
+
pred_ids = torch.argmax(logits, dim=-1)
|
117 |
+
batch["pred_strings"] = processor.batch_decode(pred_ids)
|
118 |
+
return batch
|
119 |
|
120 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
121 |
|