jonatasgrosman commited on
Commit
470f466
1 Parent(s): 8433ab8

adjust README

Browse files
Files changed (1) hide show
  1. README.md +11 -11
README.md CHANGED
@@ -23,7 +23,7 @@ model-index:
23
  metrics:
24
  - name: Test WER
25
  type: wer
26
- value: 13.45
27
  ---
28
 
29
  # Wav2Vec2-Large-XLSR-53-portuguese
@@ -54,23 +54,23 @@ model = Wav2Vec2ForCTC.from_pretrained(MODEL_ID)
54
  # Preprocessing the datasets.
55
  # We need to read the audio files as arrays
56
  def speech_file_to_array_fn(batch):
57
- speech_array, sampling_rate = librosa.load(batch["path"], sr=16_000)
58
- batch["speech"] = resampler(speech_array).squeeze().numpy()
59
- return batch
 
60
 
61
  test_dataset = test_dataset.map(speech_file_to_array_fn)
62
- inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
63
 
64
  with torch.no_grad():
65
- logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
66
 
67
  predicted_ids = torch.argmax(logits, dim=-1)
68
 
69
  print("Prediction:", processor.batch_decode(predicted_ids))
70
- print("Reference:", test_dataset["sentence"][:2])
71
  ```
72
 
73
-
74
  ## Evaluation
75
 
76
  The model can be evaluated as follows on the Portuguese test data of Common Voice.
@@ -92,7 +92,7 @@ CHARS_TO_IGNORE = [",", "?", ".", "!", "-", ";", ":", '""', "%", "'", '"', "�"
92
  test_dataset = load_dataset("common_voice", LANG_ID, split="test")
93
  wer = load_metric("wer")
94
 
95
- chars_to_ignore_regex = f'[{re.escape("".join(CHARS_TO_IGNORE))}]'
96
 
97
  processor = Wav2Vec2Processor.from_pretrained(MODEL_ID)
98
  model = Wav2Vec2ForCTC.from_pretrained(MODEL_ID)
@@ -101,7 +101,7 @@ model.to(DEVICE)
101
  # Preprocessing the datasets.
102
  # We need to read the audio files as arrays
103
  def speech_file_to_array_fn(batch):
104
- batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).upper()
105
  speech_array, sampling_rate = librosa.load(batch["path"], sr=16_000)
106
  batch["speech"] = speech_array
107
  return batch
@@ -125,4 +125,4 @@ result = test_dataset.map(evaluate, batched=True, batch_size=32)
125
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
126
  ```
127
 
128
- **Test Result**: 13.45%
 
23
  metrics:
24
  - name: Test WER
25
  type: wer
26
+ value: 13.48
27
  ---
28
 
29
  # Wav2Vec2-Large-XLSR-53-portuguese
 
54
  # Preprocessing the datasets.
55
  # We need to read the audio files as arrays
56
  def speech_file_to_array_fn(batch):
57
+ speech_array, sampling_rate = librosa.load(batch["path"], sr=16_000)
58
+ batch["speech"] = speech_array
59
+ batch["sentence"] = batch["sentence"].upper()
60
+ return batch
61
 
62
  test_dataset = test_dataset.map(speech_file_to_array_fn)
63
+ inputs = processor(test_dataset[:2]["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
64
 
65
  with torch.no_grad():
66
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
67
 
68
  predicted_ids = torch.argmax(logits, dim=-1)
69
 
70
  print("Prediction:", processor.batch_decode(predicted_ids))
71
+ print("Reference:", test_dataset[:2]["sentence"])
72
  ```
73
 
 
74
  ## Evaluation
75
 
76
  The model can be evaluated as follows on the Portuguese test data of Common Voice.
 
92
  test_dataset = load_dataset("common_voice", LANG_ID, split="test")
93
  wer = load_metric("wer")
94
 
95
+ chars_to_ignore_regex = f"[{re.escape("".join(CHARS_TO_IGNORE))}]"
96
 
97
  processor = Wav2Vec2Processor.from_pretrained(MODEL_ID)
98
  model = Wav2Vec2ForCTC.from_pretrained(MODEL_ID)
 
101
  # Preprocessing the datasets.
102
  # We need to read the audio files as arrays
103
  def speech_file_to_array_fn(batch):
104
+ batch["sentence"] = re.sub(chars_to_ignore_regex, "", batch["sentence"]).upper()
105
  speech_array, sampling_rate = librosa.load(batch["path"], sr=16_000)
106
  batch["speech"] = speech_array
107
  return batch
 
125
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
126
  ```
127
 
128
+ **Test Result**: 13.48%