diego-fustes
commited on
Commit
•
e749f54
1
Parent(s):
6c06c78
Update README.md
Browse files
README.md
CHANGED
@@ -54,15 +54,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
54 |
# Preprocessing the datasets.
|
55 |
# We need to read the aduio files as arrays
|
56 |
def speech_file_to_array_fn(batch):
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
62 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
63 |
|
64 |
with torch.no_grad():
|
65 |
-
|
66 |
|
67 |
predicted_ids = torch.argmax(logits, dim=-1)
|
68 |
|
@@ -95,24 +95,24 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
95 |
# Preprocessing the datasets.
|
96 |
# We need to read the aduio files as arrays
|
97 |
def speech_file_to_array_fn(batch):
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
|
103 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
104 |
|
105 |
# Preprocessing the datasets.
|
106 |
# We need to read the aduio files as arrays
|
107 |
def evaluate(batch):
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
|
117 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
118 |
|
|
|
54 |
# Preprocessing the datasets.
|
55 |
# We need to read the aduio files as arrays
|
56 |
def speech_file_to_array_fn(batch):
|
57 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
58 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
59 |
+
return batch
|
60 |
|
61 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
62 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
63 |
|
64 |
with torch.no_grad():
|
65 |
+
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
66 |
|
67 |
predicted_ids = torch.argmax(logits, dim=-1)
|
68 |
|
|
|
95 |
# Preprocessing the datasets.
|
96 |
# We need to read the aduio files as arrays
|
97 |
def speech_file_to_array_fn(batch):
|
98 |
+
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
99 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
100 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
101 |
+
return batch
|
102 |
|
103 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
104 |
|
105 |
# Preprocessing the datasets.
|
106 |
# We need to read the aduio files as arrays
|
107 |
def evaluate(batch):
|
108 |
+
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
109 |
+
|
110 |
+
with torch.no_grad():
|
111 |
+
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
112 |
+
|
113 |
+
pred_ids = torch.argmax(logits, dim=-1)
|
114 |
+
batch["pred_strings"] = processor.batch_decode(pred_ids)
|
115 |
+
return batch
|
116 |
|
117 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
118 |
|