bayartsogt
commited on
Commit
·
4139062
1
Parent(s):
4f91a77
Update README.md
Browse files
README.md
CHANGED
@@ -28,7 +28,7 @@ model-index:
|
|
28 |
|
29 |
# Wav2Vec2-Large-XLSR-53-Mongolian-v1
|
30 |
|
31 |
-
Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on
|
32 |
|
33 |
When using this model, make sure that your speech input is sampled at 16kHz.
|
34 |
|
@@ -51,30 +51,30 @@ processor = Wav2Vec2Processor.from_pretrained("bayartsogt/wav2vec2-large-xlsr-mo
|
|
51 |
model = Wav2Vec2ForCTC.from_pretrained("bayartsogt/wav2vec2-large-xlsr-mongolian-v1")
|
52 |
model.to("cuda")
|
53 |
|
54 |
-
chars_to_ignore_regex = '[
|
55 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
56 |
|
57 |
# Preprocessing the datasets.
|
58 |
# We need to read the aduio files as arrays
|
59 |
def speech_file_to_array_fn(batch):
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
66 |
|
67 |
# Preprocessing the datasets.
|
68 |
# We need to read the aduio files as arrays
|
69 |
def evaluate(batch):
|
70 |
-
|
71 |
|
72 |
-
|
73 |
-
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
|
79 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
80 |
|
|
|
28 |
|
29 |
# Wav2Vec2-Large-XLSR-53-Mongolian-v1
|
30 |
|
31 |
+
Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Mongolian using the [Common Voice](https://huggingface.co/datasets/common_voice).
|
32 |
|
33 |
When using this model, make sure that your speech input is sampled at 16kHz.
|
34 |
|
|
|
51 |
model = Wav2Vec2ForCTC.from_pretrained("bayartsogt/wav2vec2-large-xlsr-mongolian-v1")
|
52 |
model.to("cuda")
|
53 |
|
54 |
+
chars_to_ignore_regex = '[\\!\\"\\'\\,\\.\\«\\»\\?\\-]'
|
55 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
56 |
|
57 |
# Preprocessing the datasets.
|
58 |
# We need to read the aduio files as arrays
|
59 |
def speech_file_to_array_fn(batch):
|
60 |
+
\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
61 |
+
\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
62 |
+
\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
63 |
+
\treturn batch
|
64 |
|
65 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
66 |
|
67 |
# Preprocessing the datasets.
|
68 |
# We need to read the aduio files as arrays
|
69 |
def evaluate(batch):
|
70 |
+
\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
71 |
|
72 |
+
\twith torch.no_grad():
|
73 |
+
\t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
74 |
|
75 |
+
\tpred_ids = torch.argmax(logits, dim=-
|
76 |
+
\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
|
77 |
+
\treturn batch
|
78 |
|
79 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
80 |
|