sanchit-gandhi HF staff commited on
Commit
daff7b8
1 Parent(s): ba578f3

Training in progress, step 500

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitignore +1 -0
  2. .idea/.gitignore +8 -0
  3. .idea/inspectionProfiles/profiles_settings.xml +6 -0
  4. .idea/misc.xml +22 -0
  5. .idea/modules.xml +8 -0
  6. .idea/vcs.xml +6 -0
  7. .idea/wav2vec2-2-gpt2-grid-search.iml +12 -0
  8. config.json +265 -0
  9. create_model.py +58 -0
  10. merges.txt +0 -0
  11. preprocessor_config.json +9 -0
  12. pytorch_model.bin +3 -0
  13. run_grid_search.sh +49 -0
  14. run_librispeech.sh +36 -0
  15. run_speech_recognition_seq2seq.py +539 -0
  16. runs/Feb23_15-17-13_sanchit--v100/1645629478.673521/events.out.tfevents.1645629478.sanchit--v100.119082.1 +3 -0
  17. runs/Feb23_15-17-13_sanchit--v100/events.out.tfevents.1645629478.sanchit--v100.119082.0 +3 -0
  18. runs/Feb23_15-18-28_sanchit--v100/1645629548.7865512/events.out.tfevents.1645629548.sanchit--v100.119273.1 +3 -0
  19. runs/Feb23_15-18-28_sanchit--v100/events.out.tfevents.1645629548.sanchit--v100.119273.0 +3 -0
  20. runs/Feb23_15-20-29_sanchit--v100/1645629669.5136263/events.out.tfevents.1645629669.sanchit--v100.119533.1 +3 -0
  21. runs/Feb23_15-20-29_sanchit--v100/events.out.tfevents.1645629669.sanchit--v100.119533.0 +3 -0
  22. runs/Feb23_15-21-38_sanchit--v100/1645629738.8586485/events.out.tfevents.1645629738.sanchit--v100.119714.1 +3 -0
  23. runs/Feb23_15-21-38_sanchit--v100/events.out.tfevents.1645629738.sanchit--v100.119714.0 +3 -0
  24. runs/Feb23_15-22-45_sanchit--v100/1645629807.9885855/events.out.tfevents.1645629807.sanchit--v100.119898.1 +3 -0
  25. runs/Feb23_15-22-45_sanchit--v100/events.out.tfevents.1645629807.sanchit--v100.119898.0 +3 -0
  26. runs/Feb23_15-24-03_sanchit--v100/1645629883.5906208/events.out.tfevents.1645629883.sanchit--v100.120087.1 +3 -0
  27. runs/Feb23_15-24-03_sanchit--v100/events.out.tfevents.1645629883.sanchit--v100.120087.0 +3 -0
  28. runs/Feb23_15-28-39_sanchit--v100/1645630160.6231816/events.out.tfevents.1645630160.sanchit--v100.120564.1 +3 -0
  29. runs/Feb23_15-28-39_sanchit--v100/events.out.tfevents.1645630160.sanchit--v100.120564.0 +3 -0
  30. runs/Feb23_15-31-07_sanchit--v100/1645630308.0543547/events.out.tfevents.1645630308.sanchit--v100.120839.1 +3 -0
  31. runs/Feb23_15-31-07_sanchit--v100/events.out.tfevents.1645630308.sanchit--v100.120839.0 +3 -0
  32. runs/Feb23_15-32-51_sanchit--v100/1645630413.4061124/events.out.tfevents.1645630413.sanchit--v100.121092.1 +3 -0
  33. runs/Feb23_15-32-51_sanchit--v100/events.out.tfevents.1645630413.sanchit--v100.121092.0 +3 -0
  34. runs/Feb23_15-38-52_sanchit--v100/1645630773.5256608/events.out.tfevents.1645630773.sanchit--v100.121718.1 +3 -0
  35. runs/Feb23_15-38-52_sanchit--v100/events.out.tfevents.1645630773.sanchit--v100.121718.0 +3 -0
  36. runs/Feb23_15-46-20_sanchit--v100/1645631221.2384057/events.out.tfevents.1645631221.sanchit--v100.122633.1 +3 -0
  37. runs/Feb23_15-46-20_sanchit--v100/events.out.tfevents.1645631221.sanchit--v100.122633.0 +3 -0
  38. runs/Feb23_15-47-56_sanchit--v100/1645631316.8539507/events.out.tfevents.1645631316.sanchit--v100.122880.1 +3 -0
  39. runs/Feb23_15-47-56_sanchit--v100/events.out.tfevents.1645631316.sanchit--v100.122880.0 +3 -0
  40. runs/Feb23_15-49-04_sanchit--v100/1645631387.0714893/events.out.tfevents.1645631387.sanchit--v100.123095.1 +3 -0
  41. runs/Feb23_15-49-04_sanchit--v100/events.out.tfevents.1645631387.sanchit--v100.123095.0 +3 -0
  42. runs/Feb23_15-57-27_sanchit--v100/1645631887.9999144/events.out.tfevents.1645631888.sanchit--v100.124050.1 +3 -0
  43. runs/Feb23_15-57-27_sanchit--v100/events.out.tfevents.1645631887.sanchit--v100.124050.0 +3 -0
  44. runs/Feb23_16-07-05_sanchit--v100/1645632478.8360717/events.out.tfevents.1645632478.sanchit--v100.125003.1 +3 -0
  45. runs/Feb23_16-07-05_sanchit--v100/events.out.tfevents.1645632478.sanchit--v100.125003.0 +3 -0
  46. runs/Feb23_16-12-14_sanchit--v100/1645632776.264174/events.out.tfevents.1645632776.sanchit--v100.125542.1 +3 -0
  47. runs/Feb23_16-12-14_sanchit--v100/events.out.tfevents.1645632776.sanchit--v100.125542.0 +3 -0
  48. special_tokens_map.json +1 -0
  49. tokenizer.json +0 -0
  50. tokenizer_config.json +1 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ checkpoint-*/
.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
.idea/inspectionProfiles/profiles_settings.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
.idea/misc.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
4
+ <component name="UnattendedHostPersistenceState">
5
+ <option name="openedFilesInfos">
6
+ <list>
7
+ <OpenedFileInfo>
8
+ <option name="caretOffset" value="0" />
9
+ <option name="fileUrl" value="file://$PROJECT_DIR$/create_model.py" />
10
+ </OpenedFileInfo>
11
+ <OpenedFileInfo>
12
+ <option name="caretOffset" value="4372" />
13
+ <option name="fileUrl" value="file://$PROJECT_DIR$/run_speech_recognition_seq2seq.py" />
14
+ </OpenedFileInfo>
15
+ <OpenedFileInfo>
16
+ <option name="caretOffset" value="0" />
17
+ <option name="fileUrl" value="file://$PROJECT_DIR$/run_librispeech.sh" />
18
+ </OpenedFileInfo>
19
+ </list>
20
+ </option>
21
+ </component>
22
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/wav2vec2-2-gpt2-grid-search.iml" filepath="$PROJECT_DIR$/.idea/wav2vec2-2-gpt2-grid-search.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
.idea/wav2vec2-2-gpt2-grid-search.iml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ <component name="PyDocumentationSettings">
9
+ <option name="format" value="PLAIN" />
10
+ <option name="myDocStringFormat" value="Plain" />
11
+ </component>
12
+ </module>
config.json ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "./",
3
+ "architectures": [
4
+ "SpeechEncoderDecoderModel"
5
+ ],
6
+ "decoder": {
7
+ "_name_or_path": "gpt2-medium",
8
+ "activation_function": "gelu_new",
9
+ "add_cross_attention": true,
10
+ "architectures": [
11
+ "GPT2LMHeadModel"
12
+ ],
13
+ "attn_pdrop": 0.0,
14
+ "bad_words_ids": null,
15
+ "bos_token_id": 50256,
16
+ "chunk_size_feed_forward": 0,
17
+ "cross_attention_hidden_size": null,
18
+ "decoder_start_token_id": null,
19
+ "diversity_penalty": 0.0,
20
+ "do_sample": false,
21
+ "early_stopping": false,
22
+ "embd_pdrop": 0.0,
23
+ "encoder_no_repeat_ngram_size": 0,
24
+ "eos_token_id": 50256,
25
+ "finetuning_task": null,
26
+ "forced_bos_token_id": null,
27
+ "forced_eos_token_id": null,
28
+ "id2label": {
29
+ "0": "LABEL_0",
30
+ "1": "LABEL_1"
31
+ },
32
+ "initializer_range": 0.02,
33
+ "is_decoder": true,
34
+ "is_encoder_decoder": false,
35
+ "label2id": {
36
+ "LABEL_0": 0,
37
+ "LABEL_1": 1
38
+ },
39
+ "layer_norm_epsilon": 1e-05,
40
+ "length_penalty": 1.0,
41
+ "max_length": 20,
42
+ "min_length": 0,
43
+ "model_type": "gpt2",
44
+ "n_ctx": 1024,
45
+ "n_embd": 1024,
46
+ "n_head": 16,
47
+ "n_inner": null,
48
+ "n_layer": 24,
49
+ "n_positions": 1024,
50
+ "n_special": 0,
51
+ "no_repeat_ngram_size": 0,
52
+ "num_beam_groups": 1,
53
+ "num_beams": 1,
54
+ "num_return_sequences": 1,
55
+ "output_attentions": false,
56
+ "output_hidden_states": false,
57
+ "output_scores": false,
58
+ "pad_token_id": null,
59
+ "predict_special_tokens": true,
60
+ "prefix": null,
61
+ "problem_type": null,
62
+ "pruned_heads": {},
63
+ "remove_invalid_values": false,
64
+ "reorder_and_upcast_attn": false,
65
+ "repetition_penalty": 1.0,
66
+ "resid_pdrop": 0.0,
67
+ "return_dict": true,
68
+ "return_dict_in_generate": false,
69
+ "scale_attn_by_inverse_layer_idx": false,
70
+ "scale_attn_weights": true,
71
+ "sep_token_id": null,
72
+ "summary_activation": null,
73
+ "summary_first_dropout": 0.0,
74
+ "summary_proj_to_labels": true,
75
+ "summary_type": "cls_index",
76
+ "summary_use_proj": true,
77
+ "task_specific_params": {
78
+ "text-generation": {
79
+ "do_sample": true,
80
+ "max_length": 50
81
+ }
82
+ },
83
+ "temperature": 1.0,
84
+ "tie_encoder_decoder": false,
85
+ "tie_word_embeddings": true,
86
+ "tokenizer_class": null,
87
+ "top_k": 50,
88
+ "top_p": 1.0,
89
+ "torch_dtype": null,
90
+ "torchscript": false,
91
+ "transformers_version": "4.17.0.dev0",
92
+ "use_bfloat16": false,
93
+ "use_cache": false,
94
+ "vocab_size": 50257
95
+ },
96
+ "decoder_start_token_id": 50256,
97
+ "encoder": {
98
+ "_name_or_path": "facebook/wav2vec2-large-lv60",
99
+ "activation_dropout": 0.0,
100
+ "adapter_kernel_size": 3,
101
+ "adapter_stride": 2,
102
+ "add_adapter": true,
103
+ "add_cross_attention": false,
104
+ "apply_spec_augment": false,
105
+ "architectures": [
106
+ "Wav2Vec2ForPreTraining"
107
+ ],
108
+ "attention_dropout": 0.0,
109
+ "bad_words_ids": null,
110
+ "bos_token_id": 1,
111
+ "chunk_size_feed_forward": 0,
112
+ "classifier_proj_size": 256,
113
+ "codevector_dim": 768,
114
+ "contrastive_logits_temperature": 0.1,
115
+ "conv_bias": true,
116
+ "conv_dim": [
117
+ 512,
118
+ 512,
119
+ 512,
120
+ 512,
121
+ 512,
122
+ 512,
123
+ 512
124
+ ],
125
+ "conv_kernel": [
126
+ 10,
127
+ 3,
128
+ 3,
129
+ 3,
130
+ 3,
131
+ 2,
132
+ 2
133
+ ],
134
+ "conv_stride": [
135
+ 5,
136
+ 2,
137
+ 2,
138
+ 2,
139
+ 2,
140
+ 2,
141
+ 2
142
+ ],
143
+ "cross_attention_hidden_size": null,
144
+ "ctc_loss_reduction": "sum",
145
+ "ctc_zero_infinity": false,
146
+ "decoder_start_token_id": null,
147
+ "diversity_loss_weight": 0.1,
148
+ "diversity_penalty": 0.0,
149
+ "do_sample": false,
150
+ "do_stable_layer_norm": true,
151
+ "early_stopping": false,
152
+ "encoder_no_repeat_ngram_size": 0,
153
+ "eos_token_id": 2,
154
+ "feat_extract_activation": "gelu",
155
+ "feat_extract_dropout": 0.0,
156
+ "feat_extract_norm": "layer",
157
+ "feat_proj_dropout": 0.0,
158
+ "feat_quantizer_dropout": 0.0,
159
+ "final_dropout": 0.0,
160
+ "finetuning_task": null,
161
+ "forced_bos_token_id": null,
162
+ "forced_eos_token_id": null,
163
+ "gradient_checkpointing": false,
164
+ "hidden_act": "gelu",
165
+ "hidden_dropout": 0.0,
166
+ "hidden_dropout_prob": 0.0,
167
+ "hidden_size": 1024,
168
+ "id2label": {
169
+ "0": "LABEL_0",
170
+ "1": "LABEL_1"
171
+ },
172
+ "initializer_range": 0.02,
173
+ "intermediate_size": 4096,
174
+ "is_decoder": false,
175
+ "is_encoder_decoder": false,
176
+ "label2id": {
177
+ "LABEL_0": 0,
178
+ "LABEL_1": 1
179
+ },
180
+ "layer_norm_eps": 1e-05,
181
+ "layerdrop": 0.0,
182
+ "length_penalty": 1.0,
183
+ "mask_feature_length": 10,
184
+ "mask_feature_min_masks": 0,
185
+ "mask_feature_prob": 0.0,
186
+ "mask_time_length": 10,
187
+ "mask_time_min_masks": 2,
188
+ "mask_time_prob": 0.0,
189
+ "max_length": 20,
190
+ "min_length": 0,
191
+ "model_type": "wav2vec2",
192
+ "no_repeat_ngram_size": 0,
193
+ "num_adapter_layers": 3,
194
+ "num_attention_heads": 16,
195
+ "num_beam_groups": 1,
196
+ "num_beams": 1,
197
+ "num_codevector_groups": 2,
198
+ "num_codevectors_per_group": 320,
199
+ "num_conv_pos_embedding_groups": 16,
200
+ "num_conv_pos_embeddings": 128,
201
+ "num_feat_extract_layers": 7,
202
+ "num_hidden_layers": 24,
203
+ "num_negatives": 100,
204
+ "num_return_sequences": 1,
205
+ "output_attentions": false,
206
+ "output_hidden_size": 1024,
207
+ "output_hidden_states": false,
208
+ "output_scores": false,
209
+ "pad_token_id": 0,
210
+ "prefix": null,
211
+ "problem_type": null,
212
+ "proj_codevector_dim": 768,
213
+ "pruned_heads": {},
214
+ "remove_invalid_values": false,
215
+ "repetition_penalty": 1.0,
216
+ "return_dict": true,
217
+ "return_dict_in_generate": false,
218
+ "sep_token_id": null,
219
+ "task_specific_params": null,
220
+ "tdnn_dilation": [
221
+ 1,
222
+ 2,
223
+ 3,
224
+ 1,
225
+ 1
226
+ ],
227
+ "tdnn_dim": [
228
+ 512,
229
+ 512,
230
+ 512,
231
+ 512,
232
+ 1500
233
+ ],
234
+ "tdnn_kernel": [
235
+ 5,
236
+ 3,
237
+ 3,
238
+ 1,
239
+ 1
240
+ ],
241
+ "temperature": 1.0,
242
+ "tie_encoder_decoder": false,
243
+ "tie_word_embeddings": true,
244
+ "tokenizer_class": null,
245
+ "top_k": 50,
246
+ "top_p": 1.0,
247
+ "torch_dtype": null,
248
+ "torchscript": false,
249
+ "transformers_version": "4.17.0.dev0",
250
+ "use_bfloat16": false,
251
+ "use_weighted_layer_sum": false,
252
+ "vocab_size": 32,
253
+ "xvector_output_dim": 512
254
+ },
255
+ "eos_token_id": 50256,
256
+ "is_encoder_decoder": true,
257
+ "max_length": 50,
258
+ "model_type": "speech-encoder-decoder",
259
+ "pad_token_id": 50256,
260
+ "processor_class": "Wav2Vec2Processor",
261
+ "tie_word_embeddings": false,
262
+ "torch_dtype": "float32",
263
+ "transformers_version": null,
264
+ "use_cache": false
265
+ }
create_model.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import SpeechEncoderDecoderModel, AutoFeatureExtractor, GPT2Tokenizer
2
+ import torch
3
+
4
+ # checkpoints to leverage
5
+ encoder_id = "facebook/wav2vec2-large-lv60"
6
+ decoder_id = "gpt2-medium"
7
+
8
+ model = SpeechEncoderDecoderModel.from_encoder_decoder_pretrained(encoder_id, decoder_id, encoder_add_adapter=True)
9
+
10
+ # set all encoder regularisation to zero
11
+ model.config.encoder.feat_proj_dropout = 0.0
12
+ model.config.encoder.final_dropout = 0.0
13
+ model.config.encoder.activation_dropout = 0.0
14
+ model.config.encoder.apply_spec_augment = False
15
+ model.config.encoder.attention_dropout = 0.0
16
+ model.config.encoder.feat_extract_dropout = 0.0
17
+ model.config.encoder.feat_proj_dropout = 0.0
18
+ model.config.encoder.hidden_dropout = 0.0
19
+ model.config.encoder.hidden_dropout_prob = 0.0
20
+ model.config.encoder.layerdrop = 0.0
21
+ model.config.encoder.mask_feature_prob = 0.0
22
+ model.config.encoder.mask_time_prob = 0.0
23
+
24
+ # set all decoder regularisation to zero
25
+ model.config.decoder.attn_pdrop = 0.0
26
+ model.config.decoder.embd_pdrop = 0.0
27
+ model.config.decoder.resid_pdrop = 0.0
28
+ model.config.decoder.summary_first_dropout = 0.0
29
+
30
+ # force GPT2 to append EOS to begin and end of seq
31
+ def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
32
+ outputs = [self.bos_token_id] + token_ids_0 + [self.eos_token_id]
33
+ return outputs
34
+
35
+ GPT2Tokenizer.build_inputs_with_special_tokens = build_inputs_with_special_tokens
36
+ gpt2_tokenizer = GPT2Tokenizer.from_pretrained(decoder_id)
37
+ # set pad_token_id to unk_token_id, note: unk_token_id == eos_token_id == bos_token_id
38
+ gpt2_tokenizer.pad_token = gpt2_tokenizer.unk_token
39
+ gpt2_tokenizer.save_pretrained("./")
40
+
41
+ model.config.pad_token_id = gpt2_tokenizer.pad_token_id
42
+ model.config.decoder_start_token_id = model.decoder.config.bos_token_id
43
+ model.config.eos_token_id = model.decoder.config.eos_token_id
44
+ model.config.max_length = 50
45
+ model.config.num_beams = 1
46
+
47
+ model.config.use_cache = False
48
+ model.config.decoder.use_cache = False
49
+ model.config.processor_class = "Wav2Vec2Processor"
50
+
51
+ # check if generation works
52
+ out = model.generate(torch.ones((1, 2000)))
53
+
54
+ model.save_pretrained("./")
55
+
56
+ feature_extractor = AutoFeatureExtractor.from_pretrained(encoder_id)
57
+ feature_extractor.save_pretrained("./")
58
+
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
preprocessor_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "feature_extractor_type": "Wav2Vec2FeatureExtractor",
4
+ "feature_size": 1,
5
+ "padding_side": "right",
6
+ "padding_value": 0.0,
7
+ "return_attention_mask": true,
8
+ "sampling_rate": 16000
9
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e8581f7b9887fe3365fc16e55f698a8dbcb5f66934301a1001994acaeec98b3
3
+ size 3210531882
run_grid_search.sh ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ declare -a learning_rates=("1e-5" "3e-5" "1e-4" "3e-4" "1e-3")
4
+ declare -a batch_sizes=("8" "12" "14" "16")
5
+ declare -a gradient_accumulation_step_sizes=("2" "4" "8")
6
+
7
+ for learning_rate in "${learning_rates[@]}"; do
8
+ for batch_size in "${batch_sizes[@]}"; do
9
+ for gradient_accumulation_steps in "${gradient_accumulation_step_sizes[@]}"; do
10
+ python create_model.py
11
+ CUDA_VISIBLE_DEVICES=0 python run_speech_recognition_seq2seq.py \
12
+ --dataset_name="librispeech_asr" \
13
+ --model_name_or_path="./" \
14
+ --tokenizer_name="./" \
15
+ --dataset_config_name="clean" \
16
+ --train_split_name="train.100" \
17
+ --eval_split_name="validation" \
18
+ --output_dir="./" \
19
+ --preprocessing_num_workers="1" \
20
+ --length_column_name="input_length" \
21
+ --overwrite_output_dir \
22
+ --num_train_epochs="1" \
23
+ --per_device_train_batch_size=$batch_size \
24
+ --per_device_eval_batch_size=$batch_size \
25
+ --gradient_accumulation_steps=$gradient_accumulation_steps \
26
+ --generation_max_length="40" \
27
+ --generation_num_beams="1" \
28
+ --learning_rate=$learning_rate \
29
+ --warmup_steps="500" \
30
+ --evaluation_strategy="steps" \
31
+ --text_column_name="text" \
32
+ --save_steps="500" \
33
+ --eval_steps="500" \
34
+ --logging_steps="1" \
35
+ --save_total_limit="1" \
36
+ --freeze_feature_encoder \
37
+ --gradient_checkpointing \
38
+ --fp16 \
39
+ --group_by_length \
40
+ --predict_with_generate \
41
+ --do_lower_case \
42
+ --do_train \
43
+ --do_eval \
44
+ --push_to_hub \
45
+ --use_auth_token
46
+ done
47
+ done
48
+ done
49
+
run_librispeech.sh ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ CUDA_VISIBLE_DEVICES=1 python run_speech_recognition_seq2seq.py \
3
+ --dataset_name="librispeech_asr" \
4
+ --model_name_or_path="./" \
5
+ --tokenizer_name="./" \
6
+ --dataset_config_name="clean" \
7
+ --train_split_name="train.100" \
8
+ --eval_split_name="validation" \
9
+ --output_dir="./" \
10
+ --preprocessing_num_workers="1" \
11
+ --length_column_name="input_length" \
12
+ --overwrite_output_dir \
13
+ --num_train_epochs="3" \
14
+ --per_device_train_batch_size="14" \
15
+ --per_device_eval_batch_size="14" \
16
+ --gradient_accumulation_steps="8" \
17
+ --generation_max_length="40" \
18
+ --generation_num_beams="1" \
19
+ --learning_rate="1e-3" \
20
+ --warmup_steps="500" \
21
+ --evaluation_strategy="steps" \
22
+ --text_column_name="text" \
23
+ --save_steps="500" \
24
+ --eval_steps="500" \
25
+ --logging_steps="1" \
26
+ --save_total_limit="1" \
27
+ --freeze_feature_encoder \
28
+ --gradient_checkpointing \
29
+ --fp16 \
30
+ --group_by_length \
31
+ --predict_with_generate \
32
+ --do_lower_case \
33
+ --do_eval --do_train \
34
+ --push_to_hub \
35
+ --use_auth_token
36
+
run_speech_recognition_seq2seq.py ADDED
@@ -0,0 +1,539 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding=utf-8
3
+ # Copyright 2021 The HuggingFace Team. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ """
17
+ Fine-tuning the library models for sequence to sequence speech recognition.
18
+ """
19
+ # You can also adapt this script on your own sequence to sequence speech
20
+ # recognition task. Pointers for this are left as comments.
21
+
22
+ import logging
23
+ import os
24
+ import sys
25
+ from dataclasses import dataclass, field
26
+ from typing import Any, Dict, List, Optional, Union
27
+
28
+ import datasets
29
+ import torch
30
+ from datasets import DatasetDict, load_dataset, load_metric
31
+
32
+ import bitsandbytes as bnb
33
+ import transformers
34
+ from transformers import (
35
+ AutoConfig,
36
+ AutoFeatureExtractor,
37
+ AutoModelForSpeechSeq2Seq,
38
+ AutoProcessor,
39
+ AutoTokenizer,
40
+ HfArgumentParser,
41
+ Seq2SeqTrainer,
42
+ Seq2SeqTrainingArguments,
43
+ set_seed,
44
+ )
45
+ from transformers.trainer_pt_utils import get_parameter_names
46
+ from transformers.trainer_utils import get_last_checkpoint, is_main_process
47
+ from transformers.utils import check_min_version
48
+ from transformers.utils.versions import require_version
49
+ from transformers.optimization import Adafactor
50
+
51
+
52
+ # Will error if the minimal version of Transformers is not installed. Remove at your own risks.
53
+ check_min_version("4.17.0.dev0")
54
+
55
+ require_version("datasets>=1.8.0", "To fix: pip install -r examples/pytorch/summarization/requirements.txt")
56
+
57
+ logger = logging.getLogger(__name__)
58
+
59
+
60
+ @dataclass
61
+ class ModelArguments:
62
+ """
63
+ Arguments pertaining to which model/config/tokenizer we are going to fine-tune from.
64
+ """
65
+
66
+ model_name_or_path: str = field(
67
+ metadata={"help": "Path to pretrained model or model identifier from huggingface.co/models"}
68
+ )
69
+ config_name: Optional[str] = field(
70
+ default=None, metadata={"help": "Pretrained config name or path if not the same as model_name"}
71
+ )
72
+ tokenizer_name: Optional[str] = field(
73
+ default=None, metadata={"help": "Pretrained tokenizer name or path if not the same as model_name"}
74
+ )
75
+ feature_extractor_name: Optional[str] = field(
76
+ default=None, metadata={"help": "feature extractor name or path if not the same as model_name"}
77
+ )
78
+ cache_dir: Optional[str] = field(
79
+ default=None,
80
+ metadata={"help": "Where to store the pretrained models downloaded from huggingface.co"},
81
+ )
82
+ use_fast_tokenizer: bool = field(
83
+ default=True,
84
+ metadata={"help": "Whether to use one of the fast tokenizer (backed by the tokenizers library) or not."},
85
+ )
86
+ model_revision: str = field(
87
+ default="main",
88
+ metadata={"help": "The specific model version to use (can be a branch name, tag name or commit id)."},
89
+ )
90
+ use_auth_token: bool = field(
91
+ default=False,
92
+ metadata={
93
+ "help": "Will use the token generated when running `transformers-cli login` (necessary to use this script "
94
+ "with private models)."
95
+ },
96
+ )
97
+ freeze_feature_encoder: bool = field(
98
+ default=True, metadata={"help": "Whether to freeze the feature encoder layers of the model."}
99
+ )
100
+
101
+
102
+ @dataclass
103
+ class DataTrainingArguments:
104
+ """
105
+ Arguments pertaining to what data we are going to input our model for training and eval.
106
+ """
107
+
108
+ dataset_name: str = field(
109
+ default=None, metadata={"help": "The name of the dataset to use (via the datasets library)."}
110
+ )
111
+ dataset_config_name: Optional[str] = field(
112
+ default=None, metadata={"help": "The configuration name of the dataset to use (via the datasets library)."}
113
+ )
114
+ text_column: Optional[str] = field(
115
+ default=None,
116
+ metadata={"help": "The name of the column in the datasets containing the full texts (for summarization)."},
117
+ )
118
+ overwrite_cache: bool = field(
119
+ default=False, metadata={"help": "Overwrite the cached training and evaluation sets"}
120
+ )
121
+ preprocessing_num_workers: Optional[int] = field(
122
+ default=None,
123
+ metadata={"help": "The number of processes to use for the preprocessing."},
124
+ )
125
+ max_train_samples: Optional[int] = field(
126
+ default=None,
127
+ metadata={
128
+ "help": "For debugging purposes or quicker training, truncate the number of training examples to this "
129
+ "value if set."
130
+ },
131
+ )
132
+ max_eval_samples: Optional[int] = field(
133
+ default=None,
134
+ metadata={
135
+ "help": "For debugging purposes or quicker training, truncate the number of evaluation examples to this "
136
+ "value if set."
137
+ },
138
+ )
139
+ audio_column_name: str = field(
140
+ default="audio",
141
+ metadata={"help": "The name of the dataset column containing the audio data. Defaults to 'audio'"},
142
+ )
143
+ text_column_name: str = field(
144
+ default="text",
145
+ metadata={"help": "The name of the dataset column containing the text data. Defaults to 'text'"},
146
+ )
147
+ max_duration_in_seconds: float = field(
148
+ default=20.0,
149
+ metadata={
150
+ "help": "Truncate audio files that are longer than `max_duration_in_seconds` seconds to 'max_duration_in_seconds`"
151
+ },
152
+ )
153
+ min_duration_in_seconds: float = field(
154
+ default=0.0, metadata={"help": "Filter audio files that are shorter than `min_duration_in_seconds` seconds"}
155
+ )
156
+ preprocessing_only: bool = field(
157
+ default=False,
158
+ metadata={
159
+ "help": "Whether to only do data preprocessing and skip training. "
160
+ "This is especially useful when data preprocessing errors out in distributed training due to timeout. "
161
+ "In this case, one should run the preprocessing in a non-distributed setup with `preprocessing_only=True` "
162
+ "so that the cached datasets can consequently be loaded in distributed training"
163
+ },
164
+ )
165
+ train_split_name: str = field(
166
+ default="train",
167
+ metadata={
168
+ "help": "The name of the training data set split to use (via the datasets library). Defaults to 'train'"
169
+ },
170
+ )
171
+ eval_split_name: str = field(
172
+ default="test",
173
+ metadata={
174
+ "help": "The name of the training data set split to use (via the datasets library). Defaults to 'train'"
175
+ },
176
+ )
177
+ do_lower_case: bool = field(
178
+ default=True,
179
+ metadata={"help": "Whether the target text should be lower cased."},
180
+ )
181
+
182
+
183
+ @dataclass
184
+ class DataCollatorSpeechSeq2SeqWithPadding:
185
+ """
186
+ Data collator that will dynamically pad the inputs received.
187
+ Args:
188
+ processor ([`Wav2Vec2Processor`])
189
+ The processor used for proccessing the data.
190
+ decoder_start_token_id (`int`)
191
+ The begin-of-sentence of the decoder.
192
+ """
193
+
194
+ processor: Any
195
+ decoder_start_token_id: int
196
+
197
+ def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:
198
+ # split inputs and labels since they have to be of different lenghts and need
199
+ # different padding methods
200
+ input_features = [{"input_values": feature["input_values"]} for feature in features]
201
+ label_features = [{"input_ids": feature["labels"]} for feature in features]
202
+
203
+ batch = self.processor.feature_extractor.pad(input_features, return_tensors="pt")
204
+
205
+ labels_batch = self.processor.tokenizer.pad(label_features, return_tensors="pt")
206
+
207
+ # replace padding with -100 to ignore loss correctly
208
+ labels = labels_batch["input_ids"].masked_fill(labels_batch.attention_mask.ne(1), -100)
209
+
210
+ # if bos token is appended in previous tokenization step,
211
+ # cut bos token here as it's append later anyways
212
+ if (labels[:, 0] == self.decoder_start_token_id).all().cpu().item():
213
+ labels = labels[:, 1:]
214
+
215
+ batch["labels"] = labels
216
+
217
+ return batch
218
+
219
+
220
+ def main():
221
+ # 1. Parse input arguments
222
+ # See all possible arguments in src/transformers/training_args.py
223
+ # or by passing the --help flag to this script.
224
+ # We now keep distinct sets of args, for a cleaner separation of concerns.
225
+ parser = HfArgumentParser((ModelArguments, DataTrainingArguments, Seq2SeqTrainingArguments))
226
+
227
+ if len(sys.argv) == 2 and sys.argv[1].endswith(".json"):
228
+ # If we pass only one argument to the script and it's the path to a json file,
229
+ # let's parse it to get our arguments.
230
+ model_args, data_args, training_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1]))
231
+ else:
232
+ model_args, data_args, training_args = parser.parse_args_into_dataclasses()
233
+
234
+ # 2. Setup logging
235
+ logging.basicConfig(
236
+ format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
237
+ datefmt="%m/%d/%Y %H:%M:%S",
238
+ handlers=[logging.StreamHandler(sys.stdout)],
239
+ )
240
+ log_level = training_args.get_process_log_level()
241
+ logger.setLevel(log_level)
242
+ datasets.utils.logging.set_verbosity(log_level)
243
+ transformers.utils.logging.set_verbosity(log_level)
244
+ transformers.utils.logging.enable_default_handler()
245
+ transformers.utils.logging.enable_explicit_format()
246
+
247
+ logger.setLevel(logging.INFO if is_main_process(training_args.local_rank) else logging.WARN)
248
+
249
+ # Log on each process the small summary:
250
+ logger.warning(
251
+ f"Process rank: {training_args.local_rank}, device: {training_args.device}, n_gpu: {training_args.n_gpu}"
252
+ f"distributed training: {bool(training_args.local_rank != -1)}, 16-bits training: {training_args.fp16}"
253
+ )
254
+ logger.info(f"Training/evaluation parameters {training_args}")
255
+
256
+ # Set the verbosity to info of the Transformers logger (on main process only):
257
+ if is_main_process(training_args.local_rank):
258
+ transformers.utils.logging.set_verbosity_info()
259
+ logger.info("Training/evaluation parameters %s", training_args)
260
+
261
+ # 3. Detecting last checkpoint and eventualy continue from last checkpoint
262
+ last_checkpoint = None
263
+ if os.path.isdir(training_args.output_dir) and training_args.do_train and not training_args.overwrite_output_dir:
264
+ last_checkpoint = get_last_checkpoint(training_args.output_dir)
265
+ if last_checkpoint is None and len(os.listdir(training_args.output_dir)) > 0:
266
+ raise ValueError(
267
+ f"Output directory ({training_args.output_dir}) already exists and is not empty. "
268
+ "Use --overwrite_output_dir to overcome."
269
+ )
270
+ elif last_checkpoint is not None and training_args.resume_from_checkpoint is None:
271
+ logger.info(
272
+ f"Checkpoint detected, resuming training at {last_checkpoint}. To avoid this behavior, change "
273
+ "the `--output_dir` or add `--overwrite_output_dir` to train from scratch."
274
+ )
275
+
276
+ # Set seed before initializing model.
277
+ set_seed(training_args.seed)
278
+
279
+ # 4. Load dataset
280
+ raw_datasets = DatasetDict()
281
+
282
+ if training_args.do_train:
283
+ raw_datasets["train"] = load_dataset(
284
+ data_args.dataset_name, data_args.dataset_config_name, split=data_args.train_split_name
285
+ )
286
+
287
+ if training_args.do_eval:
288
+ raw_datasets["eval"] = load_dataset(
289
+ data_args.dataset_name, data_args.dataset_config_name, split=data_args.eval_split_name
290
+ )
291
+
292
+ if data_args.audio_column_name not in next(iter(raw_datasets.values())).column_names:
293
+ raise ValueError(
294
+ f"--audio_column_name '{data_args.audio_column_name}' not found in dataset '{data_args.dataset_name}'. "
295
+ "Make sure to set `--audio_column_name` to the correct audio column - one of "
296
+ f"{', '.join(next(iter(raw_datasets.values())).column_names)}."
297
+ )
298
+
299
+ if data_args.text_column_name not in next(iter(raw_datasets.values())).column_names:
300
+ raise ValueError(
301
+ f"--text_column_name {data_args.text_column_name} not found in dataset '{data_args.dataset_name}'. "
302
+ "Make sure to set `--text_column_name` to the correct text column - one of "
303
+ f"{', '.join(next(iter(raw_datasets.values())).column_names)}."
304
+ )
305
+
306
+ # 5. Load pretrained model, tokenizer, and feature extractor
307
+ #
308
+ # Distributed training:
309
+ # The .from_pretrained methods guarantee that only one local process can concurrently
310
+ config = AutoConfig.from_pretrained(
311
+ model_args.config_name if model_args.config_name else model_args.model_name_or_path,
312
+ cache_dir=model_args.cache_dir,
313
+ revision=model_args.model_revision,
314
+ use_auth_token=True if model_args.use_auth_token else None,
315
+ )
316
+
317
+ feature_extractor = AutoFeatureExtractor.from_pretrained(
318
+ model_args.feature_extractor_name if model_args.feature_extractor_name else model_args.model_name_or_path,
319
+ cache_dir=model_args.cache_dir,
320
+ revision=model_args.model_revision,
321
+ use_auth_token=True if model_args.use_auth_token else None,
322
+ )
323
+ tokenizer = AutoTokenizer.from_pretrained(
324
+ model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
325
+ cache_dir=model_args.cache_dir,
326
+ use_fast=model_args.use_fast_tokenizer,
327
+ revision=model_args.model_revision,
328
+ use_auth_token=True if model_args.use_auth_token else None,
329
+ )
330
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
331
+ model_args.model_name_or_path,
332
+ config=config,
333
+ cache_dir=model_args.cache_dir,
334
+ revision=model_args.model_revision,
335
+ use_auth_token=True if model_args.use_auth_token else None,
336
+ )
337
+
338
+ if model.config.decoder_start_token_id is None:
339
+ raise ValueError("Make sure that `config.decoder_start_token_id` is correctly defined")
340
+
341
+ if model_args.freeze_feature_encoder:
342
+ model.freeze_feature_encoder()
343
+
344
+ # 6. Resample speech dataset if necassary
345
+ dataset_sampling_rate = next(iter(raw_datasets.values())).features[data_args.audio_column_name].sampling_rate
346
+ if dataset_sampling_rate != feature_extractor.sampling_rate:
347
+ raw_datasets = raw_datasets.cast_column(
348
+ data_args.audio_column_name, datasets.features.Audio(sampling_rate=feature_extractor.sampling_rate)
349
+ )
350
+
351
+ # 7. Preprocessing the datasets.
352
+ # We need to read the audio files as arrays and tokenize the targets.
353
+ max_input_length = data_args.max_duration_in_seconds * feature_extractor.sampling_rate
354
+ min_input_length = data_args.min_duration_in_seconds * feature_extractor.sampling_rate
355
+ audio_column_name = data_args.audio_column_name
356
+ num_workers = data_args.preprocessing_num_workers
357
+ text_column_name = data_args.text_column_name
358
+ model_input_name = feature_extractor.model_input_names[0]
359
+ do_lower_case = data_args.do_lower_case
360
+
361
+ if data_args.max_train_samples is not None:
362
+ raw_datasets["train"] = raw_datasets["train"].select(range(data_args.max_train_samples))
363
+
364
+ if data_args.max_eval_samples is not None:
365
+ raw_datasets["eval"] = raw_datasets["eval"].select(range(data_args.max_eval_samples))
366
+
367
+ def prepare_dataset(batch):
368
+ # process audio
369
+ sample = batch[audio_column_name]
370
+ inputs = feature_extractor(sample["array"], sampling_rate=sample["sampling_rate"])
371
+ # process audio length
372
+ batch[model_input_name] = inputs.input_values[0]
373
+ batch["input_length"] = len(batch["input_values"])
374
+
375
+ # process targets
376
+ input_str = batch[text_column_name].lower() if do_lower_case else batch[text_column_name]
377
+ batch["labels"] = tokenizer(input_str).input_ids
378
+ return batch
379
+
380
+ with training_args.main_process_first(desc="dataset map pre-processing"):
381
+ vectorized_datasets = raw_datasets.map(
382
+ prepare_dataset,
383
+ remove_columns=next(iter(raw_datasets.values())).column_names,
384
+ num_proc=data_args.preprocessing_num_workers,
385
+ desc="preprocess train dataset",
386
+ )
387
+
388
+ # filter data that is shorter than min_input_length or longer than
389
+ # max_input_length
390
+ def is_audio_in_length_range(length):
391
+ return length > min_input_length and length < max_input_length
392
+
393
+ vectorized_datasets = vectorized_datasets.filter(
394
+ is_audio_in_length_range,
395
+ num_proc=num_workers,
396
+ input_columns=["input_length"],
397
+ )
398
+
399
+ # for large datasets it is advised to run the preprocessing on a
400
+ # single machine first with `args.preprocessing_only` since there will mostly likely
401
+ # be a timeout when running the script in distributed mode.
402
+ # In a second step `args.preprocessing_only` can then be set to `False` to load the
403
+ # cached dataset
404
+ if data_args.preprocessing_only:
405
+ cache = {k: v.cache_files for k, v in vectorized_datasets.items()}
406
+ logger.info(f"Data preprocessing finished. Files cached at {cache}.")
407
+ return
408
+
409
+ # 8. Load Metric
410
+ metric = load_metric("wer")
411
+
412
+ def compute_metrics(pred):
413
+ pred_ids = pred.predictions
414
+
415
+ pred.label_ids[pred.label_ids == -100] = tokenizer.pad_token_id
416
+
417
+ pred_str = tokenizer.batch_decode(pred_ids, skip_special_tokens=True)
418
+ # we do not want to group tokens when computing the metrics
419
+ label_str = tokenizer.batch_decode(pred.label_ids, skip_special_tokens=True)
420
+
421
+ wer = metric.compute(predictions=pred_str, references=label_str)
422
+
423
+ return {"wer": wer}
424
+
425
+ # 9. Create a single speech processor
426
+ if is_main_process(training_args.local_rank):
427
+ # save feature extractor, tokenizer and config
428
+ feature_extractor.save_pretrained(training_args.output_dir)
429
+ tokenizer.save_pretrained(training_args.output_dir)
430
+ config.save_pretrained(training_args.output_dir)
431
+
432
+ processor = AutoProcessor.from_pretrained(training_args.output_dir)
433
+
434
+ # 10. Define data collator
435
+ data_collator = DataCollatorSpeechSeq2SeqWithPadding(
436
+ processor=processor, decoder_start_token_id=model.config.decoder_start_token_id
437
+ )
438
+
439
+ decay_parameters = get_parameter_names(model, [torch.nn.LayerNorm])
440
+ decay_parameters = [name for name in decay_parameters if "bias" not in name]
441
+ optimizer_grouped_parameters = [
442
+ {
443
+ "params": [p for n, p in model.named_parameters() if n in decay_parameters],
444
+ "weight_decay": training_args.weight_decay,
445
+ },
446
+ {
447
+ "params": [p for n, p in model.named_parameters() if n not in decay_parameters],
448
+ "weight_decay": 0.0,
449
+ },
450
+ ]
451
+
452
+ optimizer = bnb.optim.Adam8bit(
453
+ params=optimizer_grouped_parameters,
454
+ lr=training_args.learning_rate,
455
+ betas=(training_args.adam_beta1, training_args.adam_beta2),
456
+ eps=training_args.adam_epsilon,
457
+ )
458
+
459
+ """optimizer = Adafactor(
460
+ params=optimizer_grouped_parameters,
461
+ lr=training_args.learning_rate,
462
+ beta1=training_args.adam_beta1,
463
+ eps=training_args.adam_epsilon,
464
+ relative_step=False,
465
+ )"""
466
+
467
+
468
+ optimizers = (optimizer, None)
469
+
470
+
471
+ #11. Initialize Trainer
472
+
473
+ trainer = Seq2SeqTrainer(
474
+ model=model,
475
+ args=training_args,
476
+ train_dataset=vectorized_datasets["train"] if training_args.do_train else None,
477
+ eval_dataset=vectorized_datasets["eval"] if training_args.do_eval else None,
478
+ tokenizer=feature_extractor,
479
+ data_collator=data_collator,
480
+ compute_metrics=compute_metrics if training_args.predict_with_generate else None,
481
+ optimizers=optimizers,
482
+ )
483
+
484
+ # 12. Training
485
+ if training_args.do_train:
486
+ checkpoint = None
487
+ if training_args.resume_from_checkpoint is not None:
488
+ checkpoint = training_args.resume_from_checkpoint
489
+ elif last_checkpoint is not None:
490
+ checkpoint = last_checkpoint
491
+ train_result = trainer.train(resume_from_checkpoint=checkpoint)
492
+ trainer.save_model() # Saves the feature extractor too for easy upload
493
+
494
+ metrics = train_result.metrics
495
+ max_train_samples = (
496
+ data_args.max_train_samples
497
+ if data_args.max_train_samples is not None
498
+ else len(vectorized_datasets["train"])
499
+ )
500
+ metrics["train_samples"] = min(max_train_samples, len(vectorized_datasets["train"]))
501
+ trainer.log_metrics("train", metrics)
502
+ trainer.save_metrics("train", metrics)
503
+ trainer.save_state()
504
+
505
+ # 13. Evaluation
506
+ results = {}
507
+ if training_args.do_eval:
508
+ logger.info("*** Evaluate ***")
509
+ metrics = trainer.evaluate(
510
+ metric_key_prefix="eval", max_length=model.config.max_length, num_beams=model.config.num_beams
511
+ )
512
+ max_eval_samples = (
513
+ data_args.max_eval_samples if data_args.max_eval_samples is not None else len(vectorized_datasets["eval"])
514
+ )
515
+ metrics["eval_samples"] = min(max_eval_samples, len(vectorized_datasets["eval"]))
516
+
517
+ trainer.log_metrics("eval", metrics)
518
+ trainer.save_metrics("eval", metrics)
519
+
520
+ # 14. Write Training Stats
521
+ kwargs = {"finetuned_from": model_args.model_name_or_path, "tasks": "speech recognition"}
522
+ if data_args.dataset_name is not None:
523
+ kwargs["dataset_tags"] = data_args.dataset_name
524
+ if data_args.dataset_config_name is not None:
525
+ kwargs["dataset_args"] = data_args.dataset_config_name
526
+ kwargs["dataset"] = f"{data_args.dataset_name} {data_args.dataset_config_name}"
527
+ else:
528
+ kwargs["dataset"] = data_args.dataset_name
529
+
530
+ if training_args.push_to_hub:
531
+ trainer.push_to_hub(**kwargs)
532
+ else:
533
+ trainer.create_model_card(**kwargs)
534
+
535
+ return results
536
+
537
+
538
+ if __name__ == "__main__":
539
+ main()
runs/Feb23_15-17-13_sanchit--v100/1645629478.673521/events.out.tfevents.1645629478.sanchit--v100.119082.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6d43aee7e9a127cafd31527c45179e4f9497ee022771a3cc9ddb09873bf3199
3
+ size 4964
runs/Feb23_15-17-13_sanchit--v100/events.out.tfevents.1645629478.sanchit--v100.119082.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac91a55f39ef812d56b3c694c081f889131f0205a87df812220b2c07830493b6
3
+ size 9170
runs/Feb23_15-18-28_sanchit--v100/1645629548.7865512/events.out.tfevents.1645629548.sanchit--v100.119273.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2720296d85500c3d65275e1cbcfdb893776c2ecaab2018cc103475b0049e6f7a
3
+ size 4964
runs/Feb23_15-18-28_sanchit--v100/events.out.tfevents.1645629548.sanchit--v100.119273.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cdaf4bc30e421b11019faa23f2fab3a3376148609382f426208013ab43ee132f
3
+ size 9170
runs/Feb23_15-20-29_sanchit--v100/1645629669.5136263/events.out.tfevents.1645629669.sanchit--v100.119533.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e899c4bb1eb62647b7e4323f15156841ac52b3d614ccd05352b4442c8dd87df0
3
+ size 4964
runs/Feb23_15-20-29_sanchit--v100/events.out.tfevents.1645629669.sanchit--v100.119533.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:108060fec874eae502062a68dd8c9cd69a45ba63672288a672c047230bf8ff5b
3
+ size 9170
runs/Feb23_15-21-38_sanchit--v100/1645629738.8586485/events.out.tfevents.1645629738.sanchit--v100.119714.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c4ff060c7a55e5a3d7164905903042238d66d9437c9dff9ceb4563c0a91550a
3
+ size 4964
runs/Feb23_15-21-38_sanchit--v100/events.out.tfevents.1645629738.sanchit--v100.119714.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:600bccdba6ed9a443d69598d28e8352fdc7029fb60041b75e57706dae53497e9
3
+ size 9171
runs/Feb23_15-22-45_sanchit--v100/1645629807.9885855/events.out.tfevents.1645629807.sanchit--v100.119898.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73c4324949e30b58527fad8d9979c53c580bc5e8a24a7cf0818376ebbd39bcb4
3
+ size 4964
runs/Feb23_15-22-45_sanchit--v100/events.out.tfevents.1645629807.sanchit--v100.119898.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff5cd32921e6778f45e24c9cb990e00c6f2ab2c0f8325b549b223f3d0aa22b2b
3
+ size 9171
runs/Feb23_15-24-03_sanchit--v100/1645629883.5906208/events.out.tfevents.1645629883.sanchit--v100.120087.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d3829afbf6756630f6602ed1ff25d6796e506b8c023ab7462847986c30987dcb
3
+ size 4964
runs/Feb23_15-24-03_sanchit--v100/events.out.tfevents.1645629883.sanchit--v100.120087.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d0cb07ff409753dfdf72b266e96b6e8b8bf57fc2ec2d062df497f9bceacdc78c
3
+ size 9170
runs/Feb23_15-28-39_sanchit--v100/1645630160.6231816/events.out.tfevents.1645630160.sanchit--v100.120564.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:96b6fcf29a0b81c24646e4dc6148d0afb37d09b8dae2573433f2a7631fe53f78
3
+ size 4964
runs/Feb23_15-28-39_sanchit--v100/events.out.tfevents.1645630160.sanchit--v100.120564.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ee9529bd2dbb6c2d972e6879550e91a909b8fc3f0422559007472e7f55ea2f4
3
+ size 9171
runs/Feb23_15-31-07_sanchit--v100/1645630308.0543547/events.out.tfevents.1645630308.sanchit--v100.120839.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ab4c3ea9c6c2c5a75b6daca24ecbb0e6f8f6e048c7ac91610319414ed519f36
3
+ size 4964
runs/Feb23_15-31-07_sanchit--v100/events.out.tfevents.1645630308.sanchit--v100.120839.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:12c2c57e1dc0ac95e0a8122339438cc16264e992f84ce3d4e17dedea3367fe7b
3
+ size 9172
runs/Feb23_15-32-51_sanchit--v100/1645630413.4061124/events.out.tfevents.1645630413.sanchit--v100.121092.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:53d64cfc49593e8879c6eae775a2d97c83e686f72f214f776cdd17cc3626c46f
3
+ size 4964
runs/Feb23_15-32-51_sanchit--v100/events.out.tfevents.1645630413.sanchit--v100.121092.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a27437a339911cdd0627b19f5a0db87c840aadc25ed32900d58d6f88174fd853
3
+ size 11325
runs/Feb23_15-38-52_sanchit--v100/1645630773.5256608/events.out.tfevents.1645630773.sanchit--v100.121718.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c48996fd159fc3f9cceeac9385b7b0a11986f8b07079934f8b37b8c03655289
3
+ size 4964
runs/Feb23_15-38-52_sanchit--v100/events.out.tfevents.1645630773.sanchit--v100.121718.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d74c4a7089475d8373c282caffcd4bbe70eba1205d86a23faeb66d3828cbbf43
3
+ size 9172
runs/Feb23_15-46-20_sanchit--v100/1645631221.2384057/events.out.tfevents.1645631221.sanchit--v100.122633.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:680fff33e275086a0cde022dc28d119f902ccf8693354433cddb69894acc7be7
3
+ size 4964
runs/Feb23_15-46-20_sanchit--v100/events.out.tfevents.1645631221.sanchit--v100.122633.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c26ebda7902e590c50a8b488db24b1f321ffe71d81b904415090a579ea326391
3
+ size 9323
runs/Feb23_15-47-56_sanchit--v100/1645631316.8539507/events.out.tfevents.1645631316.sanchit--v100.122880.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:85c425a554fefda42fb77fb8ec264979b083e19d54c86141d5a589b4365c7af0
3
+ size 4964
runs/Feb23_15-47-56_sanchit--v100/events.out.tfevents.1645631316.sanchit--v100.122880.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:af7fa789dce176b7e9d56d196b246484541bcdcd6660668e66974ff44723a5f5
3
+ size 9170
runs/Feb23_15-49-04_sanchit--v100/1645631387.0714893/events.out.tfevents.1645631387.sanchit--v100.123095.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02464c1c4305f8dfed87383ef996fa8dae731daf6ef936c2d77768e37d2d15a3
3
+ size 4964
runs/Feb23_15-49-04_sanchit--v100/events.out.tfevents.1645631387.sanchit--v100.123095.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:537961314f702e0ddc1ca5437e166567dc79fa2c3fa6d9c4e8b7d2889057eb1a
3
+ size 9169
runs/Feb23_15-57-27_sanchit--v100/1645631887.9999144/events.out.tfevents.1645631888.sanchit--v100.124050.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3331a52e8aa6084d33a0d4fb564340dafbff26a0bae8f97c09a490aea7a5813c
3
+ size 4964
runs/Feb23_15-57-27_sanchit--v100/events.out.tfevents.1645631887.sanchit--v100.124050.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:07383aa63fafa06e0b839fe6c239c780e47636bd9635e3fe0d76f5461a060462
3
+ size 30455
runs/Feb23_16-07-05_sanchit--v100/1645632478.8360717/events.out.tfevents.1645632478.sanchit--v100.125003.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:092ecfad7a174e7fd1c783e2414f6bfe425dbf178957abda0b947436438dbae4
3
+ size 4964
runs/Feb23_16-07-05_sanchit--v100/events.out.tfevents.1645632478.sanchit--v100.125003.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:192323750e8568c8e9556a24ca9dbca18417a58fb27d03dc52a150e433a3f6e7
3
+ size 18099
runs/Feb23_16-12-14_sanchit--v100/1645632776.264174/events.out.tfevents.1645632776.sanchit--v100.125542.1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:190eb06d178bb7ecee5436e97b31f8a4513ca8605a7419107676159f51ee791d
3
+ size 4964
runs/Feb23_16-12-14_sanchit--v100/events.out.tfevents.1645632776.sanchit--v100.125542.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0cbb281572cc9e56e9ae1cfe991fd6032a73ca3f4ea19dd908a85e479a132aea
3
+ size 87604
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "pad_token": "<|endoftext|>"}
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "add_prefix_space": false, "errors": "replace", "model_max_length": 1024, "special_tokens_map_file": null, "name_or_path": "./", "tokenizer_class": "GPT2Tokenizer"}