Rajaram Sivaramakrishnan
commited on
Commit
·
12c8ba0
1
Parent(s):
5d4f7a9
update eval script
Browse files
README.md
CHANGED
@@ -21,7 +21,7 @@ model-index:
|
|
21 |
metrics:
|
22 |
- name: Test WER
|
23 |
type: wer
|
24 |
-
value:
|
25 |
---
|
26 |
# Wav2Vec2-Large-XLSR-53-tamil
|
27 |
|
@@ -49,16 +49,16 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
49 |
# We need to read the aduio files as arrays
|
50 |
|
51 |
def speech_file_to_array_fn(batch):
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
57 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
58 |
|
59 |
with torch.no_grad():
|
60 |
-
|
61 |
-
|
62 |
predicted_ids = torch.argmax(logits, dim=-1)
|
63 |
print("Prediction:", processor.batch_decode(predicted_ids))
|
64 |
print("Reference:", test_dataset["sentence"][:2])
|
@@ -79,8 +79,8 @@ test_dataset = load_dataset("common_voice", "ta", split="test")
|
|
79 |
|
80 |
wer = load_metric("wer")
|
81 |
|
82 |
-
processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
|
83 |
-
model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
|
84 |
|
85 |
model.to("cuda")
|
86 |
chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]'
|
@@ -90,25 +90,25 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
90 |
# Preprocessing the datasets.
|
91 |
# We need to read the aduio files as arrays
|
92 |
def speech_file_to_array_fn(batch):
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
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 |
-
|
104 |
-
|
105 |
-
|
106 |
pred_ids = torch.argmax(logits, dim=-1)
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
111 |
-
print("WER: {:2f}".format(100 * wer.compute(predictions=result["
|
112 |
```
|
113 |
|
114 |
-
**Test Result**:
|
|
|
21 |
metrics:
|
22 |
- name: Test WER
|
23 |
type: wer
|
24 |
+
value: 69.76
|
25 |
---
|
26 |
# Wav2Vec2-Large-XLSR-53-tamil
|
27 |
|
|
|
49 |
# We need to read the aduio files as arrays
|
50 |
|
51 |
def speech_file_to_array_fn(batch):
|
52 |
+
\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
53 |
+
\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
54 |
+
\\treturn batch
|
55 |
+
\\t
|
56 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
57 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
58 |
|
59 |
with torch.no_grad():
|
60 |
+
\\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
61 |
+
\\t
|
62 |
predicted_ids = torch.argmax(logits, dim=-1)
|
63 |
print("Prediction:", processor.batch_decode(predicted_ids))
|
64 |
print("Reference:", test_dataset["sentence"][:2])
|
|
|
79 |
|
80 |
wer = load_metric("wer")
|
81 |
|
82 |
+
processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-53-tamil")
|
83 |
+
model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-53-tamil")
|
84 |
|
85 |
model.to("cuda")
|
86 |
chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]'
|
|
|
90 |
# Preprocessing the datasets.
|
91 |
# We need to read the aduio files as arrays
|
92 |
def speech_file_to_array_fn(batch):
|
93 |
+
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
94 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
95 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
96 |
+
return 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 |
+
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
104 |
+
with torch.no_grad():
|
105 |
+
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
106 |
pred_ids = torch.argmax(logits, dim=-1)
|
107 |
+
batch["pred_strings"] = processor.batch_decode(pred_ids)
|
108 |
+
return batch
|
109 |
+
|
110 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
111 |
+
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
112 |
```
|
113 |
|
114 |
+
**Test Result**: 69.76 %
|