Ilyes Jeronymous commited on
Commit
ba9851d
1 Parent(s): a3233bc

Update README.md (#1)

Browse files

- Update README.md (c86d5adc3bccf8dcca8c00e8757675c0742e3ca5)


Co-authored-by: Jérôme Louradour <Jeronymous@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +3 -5
README.md CHANGED
@@ -39,15 +39,13 @@ import re
39
 
40
  model_name = "Ilyes/wav2vec2-large-xlsr-53-french"
41
 
 
42
 
43
-
44
- model = Wav2Vec2ForCTC.from_pretrained(model_name).to('cuda')
45
  processor = Wav2Vec2Processor.from_pretrained(model_name)
46
 
47
  ds = load_dataset("common_voice", "fr", split="test", cache_dir="./data/fr")
48
 
49
-
50
-
51
  chars_to_ignore_regex = '[\,\?\.\!\;\:\"\“\%\‘\”\�\‘\’\’\’\‘\…\·\!\ǃ\?\«\‹\»\›“\”\\ʿ\ʾ\„\∞\\|\.\,\;\:\*\—\–\─\―\_\/\:\ː\;\,\=\«\»\→]'
52
  def map_to_array(batch):
53
  speech, _ = torchaudio.load(batch["path"])
@@ -55,10 +53,10 @@ def map_to_array(batch):
55
  batch["sampling_rate"] = resampler.new_freq
56
  batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().replace("’", "'")
57
  return batch
 
58
 
59
  ds = ds.map(map_to_array)
60
 
61
- resampler = torchaudio.transforms.Resample(48_000, 16_000)
62
  def map_to_pred(batch):
63
  features = processor(batch["speech"], sampling_rate=batch["sampling_rate"][0], padding=True, return_tensors="pt")
64
  input_values = features.input_values.to(device)
 
39
 
40
  model_name = "Ilyes/wav2vec2-large-xlsr-53-french"
41
 
42
+ device = "cpu" # "cuda"
43
 
44
+ model = Wav2Vec2ForCTC.from_pretrained(model_name).to(device)
 
45
  processor = Wav2Vec2Processor.from_pretrained(model_name)
46
 
47
  ds = load_dataset("common_voice", "fr", split="test", cache_dir="./data/fr")
48
 
 
 
49
  chars_to_ignore_regex = '[\,\?\.\!\;\:\"\“\%\‘\”\�\‘\’\’\’\‘\…\·\!\ǃ\?\«\‹\»\›“\”\\ʿ\ʾ\„\∞\\|\.\,\;\:\*\—\–\─\―\_\/\:\ː\;\,\=\«\»\→]'
50
  def map_to_array(batch):
51
  speech, _ = torchaudio.load(batch["path"])
 
53
  batch["sampling_rate"] = resampler.new_freq
54
  batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().replace("’", "'")
55
  return batch
56
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
57
 
58
  ds = ds.map(map_to_array)
59
 
 
60
  def map_to_pred(batch):
61
  features = processor(batch["speech"], sampling_rate=batch["sampling_rate"][0], padding=True, return_tensors="pt")
62
  input_values = features.input_values.to(device)