Rajaram Sivaramakrishnan commited on
Commit
5d4f7a9
·
1 Parent(s): ca1429f

turn on inference

Browse files
Files changed (1) hide show
  1. README.md +18 -19
README.md CHANGED
@@ -8,7 +8,6 @@ tags:
8
  - speech
9
  - xlsr-fine-tuning-week
10
  license: apache-2.0
11
- inference: false
12
  model-index:
13
  - name: Rajaram1996/wav2vec2-large-xlsr-tamil
14
  results:
@@ -50,16 +49,16 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
50
  # We need to read the aduio files as arrays
51
 
52
  def speech_file_to_array_fn(batch):
53
- speech_array, sampling_rate = torchaudio.load(batch["path"])
54
- batch["speech"] = resampler(speech_array).squeeze().numpy()
55
- return batch
56
-
57
  test_dataset = test_dataset.map(speech_file_to_array_fn)
58
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
59
 
60
  with torch.no_grad():
61
- logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
62
-
63
  predicted_ids = torch.argmax(logits, dim=-1)
64
  print("Prediction:", processor.batch_decode(predicted_ids))
65
  print("Reference:", test_dataset["sentence"][:2])
@@ -84,30 +83,30 @@ processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-t
84
  model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
85
 
86
  model.to("cuda")
87
- chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“]'
88
 
89
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
90
 
91
  # Preprocessing the datasets.
92
  # We need to read the aduio files as arrays
93
  def speech_file_to_array_fn(batch):
94
- batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
95
- speech_array, sampling_rate = torchaudio.load(batch["path"])
96
- batch["speech"] = resampler(speech_array).squeeze().numpy()
97
- return batch
98
-
99
  test_dataset = test_dataset.map(speech_file_to_array_fn)
100
 
101
  # Preprocessing the datasets.
102
  # We need to read the aduio files as arrays
103
  def evaluate(batch):
104
- inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
105
- with torch.no_grad():
106
- logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
107
  pred_ids = torch.argmax(logits, dim=-1)
108
- batch["pred_strings"] = processor.batch_decode(pred_ids)
109
- return batch
110
-
111
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
112
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["predicted"], references=result["target"])))
113
  ```
 
8
  - speech
9
  - xlsr-fine-tuning-week
10
  license: apache-2.0
 
11
  model-index:
12
  - name: Rajaram1996/wav2vec2-large-xlsr-tamil
13
  results:
 
49
  # We need to read the aduio files as arrays
50
 
51
  def speech_file_to_array_fn(batch):
52
+ \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
53
+ \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
54
+ \treturn batch
55
+ \t
56
  test_dataset = test_dataset.map(speech_file_to_array_fn)
57
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
58
 
59
  with torch.no_grad():
60
+ \tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
61
+ \t
62
  predicted_ids = torch.argmax(logits, dim=-1)
63
  print("Prediction:", processor.batch_decode(predicted_ids))
64
  print("Reference:", test_dataset["sentence"][:2])
 
83
  model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
84
 
85
  model.to("cuda")
86
+ chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]'
87
 
88
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
89
 
90
  # Preprocessing the datasets.
91
  # We need to read the aduio files as arrays
92
  def speech_file_to_array_fn(batch):
93
+ \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
94
+ \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
95
+ \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
96
+ \treturn batch
97
+ \t
98
  test_dataset = test_dataset.map(speech_file_to_array_fn)
99
 
100
  # Preprocessing the datasets.
101
  # We need to read the aduio files as arrays
102
  def evaluate(batch):
103
+ \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
104
+ \twith torch.no_grad():
105
+ \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
106
  pred_ids = torch.argmax(logits, dim=-1)
107
+ \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
108
+ \treturn batch
109
+ \t
110
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
111
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["predicted"], references=result["target"])))
112
  ```