patrickvonplaten
commited on
Commit
•
f373715
1
Parent(s):
0b6a34f
Update README.md
Browse files
README.md
CHANGED
@@ -53,15 +53,15 @@ resampler = lambda sampling_rate, y: librosa.resample(y.numpy().squeeze(), sampl
|
|
53 |
# Preprocessing the datasets.
|
54 |
# We need to read the audio files as arrays
|
55 |
def speech_file_to_array_fn(batch):
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
61 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
62 |
|
63 |
with torch.no_grad():
|
64 |
-
|
65 |
|
66 |
predicted_ids = torch.argmax(logits, dim=-1)
|
67 |
|
@@ -90,30 +90,30 @@ processor = Wav2Vec2Processor.from_pretrained("xsway/wav2vec2-large-xlsr-georgia
|
|
90 |
model = Wav2Vec2ForCTC.from_pretrained("xsway/wav2vec2-large-xlsr-georgian")
|
91 |
model.to("cuda")
|
92 |
|
93 |
-
chars_to_ignore_regex = '[
|
94 |
resampler = lambda sampling_rate, y: librosa.resample(y.numpy().squeeze(), sampling_rate, 16_000)
|
95 |
|
96 |
# Preprocessing the datasets.
|
97 |
# We need to read the audio files as arrays
|
98 |
def speech_file_to_array_fn(batch):
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
|
104 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
105 |
|
106 |
# Preprocessing the datasets.
|
107 |
# We need to read the audio files as arrays
|
108 |
def evaluate(batch):
|
109 |
-
|
110 |
|
111 |
-
|
112 |
-
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
119 |
|
53 |
# Preprocessing the datasets.
|
54 |
# We need to read the audio files as arrays
|
55 |
def speech_file_to_array_fn(batch):
|
56 |
+
\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
57 |
+
\\tbatch["speech"] = resampler(sampling_rate, speech_array).squeeze()
|
58 |
+
\\treturn batch
|
59 |
|
60 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
61 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
62 |
|
63 |
with torch.no_grad():
|
64 |
+
\\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
65 |
|
66 |
predicted_ids = torch.argmax(logits, dim=-1)
|
67 |
|
90 |
model = Wav2Vec2ForCTC.from_pretrained("xsway/wav2vec2-large-xlsr-georgian")
|
91 |
model.to("cuda")
|
92 |
|
93 |
+
chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]'
|
94 |
resampler = lambda sampling_rate, y: librosa.resample(y.numpy().squeeze(), sampling_rate, 16_000)
|
95 |
|
96 |
# Preprocessing the datasets.
|
97 |
# We need to read the audio files as arrays
|
98 |
def speech_file_to_array_fn(batch):
|
99 |
+
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
100 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
101 |
+
batch["speech"] = resampler(sampling_rate, speech_array).squeeze()
|
102 |
+
return batch
|
103 |
|
104 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
105 |
|
106 |
# Preprocessing the datasets.
|
107 |
# We need to read the audio files as arrays
|
108 |
def evaluate(batch):
|
109 |
+
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
110 |
|
111 |
+
with torch.no_grad():
|
112 |
+
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
113 |
|
114 |
+
pred_ids = torch.argmax(logits, dim=-1)
|
115 |
+
batch["pred_strings"] = processor.batch_decode(pred_ids)
|
116 |
+
return batch
|
117 |
|
118 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
119 |
|