gagan3012 commited on
Commit
ac53881
1 Parent(s): 9c1bbd1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -16
README.md CHANGED
@@ -30,7 +30,7 @@ model-index:
30
 
31
  # Wav2Vec2-Large-XLSR-53-Nepali
32
 
33
- Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Nepali using the [Common Voice](https://huggingface.co/datasets/common_voice), ... and ... dataset OpenSLR ne.
34
 
35
  When using this model, make sure that your speech input is sampled at 16kHz.
36
 
@@ -54,15 +54,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
 
@@ -95,30 +95,30 @@ processor = Wav2Vec2Processor.from_pretrained("gagan3012/wav2vec2-xlsr-nepali")
95
  model = Wav2Vec2ForCTC.from_pretrained("gagan3012/wav2vec2-xlsr-nepali")
96
  model.to("cuda")
97
 
98
- chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“]' # TODO: adapt this list to include all special characters you removed from the data
99
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
100
 
101
  # Preprocessing the datasets.
102
  # We need to read the aduio files as arrays
103
  def speech_file_to_array_fn(batch):
104
- batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
105
- speech_array, sampling_rate = torchaudio.load(batch["path"])
106
- batch["speech"] = resampler(speech_array).squeeze().numpy()
107
- return batch
108
 
109
  test_dataset = test_dataset.map(speech_file_to_array_fn)
110
 
111
  # Preprocessing the datasets.
112
  # We need to read the aduio files as arrays
113
  def evaluate(batch):
114
- inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
115
 
116
- with torch.no_grad():
117
- logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
118
 
119
- pred_ids = torch.argmax(logits, dim=-1)
120
- batch["pred_strings"] = processor.batch_decode(pred_ids)
121
- return batch
122
 
123
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
124
 
 
30
 
31
  # Wav2Vec2-Large-XLSR-53-Nepali
32
 
33
+ Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Nepali using the [Common Voice](https://huggingface.co/datasets/common_voice), and [OpenSLR ne](http://www.openslr.org/43/).
34
 
35
  When using this model, make sure that your speech input is sampled at 16kHz.
36
 
 
54
  # Preprocessing the datasets.
55
  # We need to read the aduio files as arrays
56
  def speech_file_to_array_fn(batch):
57
+ \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
58
+ \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
59
+ \treturn 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
+ \tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
66
 
67
  predicted_ids = torch.argmax(logits, dim=-1)
68
 
 
95
  model = Wav2Vec2ForCTC.from_pretrained("gagan3012/wav2vec2-xlsr-nepali")
96
  model.to("cuda")
97
 
98
+ chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]' # TODO: adapt this list to include all special characters you removed from the data
99
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
100
 
101
  # Preprocessing the datasets.
102
  # We need to read the aduio files as arrays
103
  def speech_file_to_array_fn(batch):
104
+ \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
105
+ \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
106
+ \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
107
+ \treturn batch
108
 
109
  test_dataset = test_dataset.map(speech_file_to_array_fn)
110
 
111
  # Preprocessing the datasets.
112
  # We need to read the aduio files as arrays
113
  def evaluate(batch):
114
+ \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
115
 
116
+ \twith torch.no_grad():
117
+ \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
118
 
119
+ \tpred_ids = torch.argmax(logits, dim=-1)
120
+ \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
121
+ \treturn batch
122
 
123
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
124