patrickvonplaten commited on
Commit
f373715
1 Parent(s): 0b6a34f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +15 -15
README.md CHANGED
@@ -53,15 +53,15 @@ resampler = lambda sampling_rate, y: librosa.resample(y.numpy().squeeze(), sampl
53
  # Preprocessing the datasets.
54
  # We need to read the audio files as arrays
55
  def speech_file_to_array_fn(batch):
56
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
57
- \tbatch["speech"] = resampler(sampling_rate, speech_array).squeeze()
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
 
@@ -90,30 +90,30 @@ processor = Wav2Vec2Processor.from_pretrained("xsway/wav2vec2-large-xlsr-georgia
90
  model = Wav2Vec2ForCTC.from_pretrained("xsway/wav2vec2-large-xlsr-georgian")
91
  model.to("cuda")
92
 
93
- chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]'
94
  resampler = lambda sampling_rate, y: librosa.resample(y.numpy().squeeze(), sampling_rate, 16_000)
95
 
96
  # Preprocessing the datasets.
97
  # We need to read the audio files as arrays
98
  def speech_file_to_array_fn(batch):
99
- \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
100
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
101
- \tbatch["speech"] = resampler(sampling_rate, speech_array).squeeze()
102
- \treturn batch
103
 
104
  test_dataset = test_dataset.map(speech_file_to_array_fn)
105
 
106
  # Preprocessing the datasets.
107
  # We need to read the audio files as arrays
108
  def evaluate(batch):
109
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
110
 
111
- \twith torch.no_grad():
112
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
113
 
114
- \tpred_ids = torch.argmax(logits, dim=-1)
115
- \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
116
- \treturn batch
117
 
118
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
119
 
53
  # Preprocessing the datasets.
54
  # We need to read the audio files as arrays
55
  def speech_file_to_array_fn(batch):
56
+ \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
57
+ \\tbatch["speech"] = resampler(sampling_rate, speech_array).squeeze()
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
 
90
  model = Wav2Vec2ForCTC.from_pretrained("xsway/wav2vec2-large-xlsr-georgian")
91
  model.to("cuda")
92
 
93
+ chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]'
94
  resampler = lambda sampling_rate, y: librosa.resample(y.numpy().squeeze(), sampling_rate, 16_000)
95
 
96
  # Preprocessing the datasets.
97
  # We need to read the audio 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(sampling_rate, speech_array).squeeze()
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 audio 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