CuongLD commited on
Commit
a46c64d
1 Parent(s): 8a7ee00

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +17 -17
README.md CHANGED
@@ -2,7 +2,7 @@
2
  language: vi
3
  datasets:
4
  - common_voice
5
- - infore_25h voice dataset
6
  (link: https://files.huylenguyen.com/25hours.zip , Password: BroughtToYouByInfoRe)
7
 
8
  metrics:
@@ -14,7 +14,7 @@ tags:
14
  - xlsr-fine-tuning-week
15
  license: apache-2.0
16
  model-index:
17
- - name: {Cuong-Cong XLSR Wav2Vec2 Large 53}
18
  results:
19
  - task:
20
  name: Speech Recognition
@@ -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
 
@@ -89,30 +89,30 @@ processor = Wav2Vec2Processor.from_pretrained("CuongLD/wav2vec2-large-xlsr-vietn
89
  model = Wav2Vec2ForCTC.from_pretrained("CuongLD/wav2vec2-large-xlsr-vietnamese")
90
  model.to("cuda")
91
 
92
- chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“]'
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
- batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
99
- speech_array, sampling_rate = torchaudio.load(batch["path"])
100
- batch["speech"] = resampler(speech_array).squeeze().numpy()
101
- return 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
- inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
109
 
110
- with torch.no_grad():
111
- logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
112
 
113
- pred_ids = torch.argmax(logits, dim=-1)
114
- batch["pred_strings"] = processor.batch_decode(pred_ids)
115
- return batch
116
 
117
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
118
 
 
2
  language: vi
3
  datasets:
4
  - common_voice
5
+ - infore_25h dataset
6
  (link: https://files.huylenguyen.com/25hours.zip , Password: BroughtToYouByInfoRe)
7
 
8
  metrics:
 
14
  - xlsr-fine-tuning-week
15
  license: apache-2.0
16
  model-index:
17
+ - name: Cuong-Cong XLSR Wav2Vec2 Large 53
18
  results:
19
  - task:
20
  name: Speech Recognition
 
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
 
 
89
  model = Wav2Vec2ForCTC.from_pretrained("CuongLD/wav2vec2-large-xlsr-vietnamese")
90
  model.to("cuda")
91
 
92
+ chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]'
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