joaoalvarenga commited on
Commit
f19d1b8
1 Parent(s): 89a63da

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -16
README.md CHANGED
@@ -33,9 +33,9 @@ model-index:
33
  ---
34
 
35
 
36
- # Wav2Vec2-Large-XLSR-53-Spanish
37
 
38
- Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Spanish using the [Common Voice](https://huggingface.co/datasets/common_voice) dataset.
39
 
40
  ## Usage
41
 
@@ -58,14 +58,14 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
58
  # We need to read the aduio files as arrays
59
  def speech_file_to_array_fn(batch):
60
  tspeech_array, sampling_rate = torchaudio.load(batch["path"])
61
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
62
- \treturn batch
63
 
64
  test_dataset = test_dataset.map(speech_file_to_array_fn)
65
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
66
 
67
  with torch.no_grad():
68
- \tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
69
 
70
  predicted_ids = torch.argmax(logits, dim=-1)
71
 
@@ -93,30 +93,30 @@ processor = Wav2Vec2Processor.from_pretrained("joorock12/wav2vec2-large-xlsr-53-
93
  model = Wav2Vec2ForCTC.from_pretrained("joorock12/wav2vec2-large-xlsr-53-portuguese")
94
  model.to("cuda")
95
 
96
- chars_to_ignore_regex = '[\\\\\\\\\\\\\\\\,\\\\\\\\\\\\\\\\?\\\\\\\\\\\\\\\\.\\\\\\\\\\\\\\\\!\\\\\\\\\\\\\\\\-\\\\\\\\\\\\\\\\;\\\\\\\\\\\\\\\\:\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\“]' # TODO: adapt this list to include all special characters you removed from the data
97
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
98
 
99
  # Preprocessing the datasets.
100
  # We need to read the aduio files as arrays
101
  def speech_file_to_array_fn(batch):
102
- \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
103
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
104
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
105
- \treturn batch
106
 
107
  test_dataset = test_dataset.map(speech_file_to_array_fn)
108
 
109
  # Preprocessing the datasets.
110
  # We need to read the aduio files as arrays
111
  def evaluate(batch):
112
- \\\\\\\\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
113
 
114
- \\\\\\\\twith torch.no_grad():
115
- \\\\\\\\t\\\\\\\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
116
 
117
  pred_ids = torch.argmax(logits, dim=-1)
118
- \\\\\\\\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
119
- \\\\\\\\treturn batch
120
 
121
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
122
 
@@ -130,4 +130,4 @@ print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"],
130
 
131
  The Common Voice `train`, `validation` datasets were used for training.
132
 
133
- The script used for training can be found at: https://github.com/joaoalvarenga/wav2vec2-large-xlsr-53-spanish/blob/main/fine-tuning.py
 
33
  ---
34
 
35
 
36
+ # Wav2Vec2-Large-XLSR-53-Portuguese
37
 
38
+ Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Portuguese using the [Common Voice](https://huggingface.co/datasets/common_voice) dataset.
39
 
40
  ## Usage
41
 
 
58
  # We need to read the aduio files as arrays
59
  def speech_file_to_array_fn(batch):
60
  tspeech_array, sampling_rate = torchaudio.load(batch["path"])
61
+ \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
62
+ \\treturn batch
63
 
64
  test_dataset = test_dataset.map(speech_file_to_array_fn)
65
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
66
 
67
  with torch.no_grad():
68
+ \\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
69
 
70
  predicted_ids = torch.argmax(logits, dim=-1)
71
 
 
93
  model = Wav2Vec2ForCTC.from_pretrained("joorock12/wav2vec2-large-xlsr-53-portuguese")
94
  model.to("cuda")
95
 
96
+ chars_to_ignore_regex = '[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\!\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\“]' # TODO: adapt this list to include all special characters you removed from the data
97
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
98
 
99
  # Preprocessing the datasets.
100
  # We need to read the aduio files as arrays
101
  def speech_file_to_array_fn(batch):
102
+ \\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
103
+ \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
104
+ \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
105
+ \\treturn batch
106
 
107
  test_dataset = test_dataset.map(speech_file_to_array_fn)
108
 
109
  # Preprocessing the datasets.
110
  # We need to read the aduio files as arrays
111
  def evaluate(batch):
112
+ \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
113
 
114
+ \twith torch.no_grad():
115
+ \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
116
 
117
  pred_ids = torch.argmax(logits, dim=-1)
118
+ \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
119
+ \treturn batch
120
 
121
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
122
 
 
130
 
131
  The Common Voice `train`, `validation` datasets were used for training.
132
 
133
+ The script used for training can be found at: https://github.com/joaoalvarenga/wav2vec2-large-xlsr-53-portuguese/blob/main/fine-tuning.py