gvs commited on
Commit
a54d8f3
1 Parent(s): e866430

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -19
README.md CHANGED
@@ -1,9 +1,9 @@
1
  ---
2
  language: ml
3
  datasets:
4
- - [Indic TTS Malayalam Speech Corpus (via Kaggle)](https://www.kaggle.com/kavyamanohar/indic-tts-malayalam-speech-corpus)
5
- - [Openslr Malayalam Speech Corpus](http://openslr.org/63/)
6
- - [SMC Malayalam Speech Corpus](https://blog.smc.org.in/malayalam-speech-corpus/)
7
  metrics:
8
  - wer
9
  tags:
@@ -53,15 +53,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
53
  # Preprocessing the datasets.
54
  # We need to read the audio files as arrays
55
  def speech_file_to_array_fn(batch):
56
- speech_array, sampling_rate = torchaudio.load(batch["path"])
57
- batch["speech"] = resampler(speech_array).squeeze().numpy()
58
- return 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
- logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
65
 
66
  predicted_ids = torch.argmax(logits, dim=-1)
67
 
@@ -90,33 +90,33 @@ processor = Wav2Vec2Processor.from_pretrained("gvs/wav2vec2-large-xlsr-malayalam
90
  model = Wav2Vec2ForCTC.from_pretrained("gvs/wav2vec2-large-xlsr-malayalam")
91
  model.to("cuda")
92
 
93
- chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�Utrnle\_]'
94
- unicode_ignore_regex = r'[\u200d\u200c\u200e]'
95
 
96
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
97
 
98
  # Preprocessing the datasets.
99
  # We need to read the audio files as arrays
100
  def speech_file_to_array_fn(batch):
101
- batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"])
102
  batch["sentence"] = re.sub(unicode_ignore_regex, '', batch["sentence"])
103
- speech_array, sampling_rate = torchaudio.load(batch["path"])
104
- batch["speech"] = resampler(speech_array).squeeze().numpy()
105
- return batch
106
 
107
  test_dataset = test_dataset.map(speech_file_to_array_fn)
108
 
109
  # Preprocessing the datasets.
110
  # We need to read the audio files as arrays
111
  def evaluate(batch):
112
- inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
113
 
114
- with torch.no_grad():
115
- logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
116
 
117
- pred_ids = torch.argmax(logits, dim=-1)
118
- batch["pred_strings"] = processor.batch_decode(pred_ids)
119
- return batch
120
 
121
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
122
 
1
  ---
2
  language: ml
3
  datasets:
4
+ - Indic TTS Malayalam Speech Corpus
5
+ - Openslr Malayalam Speech Corpus
6
+ - SMC Malayalam Speech Corpus
7
  metrics:
8
  - wer
9
  tags:
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(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
 
90
  model = Wav2Vec2ForCTC.from_pretrained("gvs/wav2vec2-large-xlsr-malayalam")
91
  model.to("cuda")
92
 
93
+ chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“\\%\\‘\\”\\�Utrnle\\_]'
94
+ unicode_ignore_regex = r'[\\u200d\\u200c\\u200e]'
95
 
96
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
97
 
98
  # Preprocessing the datasets.
99
  # We need to read the audio files as arrays
100
  def speech_file_to_array_fn(batch):
101
+ \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"])
102
  batch["sentence"] = re.sub(unicode_ignore_regex, '', batch["sentence"])
103
+ \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
104
+ \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
105
+ \treturn batch
106
 
107
  test_dataset = test_dataset.map(speech_file_to_array_fn)
108
 
109
  # Preprocessing the datasets.
110
  # We need to read the audio files as arrays
111
  def evaluate(batch):
112
+ \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
113
 
114
+ \twith torch.no_grad():
115
+ \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
116
 
117
+ \tpred_ids = torch.argmax(logits, dim=-1)
118
+ \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
119
+ \treturn batch
120
 
121
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
122