PereLluis13 commited on
Commit
d9a5de6
1 Parent(s): d547ea8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -17
README.md CHANGED
@@ -3,8 +3,7 @@
3
  language: el #TODO: replace {lang_id} in your language code here. Make sure the code is one of the *ISO codes* of [this](https://huggingface.co/languages) site.
4
  datasets:
5
  - common_voice #TODO: remove if you did not use the common voice dataset
6
- - TODO: add more datasets if you have used additional datasets. Make sure to use the exact same
7
- dataset name as the one found [here](https://huggingface.co/datasets). If the dataset can not be found in the official datasets, just give it a new name
8
  metrics:
9
  - wer
10
  tags:
@@ -54,15 +53,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
54
  # Preprocessing the datasets.
55
  # We need to read the aduio files as arrays
56
  def speech_file_to_array_fn(batch):
57
- speech_array, sampling_rate = torchaudio.load(batch["path"])
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
 
@@ -90,30 +89,30 @@ processor = Wav2Vec2Processor.from_pretrained("PereLluis13/wav2vec2-large-xlsr-5
90
  model = Wav2Vec2ForCTC.from_pretrained("PereLluis13/wav2vec2-large-xlsr-53-greek") #TODO: replace {model_id} with your model id. The model id consists of {your_username}/{your_modelname}, *e.g.* `elgeish/wav2vec2-large-xlsr-53-arabic`
91
  model.to("cuda")
92
 
93
- chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\'\�]' # TODO: adapt this list to include all special characters you removed from the data
94
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
95
 
96
  # Preprocessing the datasets.
97
  # We need to read the aduio files as arrays
98
  def speech_file_to_array_fn(batch):
99
- batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
100
- speech_array, sampling_rate = torchaudio.load(batch["path"])
101
- batch["speech"] = resampler(speech_array).squeeze().numpy()
102
- return batch
103
 
104
  test_dataset = test_dataset.map(speech_file_to_array_fn)
105
 
106
  # Preprocessing the datasets.
107
  # We need to read the aduio files as arrays
108
  def evaluate(batch):
109
- inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
110
 
111
- with torch.no_grad():
112
- logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
113
 
114
- pred_ids = torch.argmax(logits, dim=-1)
115
- batch["pred_strings"] = processor.batch_decode(pred_ids)
116
- return batch
117
 
118
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
119
 
3
  language: el #TODO: replace {lang_id} in your language code here. Make sure the code is one of the *ISO codes* of [this](https://huggingface.co/languages) site.
4
  datasets:
5
  - common_voice #TODO: remove if you did not use the common voice dataset
6
+ - CSS10
 
7
  metrics:
8
  - wer
9
  tags:
53
  # Preprocessing the datasets.
54
  # We need to read the aduio files as arrays
55
  def speech_file_to_array_fn(batch):
56
+ \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
57
+ \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
58
+ \treturn batch
59
 
60
  test_dataset = test_dataset.map(speech_file_to_array_fn)
61
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
62
 
63
  with torch.no_grad():
64
+ \tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
65
 
66
  predicted_ids = torch.argmax(logits, dim=-1)
67
 
89
  model = Wav2Vec2ForCTC.from_pretrained("PereLluis13/wav2vec2-large-xlsr-53-greek") #TODO: replace {model_id} with your model id. The model id consists of {your_username}/{your_modelname}, *e.g.* `elgeish/wav2vec2-large-xlsr-53-arabic`
90
  model.to("cuda")
91
 
92
+ chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“\\%\\'\\�]' # TODO: adapt this list to include all special characters you removed from the data
93
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
94
 
95
  # Preprocessing the datasets.
96
  # We need to read the aduio files as arrays
97
  def speech_file_to_array_fn(batch):
98
+ \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
99
+ \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
100
+ \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
101
+ \treturn batch
102
 
103
  test_dataset = test_dataset.map(speech_file_to_array_fn)
104
 
105
  # Preprocessing the datasets.
106
  # We need to read the aduio files as arrays
107
  def evaluate(batch):
108
+ \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
109
 
110
+ \twith torch.no_grad():
111
+ \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
112
 
113
+ \tpred_ids = torch.argmax(logits, dim=-1)
114
+ \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
115
+ \treturn batch
116
 
117
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
118