Fix language code
Browse files
README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
|
|
|
2 |
datasets:
|
3 |
- kazakh_speech_corpus
|
4 |
metrics:
|
@@ -18,7 +19,7 @@ model-index:
|
|
18 |
dataset:
|
19 |
name: Kazakh Speech Corpus v1.1
|
20 |
type: kazakh_speech_corpus
|
21 |
-
args:
|
22 |
metrics:
|
23 |
- name: Test WER
|
24 |
type: wer
|
@@ -52,15 +53,15 @@ model = Wav2Vec2ForCTC.from_pretrained("wav2vec2-large-xlsr-kazakh")
|
|
52 |
# Preprocessing the datasets.
|
53 |
# We need to read the audio files as arrays
|
54 |
def speech_file_to_array_fn(batch):
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
|
59 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
60 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
61 |
|
62 |
with torch.no_grad():
|
63 |
-
|
64 |
|
65 |
predicted_ids = torch.argmax(logits, dim=-1)
|
66 |
|
@@ -93,22 +94,22 @@ model.to("cuda")
|
|
93 |
# Preprocessing the datasets.
|
94 |
# We need to read the audio files as arrays
|
95 |
def speech_file_to_array_fn(batch):
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
|
101 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
102 |
|
103 |
def evaluate(batch):
|
104 |
-
|
105 |
|
106 |
-
|
107 |
-
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
|
113 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
114 |
|
|
|
1 |
+
---
|
2 |
+
language: kk
|
3 |
datasets:
|
4 |
- kazakh_speech_corpus
|
5 |
metrics:
|
|
|
19 |
dataset:
|
20 |
name: Kazakh Speech Corpus v1.1
|
21 |
type: kazakh_speech_corpus
|
22 |
+
args: kk
|
23 |
metrics:
|
24 |
- name: Test WER
|
25 |
type: wer
|
|
|
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"] = torchaudio.transforms.Resample(sampling_rate, 16_000)(speech_array).squeeze().numpy()
|
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 |
|
|
|
94 |
# Preprocessing the datasets.
|
95 |
# We need to read the audio files as arrays
|
96 |
def speech_file_to_array_fn(batch):
|
97 |
+
\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
98 |
+
\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
99 |
+
\tbatch["speech"] = torchaudio.transforms.Resample(sampling_rate, 16_000)(speech_array).squeeze().numpy()
|
100 |
+
\treturn batch
|
101 |
|
102 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
103 |
|
104 |
def evaluate(batch):
|
105 |
+
\tinputs = processor(batch["text"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
106 |
|
107 |
+
\twith torch.no_grad():
|
108 |
+
\t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
109 |
|
110 |
+
\tpred_ids = torch.argmax(logits, dim=-1)
|
111 |
+
\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
|
112 |
+
\treturn batch
|
113 |
|
114 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
115 |
|