arampacha commited on
Commit
cadb64c
1 Parent(s): a652e11

upd readme

Browse files
Files changed (1) hide show
  1. README.md +21 -21
README.md CHANGED
@@ -48,15 +48,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
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 {language} test data of Common Voice. # TODO: replace #TODO: replace language with your {language}, *e.g.* French
71
 
72
 
73
  ```python
@@ -92,30 +92,30 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
92
  # We need to read the aduio files as arrays
93
  # Note: this models is trained ignoring accents on letters as below
94
  def speech_file_to_array_fn(batch):
95
- \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().strip()
96
- \tbatch["sentence"] = re.sub(re.compile('[äá]'), 'a', batch['sentence'])
97
- \tbatch["sentence"] = re.sub(re.compile('[öó]'), 'o', batch['sentence'])
98
- \tbatch["sentence"] = re.sub(re.compile('[èé]'), 'e', batch['sentence'])
99
- \tbatch["sentence"] = re.sub(re.compile("[ïí]"), 'i', batch['sentence'])
100
- \tbatch["sentence"] = re.sub(re.compile("[üů]"), 'u', batch['sentence'])
101
- \tbatch['sentence'] = re.sub(' ', ' ', batch['sentence'])
102
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
103
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
104
- \treturn batch
105
 
106
  test_dataset = test_dataset.map(speech_file_to_array_fn)
107
 
108
  # Preprocessing the datasets.
109
  # We need to read the aduio files as arrays
110
  def evaluate(batch):
111
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
112
 
113
- \twith torch.no_grad():
114
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
115
 
116
- \tpred_ids = torch.argmax(logits, dim=-1)
117
- \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
118
- \treturn batch
119
 
120
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
121
 
 
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 Czech test data of Common Voice.
71
 
72
 
73
  ```python
 
92
  # We need to read the aduio files as arrays
93
  # Note: this models is trained ignoring accents on letters as below
94
  def speech_file_to_array_fn(batch):
95
+ \\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().strip()
96
+ \\tbatch["sentence"] = re.sub(re.compile('[äá]'), 'a', batch['sentence'])
97
+ \\tbatch["sentence"] = re.sub(re.compile('[öó]'), 'o', batch['sentence'])
98
+ \\tbatch["sentence"] = re.sub(re.compile('[èé]'), 'e', batch['sentence'])
99
+ \\tbatch["sentence"] = re.sub(re.compile("[ïí]"), 'i', batch['sentence'])
100
+ \\tbatch["sentence"] = re.sub(re.compile("[üů]"), 'u', batch['sentence'])
101
+ \\tbatch['sentence'] = re.sub(' ', ' ', batch['sentence'])
102
+ \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
103
+ \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
104
+ \\treturn batch
105
 
106
  test_dataset = test_dataset.map(speech_file_to_array_fn)
107
 
108
  # Preprocessing the datasets.
109
  # We need to read the aduio files as arrays
110
  def evaluate(batch):
111
+ \\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
112
 
113
+ \\twith torch.no_grad():
114
+ \\t\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
115
 
116
+ \\tpred_ids = torch.argmax(logits, dim=-1)
117
+ \\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
118
+ \\treturn batch
119
 
120
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
121