Rajaram Sivaramakrishnan commited on
Commit
a66c39d
1 Parent(s): 12c8ba0

update prediction script

Browse files
Files changed (1) hide show
  1. README.md +9 -9
README.md CHANGED
@@ -40,8 +40,8 @@ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
40
 
41
  test_dataset = load_dataset("common_voice", "ta", split="test[:2%]")
42
 
43
- processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
44
- model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
45
 
46
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
47
 
@@ -49,16 +49,16 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
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,7 +83,7 @@ processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-5
83
  model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-53-tamil")
84
 
85
  model.to("cuda")
86
- chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]'
87
 
88
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
89
 
 
40
 
41
  test_dataset = load_dataset("common_voice", "ta", split="test[:2%]")
42
 
43
+ processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-53-tamil")
44
+ model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-53-tamil")
45
 
46
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
47
 
 
49
  # We need to read the aduio files as arrays
50
 
51
  def speech_file_to_array_fn(batch):
52
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
53
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
54
+ return batch
55
+
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
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
61
+
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-53-tamil")
84
 
85
  model.to("cuda")
86
+ chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]'
87
 
88
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
89