shahukareem commited on
Commit
e8da1fd
·
1 Parent(s): 053169a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +15 -18
README.md CHANGED
@@ -19,9 +19,6 @@ model-index:
19
  name: Common Voice dv
20
  type: common_voice
21
  args: dv
22
- metrics:
23
- - name: Test WER
24
- type: wer
25
  ---
26
  # Wav2Vec2-Large-XLSR-53-Dhivehi
27
  Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Dhivehi using the [Common Voice](https://huggingface.co/datasets/common_voice).
@@ -39,13 +36,13 @@ model = Wav2Vec2ForCTC.from_pretrained("shahukareem/wav2vec2-large-xlsr-53-dhive
39
  # Preprocessing the datasets.
40
  # We need to read the aduio files as arrays
41
  def speech_file_to_array_fn(batch):
42
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
43
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
44
- \treturn batch
45
  test_dataset = test_dataset.map(speech_file_to_array_fn)
46
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
47
  with torch.no_grad():
48
- \tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
49
  predicted_ids = torch.argmax(logits, dim=-1)
50
  print("Prediction:", processor.batch_decode(predicted_ids))
51
  print("Reference:", test_dataset["sentence"][:2])
@@ -68,20 +65,20 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
68
  # Preprocessing the datasets.
69
  # We need to read the aduio files as arrays
70
  def speech_file_to_array_fn(batch):
71
- \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
72
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
73
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
74
- \treturn batch
75
  test_dataset = test_dataset.map(speech_file_to_array_fn)
76
  # Preprocessing the datasets.
77
  # We need to read the aduio files as arrays
78
  def evaluate(batch):
79
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
80
- \twith torch.no_grad():
81
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
82
- \tpred_ids = torch.argmax(logits, dim=-1)
83
- \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
84
- \treturn batch
85
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
86
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
87
- ```
 
19
  name: Common Voice dv
20
  type: common_voice
21
  args: dv
 
 
 
22
  ---
23
  # Wav2Vec2-Large-XLSR-53-Dhivehi
24
  Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Dhivehi using the [Common Voice](https://huggingface.co/datasets/common_voice).
 
36
  # Preprocessing the datasets.
37
  # We need to read the aduio files as arrays
38
  def speech_file_to_array_fn(batch):
39
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
40
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
41
+ return batch
42
  test_dataset = test_dataset.map(speech_file_to_array_fn)
43
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
44
  with torch.no_grad():
45
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
46
  predicted_ids = torch.argmax(logits, dim=-1)
47
  print("Prediction:", processor.batch_decode(predicted_ids))
48
  print("Reference:", test_dataset["sentence"][:2])
 
65
  # Preprocessing the datasets.
66
  # We need to read the aduio files as arrays
67
  def speech_file_to_array_fn(batch):
68
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
69
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
70
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
71
+ return batch
72
  test_dataset = test_dataset.map(speech_file_to_array_fn)
73
  # Preprocessing the datasets.
74
  # We need to read the aduio files as arrays
75
  def evaluate(batch):
76
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
77
+ with torch.no_grad():
78
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
79
+ pred_ids = torch.argmax(logits, dim=-1)
80
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
81
+ return batch
82
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
83
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
84
+ ```