vasilis commited on
Commit
409de45
·
1 Parent(s): bdadac1

updates model

Browse files
Files changed (3) hide show
  1. README.md +16 -25
  2. config.json +1 -1
  3. pytorch_model.bin +1 -1
README.md CHANGED
@@ -25,10 +25,10 @@ model-index:
25
  metrics:
26
  - name: Test WER
27
  type: wer
28
- value: 23.298429
29
  - name: Test CER
30
  type: cer
31
- value: 7.867248
32
  ---
33
 
34
  # Wav2Vec2-Large-XLSR-53-Swedish
@@ -85,11 +85,11 @@ from datasets import load_dataset, load_metric
85
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
86
  import re
87
 
88
- test_dataset = load_dataset("common_voice", "sv-SE", split="test") #TODO: replace {lang_id} in your language code here. Make sure the code is one of the *ISO codes* of [this](https://huggingface.co/languages) site.
89
  wer = load_metric("wer")
90
 
91
- processor = Wav2Vec2Processor.from_pretrained("vasilis/wav2vec2-large-xlsr-53-swedish") #TODO: replace {model_id} with your model id. The model id consists of {your_username}/{your_modelname}, *e.g.* `elgeish/wav2vec2-large-xlsr-53-arabic`
92
- model = Wav2Vec2ForCTC.from_pretrained("vasilis/wav2vec2-large-xlsr-53-swedish") #TODO: replace {model_id} with your model id. The model id consists of {your_username}/{your_modelname}, *e.g.* `elgeish/wav2vec2-large-xlsr-53-arabic`
93
  model.to("cuda")
94
 
95
  chars_to_ignore_regex = "[\,\?\.\!\-\;\:\"\“\%\‘\”\�\']" # TODO: adapt this list to include all special characters you removed from the data
@@ -100,36 +100,24 @@ resampler = {
100
  32000: torchaudio.transforms.Resample(32000, 16_000)
101
  }
102
 
103
-
104
  # Preprocessing the datasets.
105
  # We need to read the aduio files as arrays
106
  def speech_file_to_array_fn(batch):
107
  batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
 
 
108
  speech_array, sampling_rate = torchaudio.load(batch["path"])
109
  batch["speech"] = resampler[sampling_rate](speech_array).squeeze().numpy()
110
  return batch
111
 
112
-
113
- test_dataset = test_dataset.map(speech_file_to_array_fn)
114
-
115
- # Preprocessing the datasets.
116
- # We need to read the aduio files as arrays
117
- def speech_file_to_array_fn(batch):
118
- batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
119
- speech_array, sampling_rate = torchaudio.load(batch["path"])
120
- batch["speech"] = resampler(speech_array).squeeze().numpy()
121
- return batch
122
-
123
  test_dataset = test_dataset.map(speech_file_to_array_fn)
124
 
125
  # Preprocessing the datasets.
126
  # We need to read the aduio files as arrays
127
  def evaluate(batch):
128
  inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
129
-
130
  with torch.no_grad():
131
  logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
132
-
133
  pred_ids = torch.argmax(logits, dim=-1)
134
  batch["pred_strings"] = processor.batch_decode(pred_ids)
135
  return batch
@@ -141,16 +129,19 @@ print("CER: {:2f}".format(100 * wer.compute(predictions=[" ".join(list(entry)) f
141
 
142
  ```
143
 
144
- **Test Result**: 23.298429 %
145
 
146
 
147
  ## Training
148
 
149
-
150
- The Common Voice train dataset was used for training. From NST
151
- the training split (60%) as can be found [here](https://github.com/se-asr/nst/tree/master/splits/60-20-20-80096) was used. On top of this
152
- a big chunk of the dataset was filtered out based on this mask
153
 
154
  ```python
155
  mask = [(5 < len(x.split()) < 20) and np.average([len(entry) for entry in x.split()]) > 5 for x in dataset['transcript'].tolist()]
156
- ```
 
 
 
 
 
25
  metrics:
26
  - name: Test WER
27
  type: wer
28
+ value: 20.220256
29
  - name: Test CER
30
  type: cer
31
+ value: 6.924060
32
  ---
33
 
34
  # Wav2Vec2-Large-XLSR-53-Swedish
 
85
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
86
  import re
87
 
88
+ test_dataset = load_dataset("common_voice", "sv-SE", split="test")
89
  wer = load_metric("wer")
90
 
91
+ processor = Wav2Vec2Processor.from_pretrained("vasilis/wav2vec2-large-xlsr-53-swedish")
92
+ model = Wav2Vec2ForCTC.from_pretrained("vasilis/wav2vec2-large-xlsr-53-swedish")
93
  model.to("cuda")
94
 
95
  chars_to_ignore_regex = "[\,\?\.\!\-\;\:\"\“\%\‘\”\�\']" # TODO: adapt this list to include all special characters you removed from the data
 
100
  32000: torchaudio.transforms.Resample(32000, 16_000)
101
  }
102
 
 
103
  # Preprocessing the datasets.
104
  # We need to read the aduio files as arrays
105
  def speech_file_to_array_fn(batch):
106
  batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
107
+ for key, value in replacements.items():
108
+ batch["sentence"] = batch["sentence"].replace(key, value)
109
  speech_array, sampling_rate = torchaudio.load(batch["path"])
110
  batch["speech"] = resampler[sampling_rate](speech_array).squeeze().numpy()
111
  return batch
112
 
 
 
 
 
 
 
 
 
 
 
 
113
  test_dataset = test_dataset.map(speech_file_to_array_fn)
114
 
115
  # Preprocessing the datasets.
116
  # We need to read the aduio files as arrays
117
  def evaluate(batch):
118
  inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
 
119
  with torch.no_grad():
120
  logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
 
121
  pred_ids = torch.argmax(logits, dim=-1)
122
  batch["pred_strings"] = processor.batch_decode(pred_ids)
123
  return batch
 
129
 
130
  ```
131
 
132
+ **Test Result**: 20.220256 %
133
 
134
 
135
  ## Training
136
 
137
+ As first step used Common Voice train dataset and parts from NST
138
+ as can be found [here](https://github.com/se-asr/nst/tree/master).
139
+ Part of NST where removed using this mask
 
140
 
141
  ```python
142
  mask = [(5 < len(x.split()) < 20) and np.average([len(entry) for entry in x.split()]) > 5 for x in dataset['transcript'].tolist()]
143
+ ```
144
+
145
+ After training like this for 20000 steps the model was finetuned on the training and validation sets of Common Voice
146
+ only for 3500 steps more.
147
+
config.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "_name_or_path": "facebook/wav2vec2-large-xlsr-53",
3
  "activation_dropout": 0.07,
4
  "apply_spec_augment": true,
5
  "architectures": [
 
1
  {
2
+ "_name_or_path": "/speech-data-1/dev/hugging_face_finetuning_week/sw_demo/checkpoints/2020_24_3_v24/checkpoint-19600",
3
  "activation_dropout": 0.07,
4
  "apply_spec_augment": true,
5
  "architectures": [
pytorch_model.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d2b0a008e1c06230fd9aaf96e7c8f9e5edbbca5786d543bb6653dab60e268123
3
  size 1262065047
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b7be02b3d56d35d6bbdff2e511de5f2b3d44e66874958aca5617d0e594a3e20
3
  size 1262065047