mrm8488 commited on
Commit
1d90083
1 Parent(s): f2d8ee7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -19
README.md CHANGED
@@ -40,23 +40,23 @@ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
40
 
41
  test_dataset = load_dataset("common_voice", "es, split="test[:2%]").
42
 
43
- processor = Wav2Vec2Processor.from_pretrained("mrm8488/wav2vec2-large-xlsr-53-spanish")
44
- model = Wav2Vec2ForCTC.from_pretrained("mrm8488/wav2vec2-large-xlsr-53-spanish")
45
 
46
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
47
 
48
  # Preprocessing the datasets.
49
  # We need to read the aduio files as arrays
50
  def speech_file_to_array_fn(batch):
51
- \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
52
- \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
53
- \\treturn batch
54
 
55
  test_dataset = test_dataset.map(speech_file_to_array_fn)
56
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
57
 
58
  with torch.no_grad():
59
- \\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
60
 
61
  predicted_ids = torch.argmax(logits, dim=-1)
62
 
@@ -67,7 +67,7 @@ print("Reference:", test_dataset["sentence"][:2])
67
 
68
  ## Evaluation
69
 
70
- The model can be evaluated as follows on the Spanish test data of Common Voice.
71
 
72
 
73
  ```python
@@ -80,34 +80,34 @@ import re
80
  test_dataset = load_dataset("common_voice", "es", split="test")
81
  wer = load_metric("wer")
82
 
83
- processor = Wav2Vec2Processor.from_pretrained("mrm8488/wav2vec2-large-xlsr-53-spanish")
84
- model = Wav2Vec2ForCTC.from_pretrained("mrm8488/wav2vec2-large-xlsr-53-spanish")
85
  model.to("cuda")
86
 
87
- chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]'
88
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
89
 
90
  # Preprocessing the datasets.
91
  # We need to read the aduio files as arrays
92
  def speech_file_to_array_fn(batch):
93
- \\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
94
- \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
95
- \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
96
- \\treturn 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
- \\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
104
 
105
- \\twith torch.no_grad():
106
- \\t\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
107
 
108
  pred_ids = torch.argmax(logits, dim=-1)
109
- \\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
110
- \\treturn batch
111
 
112
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
113
 
40
 
41
  test_dataset = load_dataset("common_voice", "es, split="test[:2%]").
42
 
43
+ processor = Wav2Vec2Processor.from_pretrained("mrm8488/wav2vec2-large-xlsr-53-euskera")
44
+ model = Wav2Vec2ForCTC.from_pretrained("mrm8488/wav2vec2-large-xlsr-53-euskera")
45
 
46
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
47
 
48
  # Preprocessing the datasets.
49
  # We need to read the aduio files as arrays
50
  def speech_file_to_array_fn(batch):
51
+ \\\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
52
+ \\\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
53
+ \\\\treturn batch
54
 
55
  test_dataset = test_dataset.map(speech_file_to_array_fn)
56
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
57
 
58
  with torch.no_grad():
59
+ \\\\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
60
 
61
  predicted_ids = torch.argmax(logits, dim=-1)
62
 
67
 
68
  ## Evaluation
69
 
70
+ The model can be evaluated as follows on the Euskera test data of Common Voice.
71
 
72
 
73
  ```python
80
  test_dataset = load_dataset("common_voice", "es", split="test")
81
  wer = load_metric("wer")
82
 
83
+ processor = Wav2Vec2Processor.from_pretrained("mrm8488/wav2vec2-large-xlsr-53-euskera")
84
+ model = Wav2Vec2ForCTC.from_pretrained("mrm8488/wav2vec2-large-xlsr-53-euskera")
85
  model.to("cuda")
86
 
87
+ chars_to_ignore_regex = '[\\\\\\\\,\\\\\\\\?\\\\\\\\.\\\\\\\\!\\\\\\\\-\\\\\\\\;\\\\\\\\:\\\\\\\\"\\\\\\\\“]'
88
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
89
 
90
  # Preprocessing the datasets.
91
  # We need to read the aduio files as arrays
92
  def speech_file_to_array_fn(batch):
93
+ \\\\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
94
+ \\\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
95
+ \\\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
96
+ \\\\treturn 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
+ \\\\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
104
 
105
+ \\\\twith torch.no_grad():
106
+ \\\\t\\\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
107
 
108
  pred_ids = torch.argmax(logits, dim=-1)
109
+ \\\\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
110
+ \\\\treturn batch
111
 
112
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
113