Update README.md
Browse files
README.md
CHANGED
@@ -26,7 +26,7 @@ model-index:
|
|
26 |
value: 48.40
|
27 |
---
|
28 |
|
29 |
-
# Wav2Vec2-Large-XLSR-53-
|
30 |
|
31 |
Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Chuvash using the [Common Voice](https://huggingface.co/datasets/common_voice)
|
32 |
|
@@ -52,15 +52,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
52 |
# Preprocessing the datasets.
|
53 |
# We need to read the aduio 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 |
|
@@ -71,10 +71,9 @@ print("Reference:", test_dataset["sentence"][:2])
|
|
71 |
|
72 |
#### Results:
|
73 |
|
74 |
-
Prediction: ['
|
75 |
-
|
76 |
-
Reference: ['ਹਵਾਲਾਤ ਵਿੱਚ ਪੰਜ ਛੇ ਇਖ਼ਲਾਕੀ ਮੁਜਰਮ ਸਨ', 'ਮੈਂ ਇਹ ਪੈਸੇ ਲੈਣੇ ਨਹੀਂ ਸੀ ਚਾਹੁੰਦਾ']
|
77 |
|
|
|
78 |
## Evaluation
|
79 |
|
80 |
The model can be evaluated as follows on the Chuvash test data of Common Voice.
|
@@ -99,30 +98,30 @@ model.to("cuda")
|
|
99 |
|
100 |
|
101 |
|
102 |
-
chars_to_ignore_regex = '[
|
103 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
104 |
|
105 |
# Preprocessing the datasets.
|
106 |
# We need to read the aduio files as arrays
|
107 |
def speech_file_to_array_fn(batch):
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
|
113 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
114 |
|
115 |
# Preprocessing the datasets.
|
116 |
# We need to read the aduio files as arrays
|
117 |
def evaluate(batch):
|
118 |
-
|
119 |
|
120 |
-
|
121 |
-
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
|
127 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
128 |
|
|
|
26 |
value: 48.40
|
27 |
---
|
28 |
|
29 |
+
# Wav2Vec2-Large-XLSR-53-Chuvash
|
30 |
|
31 |
Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Chuvash using the [Common Voice](https://huggingface.co/datasets/common_voice)
|
32 |
|
|
|
52 |
# Preprocessing the datasets.
|
53 |
# We need to read the aduio files as arrays
|
54 |
def speech_file_to_array_fn(batch):
|
55 |
+
\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
56 |
+
\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
57 |
+
\treturn batch
|
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 |
+
\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
64 |
|
65 |
predicted_ids = torch.argmax(logits, dim=-1)
|
66 |
|
|
|
71 |
|
72 |
#### Results:
|
73 |
|
74 |
+
Prediction: ['проектпа килӗшӳллӗн тӗлӗ мероприяти иртермелле', 'твăра çак планета минтӗ пуяни калленнана']
|
|
|
|
|
75 |
|
76 |
+
Reference: ['Проектпа килӗшӳллӗн, тӗрлӗ мероприяти ирттермелле.', 'Çак планета питĕ пуян иккен.']
|
77 |
## Evaluation
|
78 |
|
79 |
The model can be evaluated as follows on the Chuvash test data of Common Voice.
|
|
|
98 |
|
99 |
|
100 |
|
101 |
+
chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]' # TODO: adapt this list to include all special characters you removed from the data
|
102 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
103 |
|
104 |
# Preprocessing the datasets.
|
105 |
# We need to read the aduio files as arrays
|
106 |
def speech_file_to_array_fn(batch):
|
107 |
+
\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
108 |
+
\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
109 |
+
\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
110 |
+
\treturn batch
|
111 |
|
112 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
113 |
|
114 |
# Preprocessing the datasets.
|
115 |
# We need to read the aduio files as arrays
|
116 |
def evaluate(batch):
|
117 |
+
\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
118 |
|
119 |
+
\twith torch.no_grad():
|
120 |
+
\t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
121 |
|
122 |
+
\tpred_ids = torch.argmax(logits, dim=-1)
|
123 |
+
\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
|
124 |
+
\treturn batch
|
125 |
|
126 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
127 |
|