Merge branch 'main' of https://huggingface.co/KBLab/wav2vec2-large-xlsr-53-swedish into main
Browse files
README.md
CHANGED
@@ -19,7 +19,7 @@ model-index:
|
|
19 |
metrics:
|
20 |
- name: Test WER
|
21 |
type: wer
|
22 |
-
value:
|
23 |
---
|
24 |
|
25 |
# Wav2Vec2-Large-XLSR-53-Swedish
|
@@ -47,15 +47,16 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
47 |
# Preprocessing the datasets.
|
48 |
# We need to read the aduio files as arrays
|
49 |
def speech_file_to_array_fn(batch):
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
53 |
|
54 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
55 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
56 |
|
57 |
with torch.no_grad():
|
58 |
-
|
59 |
|
60 |
predicted_ids = torch.argmax(logits, dim=-1)
|
61 |
|
@@ -83,30 +84,30 @@ processor = Wav2Vec2Processor.from_pretrained("KBLab/wav2vec2-large-xlsr-53-swed
|
|
83 |
model = Wav2Vec2ForCTC.from_pretrained("KBLab/wav2vec2-large-xlsr-53-swedish")
|
84 |
model.to("cuda")
|
85 |
|
86 |
-
chars_to_ignore_regex = '[
|
87 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
88 |
|
89 |
# Preprocessing the datasets.
|
90 |
# We need to read the aduio files as arrays
|
91 |
def speech_file_to_array_fn(batch):
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
|
97 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
98 |
|
99 |
# Preprocessing the datasets.
|
100 |
# We need to read the aduio files as arrays
|
101 |
def evaluate(batch):
|
102 |
-
|
103 |
|
104 |
-
|
105 |
-
|
106 |
|
107 |
pred_ids = torch.argmax(logits, dim=-1)
|
108 |
-
|
109 |
-
|
110 |
|
111 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
112 |
|
|
|
19 |
metrics:
|
20 |
- name: Test WER
|
21 |
type: wer
|
22 |
+
value: 20.93
|
23 |
---
|
24 |
|
25 |
# Wav2Vec2-Large-XLSR-53-Swedish
|
|
|
47 |
# Preprocessing the datasets.
|
48 |
# We need to read the aduio files as arrays
|
49 |
def speech_file_to_array_fn(batch):
|
50 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
51 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
52 |
+
|
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 |
|
|
|
84 |
model = Wav2Vec2ForCTC.from_pretrained("KBLab/wav2vec2-large-xlsr-53-swedish")
|
85 |
model.to("cuda")
|
86 |
|
87 |
+
chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]'
|
88 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
89 |
|
90 |
# Preprocessing the datasets.
|
91 |
# We need to read the aduio files as arrays
|
92 |
def speech_file_to_array_fn(batch):
|
93 |
+
\\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
94 |
+
\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
95 |
+
\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
96 |
+
\\treturn batch
|
97 |
|
98 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
99 |
|
100 |
# Preprocessing the datasets.
|
101 |
# We need to read the aduio files as arrays
|
102 |
def evaluate(batch):
|
103 |
+
\\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
104 |
|
105 |
+
\\twith torch.no_grad():
|
106 |
+
\\t\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
107 |
|
108 |
pred_ids = torch.argmax(logits, dim=-1)
|
109 |
+
\\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
|
110 |
+
\\treturn batch
|
111 |
|
112 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
113 |
|