Training in progress, step 200
Browse files- .gitignore +1 -0
- .ipynb_checkpoints/Untitled-checkpoint.ipynb +6 -0
- Untitled.ipynb +420 -0
- added_tokens.json +1 -0
- config.json +107 -0
- preprocessor_config.json +9 -0
- pytorch_model.bin +3 -0
- run.sh +27 -0
- run_speech_recognition_ctc.py +765 -0
- special_tokens_map.json +1 -0
- tokenizer_config.json +1 -0
- training_args.bin +3 -0
- vocab.json +1 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
checkpoint-*/
|
.ipynb_checkpoints/Untitled-checkpoint.ipynb
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [],
|
3 |
+
"metadata": {},
|
4 |
+
"nbformat": 4,
|
5 |
+
"nbformat_minor": 5
|
6 |
+
}
|
Untitled.ipynb
ADDED
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "85541f92",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stdout",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"02/07/2022 11:34:12 - WARNING - __main__ - Process rank: -1, device: cuda:0, n_gpu: 1distributed training: False, 16-bits training: True\n",
|
14 |
+
"02/07/2022 11:34:12 - INFO - __main__ - Training/evaluation parameters TrainingArguments(\n",
|
15 |
+
"_n_gpu=1,\n",
|
16 |
+
"adafactor=False,\n",
|
17 |
+
"adam_beta1=0.9,\n",
|
18 |
+
"adam_beta2=0.999,\n",
|
19 |
+
"adam_epsilon=1e-08,\n",
|
20 |
+
"bf16=False,\n",
|
21 |
+
"bf16_full_eval=False,\n",
|
22 |
+
"dataloader_drop_last=False,\n",
|
23 |
+
"dataloader_num_workers=0,\n",
|
24 |
+
"dataloader_pin_memory=True,\n",
|
25 |
+
"ddp_bucket_cap_mb=None,\n",
|
26 |
+
"ddp_find_unused_parameters=None,\n",
|
27 |
+
"debug=[],\n",
|
28 |
+
"deepspeed=None,\n",
|
29 |
+
"disable_tqdm=False,\n",
|
30 |
+
"do_eval=True,\n",
|
31 |
+
"do_predict=False,\n",
|
32 |
+
"do_train=True,\n",
|
33 |
+
"eval_accumulation_steps=None,\n",
|
34 |
+
"eval_steps=400,\n",
|
35 |
+
"evaluation_strategy=IntervalStrategy.STEPS,\n",
|
36 |
+
"fp16=True,\n",
|
37 |
+
"fp16_backend=auto,\n",
|
38 |
+
"fp16_full_eval=False,\n",
|
39 |
+
"fp16_opt_level=O1,\n",
|
40 |
+
"gradient_accumulation_steps=1,\n",
|
41 |
+
"gradient_checkpointing=True,\n",
|
42 |
+
"greater_is_better=None,\n",
|
43 |
+
"group_by_length=True,\n",
|
44 |
+
"half_precision_backend=auto,\n",
|
45 |
+
"hub_model_id=None,\n",
|
46 |
+
"hub_strategy=HubStrategy.EVERY_SAVE,\n",
|
47 |
+
"hub_token=<HUB_TOKEN>,\n",
|
48 |
+
"ignore_data_skip=False,\n",
|
49 |
+
"label_names=None,\n",
|
50 |
+
"label_smoothing_factor=0.0,\n",
|
51 |
+
"learning_rate=0.0003,\n",
|
52 |
+
"length_column_name=input_length,\n",
|
53 |
+
"load_best_model_at_end=False,\n",
|
54 |
+
"local_rank=-1,\n",
|
55 |
+
"log_level=-1,\n",
|
56 |
+
"log_level_replica=-1,\n",
|
57 |
+
"log_on_each_node=True,\n",
|
58 |
+
"logging_dir=./runs/Feb07_11-34-12_job-7e123c9a-c8eb-4ec4-9153-164c740ace86,\n",
|
59 |
+
"logging_first_step=False,\n",
|
60 |
+
"logging_nan_inf_filter=True,\n",
|
61 |
+
"logging_steps=500,\n",
|
62 |
+
"logging_strategy=IntervalStrategy.STEPS,\n",
|
63 |
+
"lr_scheduler_type=SchedulerType.LINEAR,\n",
|
64 |
+
"max_grad_norm=1.0,\n",
|
65 |
+
"max_steps=8000,\n",
|
66 |
+
"metric_for_best_model=None,\n",
|
67 |
+
"mp_parameters=,\n",
|
68 |
+
"no_cuda=False,\n",
|
69 |
+
"num_train_epochs=3.0,\n",
|
70 |
+
"optim=OptimizerNames.ADAMW_HF,\n",
|
71 |
+
"output_dir=./,\n",
|
72 |
+
"overwrite_output_dir=True,\n",
|
73 |
+
"past_index=-1,\n",
|
74 |
+
"per_device_eval_batch_size=8,\n",
|
75 |
+
"per_device_train_batch_size=16,\n",
|
76 |
+
"prediction_loss_only=False,\n",
|
77 |
+
"push_to_hub=True,\n",
|
78 |
+
"push_to_hub_model_id=None,\n",
|
79 |
+
"push_to_hub_organization=None,\n",
|
80 |
+
"push_to_hub_token=<PUSH_TO_HUB_TOKEN>,\n",
|
81 |
+
"remove_unused_columns=True,\n",
|
82 |
+
"report_to=[],\n",
|
83 |
+
"resume_from_checkpoint=None,\n",
|
84 |
+
"run_name=./,\n",
|
85 |
+
"save_on_each_node=False,\n",
|
86 |
+
"save_steps=200,\n",
|
87 |
+
"save_strategy=IntervalStrategy.STEPS,\n",
|
88 |
+
"save_total_limit=3,\n",
|
89 |
+
"seed=42,\n",
|
90 |
+
"sharded_ddp=[],\n",
|
91 |
+
"skip_memory_metrics=True,\n",
|
92 |
+
"tf32=None,\n",
|
93 |
+
"tpu_metrics_debug=False,\n",
|
94 |
+
"tpu_num_cores=None,\n",
|
95 |
+
"use_legacy_prediction_loop=False,\n",
|
96 |
+
"warmup_ratio=0.0,\n",
|
97 |
+
"warmup_steps=500,\n",
|
98 |
+
"weight_decay=0.0,\n",
|
99 |
+
"xpu_backend=None,\n",
|
100 |
+
")\n",
|
101 |
+
"02/07/2022 11:34:14 - WARNING - datasets.builder - Reusing dataset common_voice (/workspace/.cache/huggingface/datasets/mozilla-foundation___common_voice/hi/7.0.0/fe20cac47c166e25b1f096ab661832e3da7cf298ed4a91dcaa1343ad972d175b)\n",
|
102 |
+
"02/07/2022 11:34:17 - WARNING - datasets.builder - Reusing dataset common_voice (/workspace/.cache/huggingface/datasets/mozilla-foundation___common_voice/hi/7.0.0/fe20cac47c166e25b1f096ab661832e3da7cf298ed4a91dcaa1343ad972d175b)\n",
|
103 |
+
"02/07/2022 11:34:17 - WARNING - datasets.arrow_dataset - Loading cached processed dataset at /workspace/.cache/huggingface/datasets/mozilla-foundation___common_voice/hi/7.0.0/fe20cac47c166e25b1f096ab661832e3da7cf298ed4a91dcaa1343ad972d175b/cache-56c362c60f5a4e8d.arrow\n",
|
104 |
+
"02/07/2022 11:34:17 - WARNING - datasets.arrow_dataset - Loading cached processed dataset at /workspace/.cache/huggingface/datasets/mozilla-foundation___common_voice/hi/7.0.0/fe20cac47c166e25b1f096ab661832e3da7cf298ed4a91dcaa1343ad972d175b/cache-c2794d9326d1e793.arrow\n",
|
105 |
+
"loading configuration file https://huggingface.co/facebook/wav2vec2-xls-r-300m/resolve/main/config.json from cache at /workspace/.cache/huggingface/transformers/dabc27df63e37bd2a7a221c7774e35f36a280fbdf917cf54cadfc7df8c786f6f.a3e4c3c967d9985881e0ae550a5f6f668f897db5ab2e0802f9b97973b15970e6\n",
|
106 |
+
"Model config Wav2Vec2Config {\n",
|
107 |
+
" \"_name_or_path\": \"facebook/wav2vec2-xls-r-300m\",\n",
|
108 |
+
" \"activation_dropout\": 0.0,\n",
|
109 |
+
" \"adapter_kernel_size\": 3,\n",
|
110 |
+
" \"adapter_stride\": 2,\n",
|
111 |
+
" \"add_adapter\": false,\n",
|
112 |
+
" \"apply_spec_augment\": true,\n",
|
113 |
+
" \"architectures\": [\n",
|
114 |
+
" \"Wav2Vec2ForPreTraining\"\n",
|
115 |
+
" ],\n",
|
116 |
+
" \"attention_dropout\": 0.1,\n",
|
117 |
+
" \"bos_token_id\": 1,\n",
|
118 |
+
" \"classifier_proj_size\": 256,\n",
|
119 |
+
" \"codevector_dim\": 768,\n",
|
120 |
+
" \"contrastive_logits_temperature\": 0.1,\n",
|
121 |
+
" \"conv_bias\": true,\n",
|
122 |
+
" \"conv_dim\": [\n",
|
123 |
+
" 512,\n",
|
124 |
+
" 512,\n",
|
125 |
+
" 512,\n",
|
126 |
+
" 512,\n",
|
127 |
+
" 512,\n",
|
128 |
+
" 512,\n",
|
129 |
+
" 512\n",
|
130 |
+
" ],\n",
|
131 |
+
" \"conv_kernel\": [\n",
|
132 |
+
" 10,\n",
|
133 |
+
" 3,\n",
|
134 |
+
" 3,\n",
|
135 |
+
" 3,\n",
|
136 |
+
" 3,\n",
|
137 |
+
" 2,\n",
|
138 |
+
" 2\n",
|
139 |
+
" ],\n",
|
140 |
+
" \"conv_stride\": [\n",
|
141 |
+
" 5,\n",
|
142 |
+
" 2,\n",
|
143 |
+
" 2,\n",
|
144 |
+
" 2,\n",
|
145 |
+
" 2,\n",
|
146 |
+
" 2,\n",
|
147 |
+
" 2\n",
|
148 |
+
" ],\n",
|
149 |
+
" \"ctc_loss_reduction\": \"sum\",\n",
|
150 |
+
" \"ctc_zero_infinity\": false,\n",
|
151 |
+
" \"diversity_loss_weight\": 0.1,\n",
|
152 |
+
" \"do_stable_layer_norm\": true,\n",
|
153 |
+
" \"eos_token_id\": 2,\n",
|
154 |
+
" \"feat_extract_activation\": \"gelu\",\n",
|
155 |
+
" \"feat_extract_dropout\": 0.0,\n",
|
156 |
+
" \"feat_extract_norm\": \"layer\",\n",
|
157 |
+
" \"feat_proj_dropout\": 0.1,\n",
|
158 |
+
" \"feat_quantizer_dropout\": 0.0,\n",
|
159 |
+
" \"final_dropout\": 0.0,\n",
|
160 |
+
" \"gradient_checkpointing\": false,\n",
|
161 |
+
" \"hidden_act\": \"gelu\",\n",
|
162 |
+
" \"hidden_dropout\": 0.1,\n",
|
163 |
+
" \"hidden_size\": 1024,\n",
|
164 |
+
" \"initializer_range\": 0.02,\n",
|
165 |
+
" \"intermediate_size\": 4096,\n",
|
166 |
+
" \"layer_norm_eps\": 1e-05,\n",
|
167 |
+
" \"layerdrop\": 0.1,\n",
|
168 |
+
" \"mask_feature_length\": 10,\n",
|
169 |
+
" \"mask_feature_min_masks\": 0,\n",
|
170 |
+
" \"mask_feature_prob\": 0.0,\n",
|
171 |
+
" \"mask_time_length\": 10,\n",
|
172 |
+
" \"mask_time_min_masks\": 2,\n",
|
173 |
+
" \"mask_time_prob\": 0.075,\n",
|
174 |
+
" \"model_type\": \"wav2vec2\",\n",
|
175 |
+
" \"num_adapter_layers\": 3,\n",
|
176 |
+
" \"num_attention_heads\": 16,\n",
|
177 |
+
" \"num_codevector_groups\": 2,\n",
|
178 |
+
" \"num_codevectors_per_group\": 320,\n",
|
179 |
+
" \"num_conv_pos_embedding_groups\": 16,\n",
|
180 |
+
" \"num_conv_pos_embeddings\": 128,\n",
|
181 |
+
" \"num_feat_extract_layers\": 7,\n",
|
182 |
+
" \"num_hidden_layers\": 24,\n",
|
183 |
+
" \"num_negatives\": 100,\n",
|
184 |
+
" \"output_hidden_size\": 1024,\n",
|
185 |
+
" \"pad_token_id\": 0,\n",
|
186 |
+
" \"proj_codevector_dim\": 768,\n",
|
187 |
+
" \"tdnn_dilation\": [\n",
|
188 |
+
" 1,\n",
|
189 |
+
" 2,\n",
|
190 |
+
" 3,\n",
|
191 |
+
" 1,\n",
|
192 |
+
" 1\n",
|
193 |
+
" ],\n",
|
194 |
+
" \"tdnn_dim\": [\n",
|
195 |
+
" 512,\n",
|
196 |
+
" 512,\n",
|
197 |
+
" 512,\n",
|
198 |
+
" 512,\n",
|
199 |
+
" 1500\n",
|
200 |
+
" ],\n",
|
201 |
+
" \"tdnn_kernel\": [\n",
|
202 |
+
" 5,\n",
|
203 |
+
" 3,\n",
|
204 |
+
" 3,\n",
|
205 |
+
" 1,\n",
|
206 |
+
" 1\n",
|
207 |
+
" ],\n",
|
208 |
+
" \"torch_dtype\": \"float32\",\n",
|
209 |
+
" \"transformers_version\": \"4.16.2\",\n",
|
210 |
+
" \"use_weighted_layer_sum\": false,\n",
|
211 |
+
" \"vocab_size\": 32,\n",
|
212 |
+
" \"xvector_output_dim\": 512\n",
|
213 |
+
"}\n",
|
214 |
+
"\n",
|
215 |
+
"100%|█████████████████████████████████████████████| 1/1 [00:00<00:00, 3.97ba/s]\n",
|
216 |
+
"100%|█████████████████████████████████████████████| 1/1 [00:00<00:00, 15.14ba/s]\n",
|
217 |
+
"{'j', 'y', 'x', 'l', 'm', 'ज़', 'क', 'ऐ', 'ऊ', 'त', 'ञ', 'p', 'n', 'u', 'ी', 'ऋ', 'ठ', 'छ', 'ा', 'क़', '&', 'c', 'ण', 'ढ़', 'w', 'अ', 'r', ' ', 'ष', 'ट', \"'\", 'ग़', 'f', 'k', 't', 'ृ', 'v', 'भ', 'g', 'स', 'ऑ', 'े', 'झ', 'z', 'ो', 'इ', '|', '।', 'ु', 'ड़', 'ए', 'h', 'ब', 'ध', 'ग', 'ः', 'i', 'श', 'औ', 'र', 'e', 'य', 'ड', 'प', 'ि', 's', 'म', 'b', 'ख', '़', 'ल', 'ई', 'उ', 'द', 'ज', 'ढ', 'ओ', 'ॉ', 'ं', 'च', 'a', 'न', 'ै', 'घ', 'थ', 'o', 'फ', 'ँ', 'आ', 'd', 'ौ', 'ॅ', 'व', 'ू', '्', 'ह'} 96 <class 'set'> {' ': 0, '&': 1, \"'\": 2, 'a': 3, 'b': 4, 'c': 5, 'd': 6, 'e': 7, 'f': 8, 'g': 9, 'h': 10, 'i': 11, 'j': 12, 'k': 13, 'l': 14, 'm': 15, 'n': 16, 'o': 17, 'p': 18, 'r': 19, 's': 20, 't': 21, 'u': 22, 'v': 23, 'w': 24, 'x': 25, 'y': 26, 'z': 27, '|': 28, 'ँ': 29, 'ं': 30, 'ः': 31, 'अ': 32, 'आ': 33, 'इ': 34, 'ई': 35, 'उ': 36, 'ऊ': 37, 'ऋ': 38, 'ए': 39, 'ऐ': 40, 'ऑ': 41, 'ओ': 42, 'औ': 43, 'क': 44, 'ख': 45, 'ग': 46, 'घ': 47, 'च': 48, 'छ': 49, 'ज': 50, 'झ': 51, 'ञ': 52, 'ट': 53, 'ठ': 54, 'ड': 55, 'ढ': 56, 'ण': 57, 'त': 58, 'थ': 59, 'द': 60, 'ध': 61, 'न': 62, 'प': 63, 'फ': 64, 'ब': 65, 'भ': 66, 'म': 67, 'य': 68, 'र': 69, 'ल': 70, 'व': 71, 'श': 72, 'ष': 73, 'स': 74, 'ह': 75, '़': 76, 'ा': 77, 'ि': 78, 'ी': 79, 'ु': 80, 'ू': 81, 'ृ': 82, 'ॅ': 83, 'े': 84, 'ै': 85, 'ॉ': 86, 'ो': 87, 'ौ': 88, '्': 89, 'क़': 90, 'ग़': 91, 'ज़': 92, 'ड़': 93, 'ढ़': 94, '।': 95}\n",
|
218 |
+
"{'&': 1, \"'\": 2, 'a': 3, 'b': 4, 'c': 5, 'd': 6, 'e': 7, 'f': 8, 'g': 9, 'h': 10, 'i': 11, 'j': 12, 'k': 13, 'l': 14, 'm': 15, 'n': 16, 'o': 17, 'p': 18, 'r': 19, 's': 20, 't': 21, 'u': 22, 'v': 23, 'w': 24, 'x': 25, 'y': 26, 'z': 27, '|': 28, 'ँ': 29, 'ं': 30, 'ः': 31, 'अ': 32, 'आ': 33, 'इ': 34, 'ई': 35, 'उ': 36, 'ऊ': 37, 'ऋ': 38, 'ए': 39, 'ऐ': 40, 'ऑ': 41, 'ओ': 42, 'औ': 43, 'क': 44, 'ख': 45, 'ग': 46, 'घ': 47, 'च': 48, 'छ': 49, 'ज': 50, 'झ': 51, 'ञ': 52, 'ट': 53, 'ठ': 54, 'ड': 55, 'ढ': 56, 'ण': 57, 'त': 58, 'थ': 59, 'द': 60, 'ध': 61, 'न': 62, 'प': 63, 'फ': 64, 'ब': 65, 'भ': 66, 'म': 67, 'य': 68, 'र': 69, 'ल': 70, 'व': 71, 'श': 72, 'ष': 73, 'स': 74, 'ह': 75, '़': 76, 'ा': 77, 'ि': 78, 'ी': 79, 'ु': 80, 'ू': 81, 'ृ': 82, 'ॅ': 83, 'े': 84, 'ै': 85, 'ॉ': 86, 'ो': 87, 'ौ': 88, '्': 89, 'क़': 90, 'ग़': 91, 'ज़': 92, 'ड़': 93, 'ढ़': 94, '।': 95, '$': 0, '[UNK]': 96, '[PAD]': 97}\n",
|
219 |
+
"Didn't find file ./tokenizer_config.json. We won't load it.\n",
|
220 |
+
"Didn't find file ./added_tokens.json. We won't load it.\n",
|
221 |
+
"Didn't find file ./special_tokens_map.json. We won't load it.\n",
|
222 |
+
"Didn't find file ./tokenizer.json. We won't load it.\n",
|
223 |
+
"loading file ./vocab.json\n",
|
224 |
+
"loading file None\n",
|
225 |
+
"loading file None\n",
|
226 |
+
"loading file None\n",
|
227 |
+
"loading file None\n",
|
228 |
+
"file ./config.json not found\n",
|
229 |
+
"Adding <s> to the vocabulary\n",
|
230 |
+
"Adding </s> to the vocabulary\n",
|
231 |
+
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n",
|
232 |
+
"loading configuration file https://huggingface.co/facebook/wav2vec2-xls-r-300m/resolve/main/config.json from cache at /workspace/.cache/huggingface/transformers/dabc27df63e37bd2a7a221c7774e35f36a280fbdf917cf54cadfc7df8c786f6f.a3e4c3c967d9985881e0ae550a5f6f668f897db5ab2e0802f9b97973b15970e6\n",
|
233 |
+
"Model config Wav2Vec2Config {\n",
|
234 |
+
" \"_name_or_path\": \"facebook/wav2vec2-xls-r-300m\",\n",
|
235 |
+
" \"activation_dropout\": 0.0,\n",
|
236 |
+
" \"adapter_kernel_size\": 3,\n",
|
237 |
+
" \"adapter_stride\": 2,\n",
|
238 |
+
" \"add_adapter\": false,\n",
|
239 |
+
" \"apply_spec_augment\": true,\n",
|
240 |
+
" \"architectures\": [\n",
|
241 |
+
" \"Wav2Vec2ForPreTraining\"\n",
|
242 |
+
" ],\n",
|
243 |
+
" \"attention_dropout\": 0.1,\n",
|
244 |
+
" \"bos_token_id\": 1,\n",
|
245 |
+
" \"classifier_proj_size\": 256,\n",
|
246 |
+
" \"codevector_dim\": 768,\n",
|
247 |
+
" \"contrastive_logits_temperature\": 0.1,\n",
|
248 |
+
" \"conv_bias\": true,\n",
|
249 |
+
" \"conv_dim\": [\n",
|
250 |
+
" 512,\n",
|
251 |
+
" 512,\n",
|
252 |
+
" 512,\n",
|
253 |
+
" 512,\n",
|
254 |
+
" 512,\n",
|
255 |
+
" 512,\n",
|
256 |
+
" 512\n",
|
257 |
+
" ],\n",
|
258 |
+
" \"conv_kernel\": [\n",
|
259 |
+
" 10,\n",
|
260 |
+
" 3,\n",
|
261 |
+
" 3,\n",
|
262 |
+
" 3,\n",
|
263 |
+
" 3,\n",
|
264 |
+
" 2,\n",
|
265 |
+
" 2\n",
|
266 |
+
" ],\n",
|
267 |
+
" \"conv_stride\": [\n",
|
268 |
+
" 5,\n",
|
269 |
+
" 2,\n",
|
270 |
+
" 2,\n",
|
271 |
+
" 2,\n",
|
272 |
+
" 2,\n",
|
273 |
+
" 2,\n",
|
274 |
+
" 2\n",
|
275 |
+
" ],\n",
|
276 |
+
" \"ctc_loss_reduction\": \"sum\",\n",
|
277 |
+
" \"ctc_zero_infinity\": false,\n",
|
278 |
+
" \"diversity_loss_weight\": 0.1,\n",
|
279 |
+
" \"do_stable_layer_norm\": true,\n",
|
280 |
+
" \"eos_token_id\": 2,\n",
|
281 |
+
" \"feat_extract_activation\": \"gelu\",\n",
|
282 |
+
" \"feat_extract_dropout\": 0.0,\n",
|
283 |
+
" \"feat_extract_norm\": \"layer\",\n",
|
284 |
+
" \"feat_proj_dropout\": 0.1,\n",
|
285 |
+
" \"feat_quantizer_dropout\": 0.0,\n",
|
286 |
+
" \"final_dropout\": 0.0,\n",
|
287 |
+
" \"gradient_checkpointing\": false,\n",
|
288 |
+
" \"hidden_act\": \"gelu\",\n",
|
289 |
+
" \"hidden_dropout\": 0.1,\n",
|
290 |
+
" \"hidden_size\": 1024,\n",
|
291 |
+
" \"initializer_range\": 0.02,\n",
|
292 |
+
" \"intermediate_size\": 4096,\n",
|
293 |
+
" \"layer_norm_eps\": 1e-05,\n",
|
294 |
+
" \"layerdrop\": 0.1,\n",
|
295 |
+
" \"mask_feature_length\": 10,\n",
|
296 |
+
" \"mask_feature_min_masks\": 0,\n",
|
297 |
+
" \"mask_feature_prob\": 0.0,\n",
|
298 |
+
" \"mask_time_length\": 10,\n",
|
299 |
+
" \"mask_time_min_masks\": 2,\n",
|
300 |
+
" \"mask_time_prob\": 0.075,\n",
|
301 |
+
" \"model_type\": \"wav2vec2\",\n",
|
302 |
+
" \"num_adapter_layers\": 3,\n",
|
303 |
+
" \"num_attention_heads\": 16,\n",
|
304 |
+
" \"num_codevector_groups\": 2,\n",
|
305 |
+
" \"num_codevectors_per_group\": 320,\n",
|
306 |
+
" \"num_conv_pos_embedding_groups\": 16,\n",
|
307 |
+
" \"num_conv_pos_embeddings\": 128,\n",
|
308 |
+
" \"num_feat_extract_layers\": 7,\n",
|
309 |
+
" \"num_hidden_layers\": 24,\n",
|
310 |
+
" \"num_negatives\": 100,\n",
|
311 |
+
" \"output_hidden_size\": 1024,\n",
|
312 |
+
" \"pad_token_id\": 0,\n",
|
313 |
+
" \"proj_codevector_dim\": 768,\n",
|
314 |
+
" \"tdnn_dilation\": [\n",
|
315 |
+
" 1,\n",
|
316 |
+
" 2,\n",
|
317 |
+
" 3,\n",
|
318 |
+
" 1,\n",
|
319 |
+
" 1\n",
|
320 |
+
" ],\n",
|
321 |
+
" \"tdnn_dim\": [\n",
|
322 |
+
" 512,\n",
|
323 |
+
" 512,\n",
|
324 |
+
" 512,\n",
|
325 |
+
" 512,\n",
|
326 |
+
" 1500\n",
|
327 |
+
" ],\n",
|
328 |
+
" \"tdnn_kernel\": [\n",
|
329 |
+
" 5,\n",
|
330 |
+
" 3,\n",
|
331 |
+
" 3,\n",
|
332 |
+
" 1,\n",
|
333 |
+
" 1\n",
|
334 |
+
" ],\n",
|
335 |
+
" \"torch_dtype\": \"float32\",\n",
|
336 |
+
" \"transformers_version\": \"4.16.2\",\n",
|
337 |
+
" \"use_weighted_layer_sum\": false,\n",
|
338 |
+
" \"vocab_size\": 32,\n",
|
339 |
+
" \"xvector_output_dim\": 512\n",
|
340 |
+
"}\n",
|
341 |
+
"\n",
|
342 |
+
"loading feature extractor configuration file https://huggingface.co/facebook/wav2vec2-xls-r-300m/resolve/main/preprocessor_config.json from cache at /workspace/.cache/huggingface/transformers/6fb028b95b394059e7d3b367bbca2382b576c66aebe896f04d2cd34e1b575f5b.d4484dc1c81456a2461485e7168b04347a7b9a4e3b1ef3aba723323b33e12326\n",
|
343 |
+
"Feature extractor Wav2Vec2FeatureExtractor {\n",
|
344 |
+
" \"do_normalize\": true,\n",
|
345 |
+
" \"feature_extractor_type\": \"Wav2Vec2FeatureExtractor\",\n",
|
346 |
+
" \"feature_size\": 1,\n",
|
347 |
+
" \"padding_side\": \"right\",\n",
|
348 |
+
" \"padding_value\": 0,\n",
|
349 |
+
" \"return_attention_mask\": true,\n",
|
350 |
+
" \"sampling_rate\": 16000\n",
|
351 |
+
"}\n",
|
352 |
+
"\n",
|
353 |
+
"loading weights file https://huggingface.co/facebook/wav2vec2-xls-r-300m/resolve/main/pytorch_model.bin from cache at /workspace/.cache/huggingface/transformers/1e6a6507f3b689035cd4b247e2a37c154e27f39143f31357a49b4e38baeccc36.1edb32803799e27ed554eb7dd935f6745b1a0b17b0ea256442fe24db6eb546cd\n",
|
354 |
+
"^C\n",
|
355 |
+
"Traceback (most recent call last):\n",
|
356 |
+
" File \"run_speech_recognition_ctc.py\", line 765, in <module>\n",
|
357 |
+
" main()\n",
|
358 |
+
" File \"run_speech_recognition_ctc.py\", line 572, in main\n",
|
359 |
+
" model = AutoModelForCTC.from_pretrained(\n",
|
360 |
+
" File \"/workspace/.local/lib/python3.8/site-packages/transformers/models/auto/auto_factory.py\", line 447, in from_pretrained\n",
|
361 |
+
" return model_class.from_pretrained(pretrained_model_name_or_path, *model_args, config=config, **kwargs)\n",
|
362 |
+
" File \"/workspace/.local/lib/python3.8/site-packages/transformers/modeling_utils.py\", line 1489, in from_pretrained\n",
|
363 |
+
" model = cls(config, *model_args, **model_kwargs)\n",
|
364 |
+
" File \"/workspace/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_wav2vec2.py\", line 1680, in __init__\n",
|
365 |
+
" self.wav2vec2 = Wav2Vec2Model(config)\n",
|
366 |
+
" File \"/workspace/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_wav2vec2.py\", line 1234, in __init__\n",
|
367 |
+
" self.encoder = Wav2Vec2EncoderStableLayerNorm(config)\n",
|
368 |
+
" File \"/workspace/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_wav2vec2.py\", line 859, in __init__\n",
|
369 |
+
" [Wav2Vec2EncoderLayerStableLayerNorm(config) for _ in range(config.num_hidden_layers)]\n",
|
370 |
+
" File \"/workspace/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_wav2vec2.py\", line 859, in <listcomp>\n",
|
371 |
+
" [Wav2Vec2EncoderLayerStableLayerNorm(config) for _ in range(config.num_hidden_layers)]\n",
|
372 |
+
" File \"/workspace/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_wav2vec2.py\", line 737, in __init__\n",
|
373 |
+
" self.attention = Wav2Vec2Attention(\n",
|
374 |
+
" File \"/workspace/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_wav2vec2.py\", line 559, in __init__\n",
|
375 |
+
" self.q_proj = nn.Linear(embed_dim, embed_dim, bias=bias)\n",
|
376 |
+
" File \"/opt/conda/lib/python3.8/site-packages/torch/nn/modules/linear.py\", line 90, in __init__\n",
|
377 |
+
" self.reset_parameters()\n",
|
378 |
+
" File \"/opt/conda/lib/python3.8/site-packages/torch/nn/modules/linear.py\", line 96, in reset_parameters\n",
|
379 |
+
" init.kaiming_uniform_(self.weight, a=math.sqrt(5))\n",
|
380 |
+
" File \"/opt/conda/lib/python3.8/site-packages/torch/nn/init.py\", line 395, in kaiming_uniform_\n",
|
381 |
+
" return tensor.uniform_(-bound, bound)\n",
|
382 |
+
"KeyboardInterrupt\n"
|
383 |
+
]
|
384 |
+
}
|
385 |
+
],
|
386 |
+
"source": [
|
387 |
+
"!. run.sh"
|
388 |
+
]
|
389 |
+
},
|
390 |
+
{
|
391 |
+
"cell_type": "code",
|
392 |
+
"execution_count": null,
|
393 |
+
"id": "5c2d3236",
|
394 |
+
"metadata": {},
|
395 |
+
"outputs": [],
|
396 |
+
"source": []
|
397 |
+
}
|
398 |
+
],
|
399 |
+
"metadata": {
|
400 |
+
"kernelspec": {
|
401 |
+
"display_name": "Python 3",
|
402 |
+
"language": "python",
|
403 |
+
"name": "python3"
|
404 |
+
},
|
405 |
+
"language_info": {
|
406 |
+
"codemirror_mode": {
|
407 |
+
"name": "ipython",
|
408 |
+
"version": 3
|
409 |
+
},
|
410 |
+
"file_extension": ".py",
|
411 |
+
"mimetype": "text/x-python",
|
412 |
+
"name": "python",
|
413 |
+
"nbconvert_exporter": "python",
|
414 |
+
"pygments_lexer": "ipython3",
|
415 |
+
"version": "3.8.8"
|
416 |
+
}
|
417 |
+
},
|
418 |
+
"nbformat": 4,
|
419 |
+
"nbformat_minor": 5
|
420 |
+
}
|
added_tokens.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"<s>": 98, "</s>": 99}
|
config.json
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "facebook/wav2vec2-xls-r-300m",
|
3 |
+
"activation_dropout": 0.0,
|
4 |
+
"adapter_kernel_size": 3,
|
5 |
+
"adapter_stride": 2,
|
6 |
+
"add_adapter": false,
|
7 |
+
"apply_spec_augment": true,
|
8 |
+
"architectures": [
|
9 |
+
"Wav2Vec2ForCTC"
|
10 |
+
],
|
11 |
+
"attention_dropout": 0.0,
|
12 |
+
"bos_token_id": 1,
|
13 |
+
"classifier_proj_size": 256,
|
14 |
+
"codevector_dim": 768,
|
15 |
+
"contrastive_logits_temperature": 0.1,
|
16 |
+
"conv_bias": true,
|
17 |
+
"conv_dim": [
|
18 |
+
512,
|
19 |
+
512,
|
20 |
+
512,
|
21 |
+
512,
|
22 |
+
512,
|
23 |
+
512,
|
24 |
+
512
|
25 |
+
],
|
26 |
+
"conv_kernel": [
|
27 |
+
10,
|
28 |
+
3,
|
29 |
+
3,
|
30 |
+
3,
|
31 |
+
3,
|
32 |
+
2,
|
33 |
+
2
|
34 |
+
],
|
35 |
+
"conv_stride": [
|
36 |
+
5,
|
37 |
+
2,
|
38 |
+
2,
|
39 |
+
2,
|
40 |
+
2,
|
41 |
+
2,
|
42 |
+
2
|
43 |
+
],
|
44 |
+
"ctc_loss_reduction": "mean",
|
45 |
+
"ctc_zero_infinity": false,
|
46 |
+
"diversity_loss_weight": 0.1,
|
47 |
+
"do_stable_layer_norm": true,
|
48 |
+
"eos_token_id": 2,
|
49 |
+
"feat_extract_activation": "gelu",
|
50 |
+
"feat_extract_dropout": 0.0,
|
51 |
+
"feat_extract_norm": "layer",
|
52 |
+
"feat_proj_dropout": 0.0,
|
53 |
+
"feat_quantizer_dropout": 0.0,
|
54 |
+
"final_dropout": 0.0,
|
55 |
+
"hidden_act": "gelu",
|
56 |
+
"hidden_dropout": 0.0,
|
57 |
+
"hidden_size": 1024,
|
58 |
+
"initializer_range": 0.02,
|
59 |
+
"intermediate_size": 4096,
|
60 |
+
"layer_norm_eps": 1e-05,
|
61 |
+
"layerdrop": 0.0,
|
62 |
+
"mask_feature_length": 10,
|
63 |
+
"mask_feature_min_masks": 0,
|
64 |
+
"mask_feature_prob": 0.0,
|
65 |
+
"mask_time_length": 10,
|
66 |
+
"mask_time_min_masks": 2,
|
67 |
+
"mask_time_prob": 0.05,
|
68 |
+
"model_type": "wav2vec2",
|
69 |
+
"num_adapter_layers": 3,
|
70 |
+
"num_attention_heads": 16,
|
71 |
+
"num_codevector_groups": 2,
|
72 |
+
"num_codevectors_per_group": 320,
|
73 |
+
"num_conv_pos_embedding_groups": 16,
|
74 |
+
"num_conv_pos_embeddings": 128,
|
75 |
+
"num_feat_extract_layers": 7,
|
76 |
+
"num_hidden_layers": 24,
|
77 |
+
"num_negatives": 100,
|
78 |
+
"output_hidden_size": 1024,
|
79 |
+
"pad_token_id": 97,
|
80 |
+
"proj_codevector_dim": 768,
|
81 |
+
"tdnn_dilation": [
|
82 |
+
1,
|
83 |
+
2,
|
84 |
+
3,
|
85 |
+
1,
|
86 |
+
1
|
87 |
+
],
|
88 |
+
"tdnn_dim": [
|
89 |
+
512,
|
90 |
+
512,
|
91 |
+
512,
|
92 |
+
512,
|
93 |
+
1500
|
94 |
+
],
|
95 |
+
"tdnn_kernel": [
|
96 |
+
5,
|
97 |
+
3,
|
98 |
+
3,
|
99 |
+
1,
|
100 |
+
1
|
101 |
+
],
|
102 |
+
"torch_dtype": "float32",
|
103 |
+
"transformers_version": "4.16.2",
|
104 |
+
"use_weighted_layer_sum": false,
|
105 |
+
"vocab_size": 100,
|
106 |
+
"xvector_output_dim": 512
|
107 |
+
}
|
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,
|
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:8b94df9afab6a29dde619f3dae5b5c27e9f1d4aba16828352b07ee3a2b43a008
|
3 |
+
size 1262333681
|
run.sh
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
python run_speech_recognition_ctc.py \
|
2 |
+
--dataset_name="mozilla-foundation/common_voice_7_0" \
|
3 |
+
--model_name_or_path="facebook/wav2vec2-xls-r-300m" \
|
4 |
+
--dataset_config_name="hi" \
|
5 |
+
--output_dir="./" \
|
6 |
+
--overwrite_output_dir \
|
7 |
+
--max_steps="8000" \
|
8 |
+
--per_device_train_batch_size="16" \
|
9 |
+
--learning_rate="3e-4" \
|
10 |
+
--warmup_steps="500" \
|
11 |
+
--save_steps="200" \
|
12 |
+
--eval_steps="400" \
|
13 |
+
--save_total_limit="3" \
|
14 |
+
--evaluation_strategy="steps" \
|
15 |
+
--text_column_name="sentence" \
|
16 |
+
--length_column_name="input_length" \
|
17 |
+
--layerdrop="0.0" \
|
18 |
+
--freeze_feature_encoder \
|
19 |
+
--gradient_checkpointing \
|
20 |
+
--fp16 \
|
21 |
+
--group_by_length \
|
22 |
+
--push_to_hub \
|
23 |
+
--use_auth_token \
|
24 |
+
--do_train \
|
25 |
+
--do_eval \
|
26 |
+
--chars_to_ignore , ? . ! - \; \: \" “ % ‘ ” � \
|
27 |
+
|
run_speech_recognition_ctc.py
ADDED
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding=utf-8
|
3 |
+
# Copyright 2021 The HuggingFace Inc. 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:a
|
10 |
+
# //www.apache.org/licenses/LICENSE-2.0
|
11 |
+
#
|
12 |
+
# Unless required by applicable law or agreed to in writing, software
|
13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15 |
+
# See the License for the specific language governing permissions and
|
16 |
+
|
17 |
+
""" Fine-tuning a 🤗 Transformers CTC model for automatic speech recognition"""
|
18 |
+
|
19 |
+
import functools
|
20 |
+
import json
|
21 |
+
import logging
|
22 |
+
import os
|
23 |
+
import re
|
24 |
+
import sys
|
25 |
+
import warnings
|
26 |
+
from dataclasses import dataclass, field
|
27 |
+
from typing import Dict, List, Optional, Union
|
28 |
+
|
29 |
+
import datasets
|
30 |
+
import numpy as np
|
31 |
+
import torch
|
32 |
+
from datasets import DatasetDict, load_dataset, load_metric
|
33 |
+
|
34 |
+
import transformers
|
35 |
+
from transformers import (
|
36 |
+
AutoConfig,
|
37 |
+
AutoFeatureExtractor,
|
38 |
+
AutoModelForCTC,
|
39 |
+
AutoProcessor,
|
40 |
+
AutoTokenizer,
|
41 |
+
HfArgumentParser,
|
42 |
+
Trainer,
|
43 |
+
TrainingArguments,
|
44 |
+
Wav2Vec2Processor,
|
45 |
+
set_seed,
|
46 |
+
)
|
47 |
+
from transformers.trainer_utils import get_last_checkpoint, is_main_process
|
48 |
+
from transformers.utils import check_min_version
|
49 |
+
from transformers.utils.versions import require_version
|
50 |
+
|
51 |
+
|
52 |
+
# Will error if the minimal version of Transformers is not installed. Remove at your own risks.
|
53 |
+
check_min_version("4.16.0.dev0")
|
54 |
+
|
55 |
+
require_version("datasets>=1.13.3", "To fix: pip install -r examples/pytorch/text-classification/requirements.txt")
|
56 |
+
|
57 |
+
|
58 |
+
logger = logging.getLogger(__name__)
|
59 |
+
|
60 |
+
|
61 |
+
def list_field(default=None, metadata=None):
|
62 |
+
return field(default_factory=lambda: default, metadata=metadata)
|
63 |
+
|
64 |
+
|
65 |
+
@dataclass
|
66 |
+
class ModelArguments:
|
67 |
+
"""
|
68 |
+
Arguments pertaining to which model/config/tokenizer we are going to fine-tune from.
|
69 |
+
"""
|
70 |
+
|
71 |
+
model_name_or_path: str = field(
|
72 |
+
metadata={"help": "Path to pretrained model or model identifier from huggingface.co/models"}
|
73 |
+
)
|
74 |
+
tokenizer_name_or_path: Optional[str] = field(
|
75 |
+
default=None,
|
76 |
+
metadata={"help": "Path to pretrained tokenizer or tokenizer identifier from huggingface.co/models"},
|
77 |
+
)
|
78 |
+
cache_dir: Optional[str] = field(
|
79 |
+
default=None,
|
80 |
+
metadata={"help": "Where do you want to store the pretrained models downloaded from huggingface.co"},
|
81 |
+
)
|
82 |
+
freeze_feature_encoder: bool = field(
|
83 |
+
default=True, metadata={"help": "Whether to freeze the feature encoder layers of the model."}
|
84 |
+
)
|
85 |
+
attention_dropout: float = field(
|
86 |
+
default=0.0, metadata={"help": "The dropout ratio for the attention probabilities."}
|
87 |
+
)
|
88 |
+
activation_dropout: float = field(
|
89 |
+
default=0.0, metadata={"help": "The dropout ratio for activations inside the fully connected layer."}
|
90 |
+
)
|
91 |
+
feat_proj_dropout: float = field(default=0.0, metadata={"help": "The dropout ratio for the projected features."})
|
92 |
+
hidden_dropout: float = field(
|
93 |
+
default=0.0,
|
94 |
+
metadata={
|
95 |
+
"help": "The dropout probability for all fully connected layers in the embeddings, encoder, and pooler."
|
96 |
+
},
|
97 |
+
)
|
98 |
+
final_dropout: float = field(
|
99 |
+
default=0.0,
|
100 |
+
metadata={"help": "The dropout probability for the final projection layer."},
|
101 |
+
)
|
102 |
+
mask_time_prob: float = field(
|
103 |
+
default=0.05,
|
104 |
+
metadata={
|
105 |
+
"help": "Probability of each feature vector along the time axis to be chosen as the start of the vector"
|
106 |
+
"span to be masked. Approximately ``mask_time_prob * sequence_length // mask_time_length`` feature"
|
107 |
+
"vectors will be masked along the time axis."
|
108 |
+
},
|
109 |
+
)
|
110 |
+
mask_time_length: int = field(
|
111 |
+
default=10,
|
112 |
+
metadata={"help": "Length of vector span to mask along the time axis."},
|
113 |
+
)
|
114 |
+
mask_feature_prob: float = field(
|
115 |
+
default=0.0,
|
116 |
+
metadata={
|
117 |
+
"help": "Probability of each feature vector along the feature axis to be chosen as the start of the vector"
|
118 |
+
"span to be masked. Approximately ``mask_feature_prob * sequence_length // mask_feature_length`` feature bins will be masked along the time axis."
|
119 |
+
},
|
120 |
+
)
|
121 |
+
mask_feature_length: int = field(
|
122 |
+
default=10,
|
123 |
+
metadata={"help": "Length of vector span to mask along the feature axis."},
|
124 |
+
)
|
125 |
+
layerdrop: float = field(default=0.0, metadata={"help": "The LayerDrop probability."})
|
126 |
+
ctc_loss_reduction: Optional[str] = field(
|
127 |
+
default="mean", metadata={"help": "The way the ctc loss should be reduced. Should be one of 'mean' or 'sum'."}
|
128 |
+
)
|
129 |
+
|
130 |
+
|
131 |
+
@dataclass
|
132 |
+
class DataTrainingArguments:
|
133 |
+
"""
|
134 |
+
Arguments pertaining to what data we are going to input our model for training and eval.
|
135 |
+
|
136 |
+
Using `HfArgumentParser` we can turn this class
|
137 |
+
into argparse arguments to be able to specify them on
|
138 |
+
the command line.
|
139 |
+
"""
|
140 |
+
|
141 |
+
dataset_name: str = field(
|
142 |
+
metadata={"help": "The configuration name of the dataset to use (via the datasets library)."}
|
143 |
+
)
|
144 |
+
dataset_config_name: str = field(
|
145 |
+
default=None, metadata={"help": "The configuration name of the dataset to use (via the datasets library)."}
|
146 |
+
)
|
147 |
+
train_split_name: str = field(
|
148 |
+
default="train+validation",
|
149 |
+
metadata={
|
150 |
+
"help": "The name of the training data set split to use (via the datasets library). Defaults to 'train'"
|
151 |
+
},
|
152 |
+
)
|
153 |
+
eval_split_name: str = field(
|
154 |
+
default="test",
|
155 |
+
metadata={
|
156 |
+
"help": "The name of the training data set split to use (via the datasets library). Defaults to 'train'"
|
157 |
+
},
|
158 |
+
)
|
159 |
+
audio_column_name: str = field(
|
160 |
+
default="audio",
|
161 |
+
metadata={"help": "The name of the dataset column containing the audio data. Defaults to 'audio'"},
|
162 |
+
)
|
163 |
+
text_column_name: str = field(
|
164 |
+
default="text",
|
165 |
+
metadata={"help": "The name of the dataset column containing the text data. Defaults to 'text'"},
|
166 |
+
)
|
167 |
+
overwrite_cache: bool = field(
|
168 |
+
default=False, metadata={"help": "Overwrite the cached preprocessed datasets or not."}
|
169 |
+
)
|
170 |
+
preprocessing_num_workers: Optional[int] = field(
|
171 |
+
default=None,
|
172 |
+
metadata={"help": "The number of processes to use for the preprocessing."},
|
173 |
+
)
|
174 |
+
max_train_samples: Optional[int] = field(
|
175 |
+
default=None,
|
176 |
+
metadata={
|
177 |
+
"help": "For debugging purposes or quicker training, truncate the number of training examples to this "
|
178 |
+
"value if set."
|
179 |
+
},
|
180 |
+
)
|
181 |
+
max_eval_samples: Optional[int] = field(
|
182 |
+
default=None,
|
183 |
+
metadata={
|
184 |
+
"help": "For debugging purposes or quicker training, truncate the number of validation examples to this "
|
185 |
+
"value if set."
|
186 |
+
},
|
187 |
+
)
|
188 |
+
chars_to_ignore: Optional[List[str]] = list_field(
|
189 |
+
default=None,
|
190 |
+
metadata={"help": "A list of characters to remove from the transcripts."},
|
191 |
+
)
|
192 |
+
eval_metrics: List[str] = list_field(
|
193 |
+
default=["wer"],
|
194 |
+
metadata={"help": "A list of metrics the model should be evaluated on. E.g. `'wer cer'`"},
|
195 |
+
)
|
196 |
+
max_duration_in_seconds: float = field(
|
197 |
+
default=20.0,
|
198 |
+
metadata={
|
199 |
+
"help": "Filter audio files that are longer than `max_duration_in_seconds` seconds to 'max_duration_in_seconds`"
|
200 |
+
},
|
201 |
+
)
|
202 |
+
min_duration_in_seconds: float = field(
|
203 |
+
default=0.0, metadata={"help": "Filter audio files that are shorter than `min_duration_in_seconds` seconds"}
|
204 |
+
)
|
205 |
+
preprocessing_only: bool = field(
|
206 |
+
default=False,
|
207 |
+
metadata={
|
208 |
+
"help": "Whether to only do data preprocessing and skip training. "
|
209 |
+
"This is especially useful when data preprocessing errors out in distributed training due to timeout. "
|
210 |
+
"In this case, one should run the preprocessing in a non-distributed setup with `preprocessing_only=True` "
|
211 |
+
"so that the cached datasets can consequently be loaded in distributed training"
|
212 |
+
},
|
213 |
+
)
|
214 |
+
use_auth_token: bool = field(
|
215 |
+
default=False,
|
216 |
+
metadata={
|
217 |
+
"help": "If :obj:`True`, will use the token generated when running"
|
218 |
+
":obj:`transformers-cli login` as HTTP bearer authorization for remote files."
|
219 |
+
},
|
220 |
+
)
|
221 |
+
unk_token: str = field(
|
222 |
+
default="[UNK]",
|
223 |
+
metadata={"help": "The unk token for the tokenizer"},
|
224 |
+
)
|
225 |
+
pad_token: str = field(
|
226 |
+
default="[PAD]",
|
227 |
+
metadata={"help": "The padding token for the tokenizer"},
|
228 |
+
)
|
229 |
+
word_delimiter_token: str = field(
|
230 |
+
default="$",
|
231 |
+
metadata={"help": "The word delimiter token for the tokenizer"},
|
232 |
+
)
|
233 |
+
phoneme_language: Optional[str] = field(
|
234 |
+
default=None,
|
235 |
+
metadata={
|
236 |
+
"help": "The target language that should be used be"
|
237 |
+
" passed to the tokenizer for tokenization. Note that"
|
238 |
+
" this is only relevant if the model classifies the"
|
239 |
+
" input audio to a sequence of phoneme sequences."
|
240 |
+
},
|
241 |
+
)
|
242 |
+
|
243 |
+
|
244 |
+
@dataclass
|
245 |
+
class DataCollatorCTCWithPadding:
|
246 |
+
"""
|
247 |
+
Data collator that will dynamically pad the inputs received.
|
248 |
+
Args:
|
249 |
+
processor (:class:`~transformers.AutoProcessor`)
|
250 |
+
The processor used for proccessing the data.
|
251 |
+
padding (:obj:`bool`, :obj:`str` or :class:`~transformers.tokenization_utils_base.PaddingStrategy`, `optional`, defaults to :obj:`True`):
|
252 |
+
Select a strategy to pad the returned sequences (according to the model's padding side and padding index)
|
253 |
+
among:
|
254 |
+
* :obj:`True` or :obj:`'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
|
255 |
+
sequence if provided).
|
256 |
+
* :obj:`'max_length'`: Pad to a maximum length specified with the argument :obj:`max_length` or to the
|
257 |
+
maximum acceptable input length for the model if that argument is not provided.
|
258 |
+
* :obj:`False` or :obj:`'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of
|
259 |
+
different lengths).
|
260 |
+
max_length (:obj:`int`, `optional`):
|
261 |
+
Maximum length of the ``input_values`` of the returned list and optionally padding length (see above).
|
262 |
+
max_length_labels (:obj:`int`, `optional`):
|
263 |
+
Maximum length of the ``labels`` returned list and optionally padding length (see above).
|
264 |
+
pad_to_multiple_of (:obj:`int`, `optional`):
|
265 |
+
If set will pad the sequence to a multiple of the provided value.
|
266 |
+
This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability >=
|
267 |
+
7.5 (Volta).
|
268 |
+
"""
|
269 |
+
|
270 |
+
processor: AutoProcessor
|
271 |
+
padding: Union[bool, str] = "longest"
|
272 |
+
pad_to_multiple_of: Optional[int] = None
|
273 |
+
pad_to_multiple_of_labels: Optional[int] = None
|
274 |
+
|
275 |
+
def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:
|
276 |
+
# split inputs and labels since they have to be of different lenghts and need
|
277 |
+
# different padding methods
|
278 |
+
input_features = [{"input_values": feature["input_values"]} for feature in features]
|
279 |
+
label_features = [{"input_ids": feature["labels"]} for feature in features]
|
280 |
+
|
281 |
+
batch = self.processor.pad(
|
282 |
+
input_features,
|
283 |
+
padding=self.padding,
|
284 |
+
pad_to_multiple_of=self.pad_to_multiple_of,
|
285 |
+
return_tensors="pt",
|
286 |
+
)
|
287 |
+
|
288 |
+
with self.processor.as_target_processor():
|
289 |
+
labels_batch = self.processor.pad(
|
290 |
+
label_features,
|
291 |
+
padding=self.padding,
|
292 |
+
pad_to_multiple_of=self.pad_to_multiple_of_labels,
|
293 |
+
return_tensors="pt",
|
294 |
+
)
|
295 |
+
|
296 |
+
# replace padding with -100 to ignore loss correctly
|
297 |
+
labels = labels_batch["input_ids"].masked_fill(labels_batch.attention_mask.ne(1), -100)
|
298 |
+
|
299 |
+
batch["labels"] = labels
|
300 |
+
|
301 |
+
return batch
|
302 |
+
|
303 |
+
|
304 |
+
def create_vocabulary_from_data(
|
305 |
+
datasets: DatasetDict,
|
306 |
+
word_delimiter_token: Optional[str] = None,
|
307 |
+
unk_token: Optional[str] = None,
|
308 |
+
pad_token: Optional[str] = None,
|
309 |
+
):
|
310 |
+
# Given training and test labels create vocabulary
|
311 |
+
def extract_all_chars(batch):
|
312 |
+
all_text = " ".join(batch["target_text"])
|
313 |
+
vocab = list(set(all_text))
|
314 |
+
return {"vocab": [vocab], "all_text": [all_text]}
|
315 |
+
|
316 |
+
vocabs = datasets.map(
|
317 |
+
extract_all_chars,
|
318 |
+
batched=True,
|
319 |
+
batch_size=-1,
|
320 |
+
keep_in_memory=True,
|
321 |
+
remove_columns=datasets["train"].column_names,
|
322 |
+
)
|
323 |
+
|
324 |
+
# take union of all unique characters in each dataset
|
325 |
+
vocab_set = functools.reduce(
|
326 |
+
lambda vocab_1, vocab_2: set(vocab_1["vocab"][0]) | set(vocab_2["vocab"][0]), vocabs.values()
|
327 |
+
)
|
328 |
+
|
329 |
+
vocab_dict = {v: k for k, v in enumerate(sorted(list(set(vocab_set))))}
|
330 |
+
print(vocab_set,len(vocab_set),type(vocab_set),vocab_dict)
|
331 |
+
# replace white space with delimiter token
|
332 |
+
if word_delimiter_token is not None:
|
333 |
+
vocab_dict[word_delimiter_token] = vocab_dict[" "]
|
334 |
+
del vocab_dict[" "]
|
335 |
+
|
336 |
+
# add unk and pad token
|
337 |
+
if unk_token is not None:
|
338 |
+
vocab_dict[unk_token] = len(vocab_dict)
|
339 |
+
|
340 |
+
if pad_token is not None:
|
341 |
+
vocab_dict[pad_token] = len(vocab_dict)
|
342 |
+
|
343 |
+
print(vocab_dict)
|
344 |
+
return vocab_dict
|
345 |
+
|
346 |
+
|
347 |
+
def main():
|
348 |
+
# See all possible arguments in src/transformers/training_args.py
|
349 |
+
# or by passing the --help flag to this script.
|
350 |
+
# We now keep distinct sets of args, for a cleaner separation of concerns.
|
351 |
+
|
352 |
+
parser = HfArgumentParser((ModelArguments, DataTrainingArguments, TrainingArguments))
|
353 |
+
if len(sys.argv) == 2 and sys.argv[1].endswith(".json"):
|
354 |
+
# If we pass only one argument to the script and it's the path to a json file,
|
355 |
+
# let's parse it to get our arguments.
|
356 |
+
model_args, data_args, training_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1]))
|
357 |
+
else:
|
358 |
+
model_args, data_args, training_args = parser.parse_args_into_dataclasses()
|
359 |
+
|
360 |
+
# Detecting last checkpoint.
|
361 |
+
last_checkpoint = None
|
362 |
+
if os.path.isdir(training_args.output_dir) and training_args.do_train and not training_args.overwrite_output_dir:
|
363 |
+
last_checkpoint = get_last_checkpoint(training_args.output_dir)
|
364 |
+
if last_checkpoint is None and len(os.listdir(training_args.output_dir)) > 0:
|
365 |
+
raise ValueError(
|
366 |
+
f"Output directory ({training_args.output_dir}) already exists and is not empty. "
|
367 |
+
"Use --overwrite_output_dir to overcome."
|
368 |
+
)
|
369 |
+
elif last_checkpoint is not None:
|
370 |
+
logger.info(
|
371 |
+
f"Checkpoint detected, resuming training at {last_checkpoint}. To avoid this behavior, change "
|
372 |
+
"the `--output_dir` or add `--overwrite_output_dir` to train from scratch."
|
373 |
+
)
|
374 |
+
|
375 |
+
# Setup logging
|
376 |
+
logging.basicConfig(
|
377 |
+
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
|
378 |
+
datefmt="%m/%d/%Y %H:%M:%S",
|
379 |
+
handlers=[logging.StreamHandler(sys.stdout)],
|
380 |
+
)
|
381 |
+
logger.setLevel(logging.INFO if is_main_process(training_args.local_rank) else logging.WARN)
|
382 |
+
|
383 |
+
# Log on each process the small summary:
|
384 |
+
logger.warning(
|
385 |
+
f"Process rank: {training_args.local_rank}, device: {training_args.device}, n_gpu: {training_args.n_gpu}"
|
386 |
+
f"distributed training: {bool(training_args.local_rank != -1)}, 16-bits training: {training_args.fp16}"
|
387 |
+
)
|
388 |
+
# Set the verbosity to info of the Transformers logger (on main process only):
|
389 |
+
if is_main_process(training_args.local_rank):
|
390 |
+
transformers.utils.logging.set_verbosity_info()
|
391 |
+
logger.info("Training/evaluation parameters %s", training_args)
|
392 |
+
|
393 |
+
# Set seed before initializing model.
|
394 |
+
set_seed(training_args.seed)
|
395 |
+
|
396 |
+
# 1. First, let's load the dataset
|
397 |
+
raw_datasets = DatasetDict()
|
398 |
+
|
399 |
+
if training_args.do_train:
|
400 |
+
raw_datasets["train"] = load_dataset(
|
401 |
+
data_args.dataset_name,
|
402 |
+
data_args.dataset_config_name,
|
403 |
+
split=data_args.train_split_name,
|
404 |
+
use_auth_token=data_args.use_auth_token,
|
405 |
+
)
|
406 |
+
|
407 |
+
if data_args.audio_column_name not in raw_datasets["train"].column_names:
|
408 |
+
raise ValueError(
|
409 |
+
f"--audio_column_name '{data_args.audio_column_name}' not found in dataset '{data_args.dataset_name}'. "
|
410 |
+
"Make sure to set `--audio_column_name` to the correct audio column - one of "
|
411 |
+
f"{', '.join(raw_datasets['train'].column_names)}."
|
412 |
+
)
|
413 |
+
|
414 |
+
if data_args.text_column_name not in raw_datasets["train"].column_names:
|
415 |
+
raise ValueError(
|
416 |
+
f"--text_column_name {data_args.text_column_name} not found in dataset '{data_args.dataset_name}'. "
|
417 |
+
"Make sure to set `--text_column_name` to the correct text column - one of "
|
418 |
+
f"{', '.join(raw_datasets['train'].column_names)}."
|
419 |
+
)
|
420 |
+
|
421 |
+
if data_args.max_train_samples is not None:
|
422 |
+
raw_datasets["train"] = raw_datasets["train"].select(range(data_args.max_train_samples))
|
423 |
+
|
424 |
+
if training_args.do_eval:
|
425 |
+
raw_datasets["eval"] = load_dataset(
|
426 |
+
data_args.dataset_name,
|
427 |
+
data_args.dataset_config_name,
|
428 |
+
split=data_args.eval_split_name,
|
429 |
+
use_auth_token=data_args.use_auth_token,
|
430 |
+
)
|
431 |
+
|
432 |
+
if data_args.max_eval_samples is not None:
|
433 |
+
raw_datasets["eval"] = raw_datasets["eval"].select(range(data_args.max_eval_samples))
|
434 |
+
|
435 |
+
# 2. We remove some special characters from the datasets
|
436 |
+
# that make training complicated and do not help in transcribing the speech
|
437 |
+
# E.g. characters, such as `,` and `.` do not really have an acoustic characteristic
|
438 |
+
# that could be easily picked up by the model
|
439 |
+
# chars_to_ignore_regex = (
|
440 |
+
# f'[{"".join(data_args.chars_to_ignore)}]' if data_args.chars_to_ignore is not None else None
|
441 |
+
# )
|
442 |
+
chars_to_ignore_regex = '[,?.!\-\;\:"“%‘”�—’…–]'
|
443 |
+
text_column_name = data_args.text_column_name
|
444 |
+
|
445 |
+
|
446 |
+
def replace_text(text):
|
447 |
+
text=text.replace('„', r'"')
|
448 |
+
text=text.replace('“', r'"')
|
449 |
+
text=text.replace('”', r'"')
|
450 |
+
text=text.replace('–', r'-')
|
451 |
+
text=text.replace('—', r' - ')
|
452 |
+
text=text.replace('´', r"'")
|
453 |
+
text=text.replace('‘', r"'")
|
454 |
+
text=text.replace('‚', r"'")
|
455 |
+
text=text.replace('’', r"'")
|
456 |
+
text=text.replace("''", r'"')
|
457 |
+
text=text.replace('´´', r'"')
|
458 |
+
|
459 |
+
token_sequences_to_ignore = ["\n\n", "\n", " ", " "]
|
460 |
+
for t in token_sequences_to_ignore:
|
461 |
+
text = " ".join(text.split(t))
|
462 |
+
return text
|
463 |
+
|
464 |
+
def remove_special_characters(batch):
|
465 |
+
text=batch[text_column_name]
|
466 |
+
text=replace_text(text)
|
467 |
+
|
468 |
+
|
469 |
+
if chars_to_ignore_regex is not None:
|
470 |
+
target_text = re.sub(chars_to_ignore_regex, "", text).lower() + " "
|
471 |
+
else:
|
472 |
+
target_text = text.lower() + " "
|
473 |
+
|
474 |
+
batch["target_text"]=target_text
|
475 |
+
return batch
|
476 |
+
|
477 |
+
with training_args.main_process_first(desc="dataset map special characters removal"):
|
478 |
+
raw_datasets = raw_datasets.map(
|
479 |
+
remove_special_characters,
|
480 |
+
remove_columns=[text_column_name],
|
481 |
+
desc="remove special characters from datasets",
|
482 |
+
)
|
483 |
+
|
484 |
+
# save special tokens for tokenizer
|
485 |
+
word_delimiter_token = data_args.word_delimiter_token
|
486 |
+
unk_token = data_args.unk_token
|
487 |
+
pad_token = data_args.pad_token
|
488 |
+
|
489 |
+
# 3. Next, let's load the config as we might need it to create
|
490 |
+
# the tokenizer
|
491 |
+
# load config
|
492 |
+
config = AutoConfig.from_pretrained(
|
493 |
+
model_args.model_name_or_path, cache_dir=model_args.cache_dir, use_auth_token=data_args.use_auth_token
|
494 |
+
)
|
495 |
+
|
496 |
+
# 4. Next, if no tokenizer file is defined,
|
497 |
+
# we create the vocabulary of the model by extracting all unique characters from
|
498 |
+
# the training and evaluation datasets
|
499 |
+
# We need to make sure that only first rank saves vocabulary
|
500 |
+
# make sure all processes wait until vocab is created
|
501 |
+
tokenizer_name_or_path = model_args.tokenizer_name_or_path
|
502 |
+
tokenizer_kwargs = {}
|
503 |
+
if tokenizer_name_or_path is None:
|
504 |
+
# save vocab in training output dir
|
505 |
+
tokenizer_name_or_path = training_args.output_dir
|
506 |
+
|
507 |
+
vocab_file = os.path.join(tokenizer_name_or_path, "vocab.json")
|
508 |
+
|
509 |
+
with training_args.main_process_first():
|
510 |
+
if training_args.overwrite_output_dir and os.path.isfile(vocab_file):
|
511 |
+
os.remove(vocab_file)
|
512 |
+
|
513 |
+
with training_args.main_process_first(desc="dataset map vocabulary creation"):
|
514 |
+
if not os.path.isfile(vocab_file):
|
515 |
+
os.makedirs(tokenizer_name_or_path, exist_ok=True)
|
516 |
+
vocab_dict = create_vocabulary_from_data(
|
517 |
+
raw_datasets,
|
518 |
+
word_delimiter_token=word_delimiter_token,
|
519 |
+
unk_token=unk_token,
|
520 |
+
pad_token=pad_token,
|
521 |
+
)
|
522 |
+
|
523 |
+
# save vocab dict to be loaded into tokenizer
|
524 |
+
with open(vocab_file, "w") as file:
|
525 |
+
json.dump(vocab_dict, file)
|
526 |
+
|
527 |
+
# if tokenizer has just been created
|
528 |
+
# it is defined by `tokenizer_class` if present in config else by `model_type`
|
529 |
+
tokenizer_kwargs = {
|
530 |
+
"config": config if config.tokenizer_class is not None else None,
|
531 |
+
"tokenizer_type": config.model_type if config.tokenizer_class is None else None,
|
532 |
+
"unk_token": unk_token,
|
533 |
+
"pad_token": pad_token,
|
534 |
+
"word_delimiter_token": word_delimiter_token,
|
535 |
+
}
|
536 |
+
|
537 |
+
# 5. Now we can instantiate the feature extractor, tokenizer and model
|
538 |
+
# Note for distributed training, the .from_pretrained methods guarantee that only
|
539 |
+
# one local process can concurrently download model & vocab.
|
540 |
+
|
541 |
+
# load feature_extractor and tokenizer
|
542 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
543 |
+
tokenizer_name_or_path,
|
544 |
+
use_auth_token=data_args.use_auth_token,
|
545 |
+
**tokenizer_kwargs,
|
546 |
+
)
|
547 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(
|
548 |
+
model_args.model_name_or_path, cache_dir=model_args.cache_dir, use_auth_token=data_args.use_auth_token
|
549 |
+
)
|
550 |
+
|
551 |
+
# adapt config
|
552 |
+
config.update(
|
553 |
+
{
|
554 |
+
"feat_proj_dropout": model_args.feat_proj_dropout,
|
555 |
+
"attention_dropout": model_args.attention_dropout,
|
556 |
+
"hidden_dropout": model_args.hidden_dropout,
|
557 |
+
"final_dropout": model_args.final_dropout,
|
558 |
+
"mask_time_prob": model_args.mask_time_prob,
|
559 |
+
"mask_time_length": model_args.mask_time_length,
|
560 |
+
"mask_feature_prob": model_args.mask_feature_prob,
|
561 |
+
"mask_feature_length": model_args.mask_feature_length,
|
562 |
+
"gradient_checkpointing": training_args.gradient_checkpointing,
|
563 |
+
"layerdrop": model_args.layerdrop,
|
564 |
+
"ctc_loss_reduction": model_args.ctc_loss_reduction,
|
565 |
+
"pad_token_id": tokenizer.pad_token_id,
|
566 |
+
"vocab_size": len(tokenizer),
|
567 |
+
"activation_dropout": model_args.activation_dropout,
|
568 |
+
}
|
569 |
+
)
|
570 |
+
|
571 |
+
# create model
|
572 |
+
model = AutoModelForCTC.from_pretrained(
|
573 |
+
model_args.model_name_or_path,
|
574 |
+
cache_dir=model_args.cache_dir,
|
575 |
+
config=config,
|
576 |
+
use_auth_token=data_args.use_auth_token,
|
577 |
+
)
|
578 |
+
|
579 |
+
# freeze encoder
|
580 |
+
if model_args.freeze_feature_encoder:
|
581 |
+
model.freeze_feature_encoder()
|
582 |
+
|
583 |
+
# 6. Now we preprocess the datasets including loading the audio, resampling and normalization
|
584 |
+
# Thankfully, `datasets` takes care of automatically loading and resampling the audio,
|
585 |
+
# so that we just need to set the correct target sampling rate and normalize the input
|
586 |
+
# via the `feature_extractor`
|
587 |
+
|
588 |
+
# make sure that dataset decodes audio with correct sampling rate
|
589 |
+
dataset_sampling_rate = next(iter(raw_datasets.values())).features[data_args.audio_column_name].sampling_rate
|
590 |
+
if dataset_sampling_rate != feature_extractor.sampling_rate:
|
591 |
+
raw_datasets = raw_datasets.cast_column(
|
592 |
+
data_args.audio_column_name, datasets.features.Audio(sampling_rate=feature_extractor.sampling_rate)
|
593 |
+
)
|
594 |
+
|
595 |
+
# derive max & min input length for sample rate & max duration
|
596 |
+
max_input_length = data_args.max_duration_in_seconds * feature_extractor.sampling_rate
|
597 |
+
min_input_length = data_args.min_duration_in_seconds * feature_extractor.sampling_rate
|
598 |
+
audio_column_name = data_args.audio_column_name
|
599 |
+
num_workers = data_args.preprocessing_num_workers
|
600 |
+
|
601 |
+
# `phoneme_language` is only relevant if the model is fine-tuned on phoneme classification
|
602 |
+
phoneme_language = data_args.phoneme_language
|
603 |
+
|
604 |
+
# Preprocessing the datasets.
|
605 |
+
# We need to read the audio files as arrays and tokenize the targets.
|
606 |
+
def prepare_dataset(batch):
|
607 |
+
# load audio
|
608 |
+
sample = batch[audio_column_name]
|
609 |
+
|
610 |
+
inputs = feature_extractor(sample["array"], sampling_rate=sample["sampling_rate"])
|
611 |
+
batch["input_values"] = inputs.input_values[0]
|
612 |
+
batch["input_length"] = len(batch["input_values"])
|
613 |
+
|
614 |
+
# encode targets
|
615 |
+
additional_kwargs = {}
|
616 |
+
if phoneme_language is not None:
|
617 |
+
additional_kwargs["phonemizer_lang"] = phoneme_language
|
618 |
+
|
619 |
+
batch["labels"] = tokenizer(batch["target_text"], **additional_kwargs).input_ids
|
620 |
+
return batch
|
621 |
+
|
622 |
+
with training_args.main_process_first(desc="dataset map preprocessing"):
|
623 |
+
vectorized_datasets = raw_datasets.map(
|
624 |
+
prepare_dataset,
|
625 |
+
remove_columns=next(iter(raw_datasets.values())).column_names,
|
626 |
+
num_proc=num_workers,
|
627 |
+
desc="preprocess datasets",
|
628 |
+
)
|
629 |
+
|
630 |
+
def is_audio_in_length_range(length):
|
631 |
+
return length > min_input_length and length < max_input_length
|
632 |
+
|
633 |
+
# filter data that is shorter than min_input_length
|
634 |
+
vectorized_datasets = vectorized_datasets.filter(
|
635 |
+
is_audio_in_length_range,
|
636 |
+
num_proc=num_workers,
|
637 |
+
input_columns=["input_length"],
|
638 |
+
)
|
639 |
+
|
640 |
+
# 7. Next, we can prepare the training.
|
641 |
+
# Let's use word error rate (WER) as our evaluation metric,
|
642 |
+
# instantiate a data collator and the trainer
|
643 |
+
|
644 |
+
# Define evaluation metrics during training, *i.e.* word error rate, character error rate
|
645 |
+
eval_metrics = {metric: load_metric(metric) for metric in data_args.eval_metrics}
|
646 |
+
|
647 |
+
# for large datasets it is advised to run the preprocessing on a
|
648 |
+
# single machine first with ``args.preprocessing_only`` since there will mostly likely
|
649 |
+
# be a timeout when running the script in distributed mode.
|
650 |
+
# In a second step ``args.preprocessing_only`` can then be set to `False` to load the
|
651 |
+
# cached dataset
|
652 |
+
if data_args.preprocessing_only:
|
653 |
+
logger.info(f"Data preprocessing finished. Files cached at {vectorized_datasets.cache_files}")
|
654 |
+
return
|
655 |
+
|
656 |
+
def compute_metrics(pred):
|
657 |
+
pred_logits = pred.predictions
|
658 |
+
pred_ids = np.argmax(pred_logits, axis=-1)
|
659 |
+
|
660 |
+
pred.label_ids[pred.label_ids == -100] = tokenizer.pad_token_id
|
661 |
+
|
662 |
+
pred_str = tokenizer.batch_decode(pred_ids)
|
663 |
+
# we do not want to group tokens when computing the metrics
|
664 |
+
label_str = tokenizer.batch_decode(pred.label_ids, group_tokens=False)
|
665 |
+
|
666 |
+
metrics = {k: v.compute(predictions=pred_str, references=label_str) for k, v in eval_metrics.items()}
|
667 |
+
|
668 |
+
return metrics
|
669 |
+
|
670 |
+
# Now save everything to be able to create a single processor later
|
671 |
+
if is_main_process(training_args.local_rank):
|
672 |
+
# save feature extractor, tokenizer and config
|
673 |
+
feature_extractor.save_pretrained(training_args.output_dir)
|
674 |
+
tokenizer.save_pretrained(training_args.output_dir)
|
675 |
+
config.save_pretrained(training_args.output_dir)
|
676 |
+
|
677 |
+
try:
|
678 |
+
processor = AutoProcessor.from_pretrained(training_args.output_dir)
|
679 |
+
except (OSError, KeyError):
|
680 |
+
warnings.warn(
|
681 |
+
"Loading a processor from a feature extractor config that does not"
|
682 |
+
" include a `processor_class` attribute is deprecated and will be removed in v5. Please add the following "
|
683 |
+
" attribute to your `preprocessor_config.json` file to suppress this warning: "
|
684 |
+
" `'processor_class': 'Wav2Vec2Processor'`",
|
685 |
+
FutureWarning,
|
686 |
+
)
|
687 |
+
processor = Wav2Vec2Processor.from_pretrained(training_args.output_dir)
|
688 |
+
|
689 |
+
# Instantiate custom data collator
|
690 |
+
data_collator = DataCollatorCTCWithPadding(processor=processor)
|
691 |
+
|
692 |
+
# Initialize Trainer
|
693 |
+
trainer = Trainer(
|
694 |
+
model=model,
|
695 |
+
data_collator=data_collator,
|
696 |
+
args=training_args,
|
697 |
+
compute_metrics=compute_metrics,
|
698 |
+
train_dataset=vectorized_datasets["train"] if training_args.do_train else None,
|
699 |
+
eval_dataset=vectorized_datasets["eval"] if training_args.do_eval else None,
|
700 |
+
tokenizer=feature_extractor,
|
701 |
+
)
|
702 |
+
|
703 |
+
# 8. Finally, we can start training
|
704 |
+
|
705 |
+
# Training
|
706 |
+
if training_args.do_train:
|
707 |
+
|
708 |
+
# use last checkpoint if exist
|
709 |
+
if last_checkpoint is not None:
|
710 |
+
checkpoint = last_checkpoint
|
711 |
+
elif os.path.isdir(model_args.model_name_or_path):
|
712 |
+
checkpoint = model_args.model_name_or_path
|
713 |
+
else:
|
714 |
+
checkpoint = None
|
715 |
+
|
716 |
+
train_result = trainer.train(resume_from_checkpoint=checkpoint)
|
717 |
+
trainer.save_model()
|
718 |
+
|
719 |
+
metrics = train_result.metrics
|
720 |
+
max_train_samples = (
|
721 |
+
data_args.max_train_samples
|
722 |
+
if data_args.max_train_samples is not None
|
723 |
+
else len(vectorized_datasets["train"])
|
724 |
+
)
|
725 |
+
metrics["train_samples"] = min(max_train_samples, len(vectorized_datasets["train"]))
|
726 |
+
|
727 |
+
trainer.log_metrics("train", metrics)
|
728 |
+
trainer.save_metrics("train", metrics)
|
729 |
+
trainer.save_state()
|
730 |
+
|
731 |
+
# Evaluation
|
732 |
+
results = {}
|
733 |
+
if training_args.do_eval:
|
734 |
+
logger.info("*** Evaluate ***")
|
735 |
+
metrics = trainer.evaluate()
|
736 |
+
max_eval_samples = (
|
737 |
+
data_args.max_eval_samples if data_args.max_eval_samples is not None else len(vectorized_datasets["eval"])
|
738 |
+
)
|
739 |
+
metrics["eval_samples"] = min(max_eval_samples, len(vectorized_datasets["eval"]))
|
740 |
+
|
741 |
+
trainer.log_metrics("eval", metrics)
|
742 |
+
trainer.save_metrics("eval", metrics)
|
743 |
+
|
744 |
+
# Write model card and (optionally) push to hub
|
745 |
+
config_name = data_args.dataset_config_name if data_args.dataset_config_name is not None else "na"
|
746 |
+
kwargs = {
|
747 |
+
"finetuned_from": model_args.model_name_or_path,
|
748 |
+
"tasks": "speech-recognition",
|
749 |
+
"tags": ["automatic-speech-recognition", data_args.dataset_name,"robust-speech-event"],
|
750 |
+
"dataset_args": f"Config: {config_name}, Training split: {data_args.train_split_name}, Eval split: {data_args.eval_split_name}",
|
751 |
+
"dataset": f"{data_args.dataset_name.upper()} - {config_name.upper()}",
|
752 |
+
}
|
753 |
+
if "common_voice" in data_args.dataset_name:
|
754 |
+
kwargs["language"] = config_name
|
755 |
+
|
756 |
+
if training_args.push_to_hub:
|
757 |
+
trainer.push_to_hub(**kwargs)
|
758 |
+
else:
|
759 |
+
trainer.create_model_card(**kwargs)
|
760 |
+
|
761 |
+
return results
|
762 |
+
|
763 |
+
|
764 |
+
if __name__ == "__main__":
|
765 |
+
main()
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "[UNK]", "pad_token": "[PAD]", "additional_special_tokens": [{"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}]}
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "bos_token": "<s>", "eos_token": "</s>", "pad_token": "[PAD]", "do_lower_case": false, "word_delimiter_token": "$", "special_tokens_map_file": null, "tokenizer_file": null, "name_or_path": "./", "tokenizer_class": "Wav2Vec2CTCTokenizer"}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1b14a8f9f8277105473cbf033c9a27c340ba9432e25e5aaa2aef3d10c81d85e9
|
3 |
+
size 2991
|
vocab.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"&": 1, "'": 2, "a": 3, "b": 4, "c": 5, "d": 6, "e": 7, "f": 8, "g": 9, "h": 10, "i": 11, "j": 12, "k": 13, "l": 14, "m": 15, "n": 16, "o": 17, "p": 18, "r": 19, "s": 20, "t": 21, "u": 22, "v": 23, "w": 24, "x": 25, "y": 26, "z": 27, "|": 28, "ँ": 29, "ं": 30, "ः": 31, "अ": 32, "आ": 33, "इ": 34, "ई": 35, "उ": 36, "ऊ": 37, "ऋ": 38, "ए": 39, "ऐ": 40, "ऑ": 41, "ओ": 42, "औ": 43, "क": 44, "ख": 45, "ग": 46, "घ": 47, "च": 48, "छ": 49, "ज": 50, "झ": 51, "ञ": 52, "ट": 53, "ठ": 54, "ड": 55, "ढ": 56, "ण": 57, "त": 58, "थ": 59, "द": 60, "ध": 61, "न": 62, "प": 63, "फ": 64, "ब": 65, "भ": 66, "म": 67, "य": 68, "र": 69, "ल": 70, "व": 71, "श": 72, "ष": 73, "स": 74, "ह": 75, "़": 76, "ा": 77, "ि": 78, "ी": 79, "ु": 80, "ू": 81, "ृ": 82, "ॅ": 83, "े": 84, "ै": 85, "ॉ": 86, "ो": 87, "ौ": 88, "्": 89, "क़": 90, "ग़": 91, "ज़": 92, "ड़": 93, "ढ़": 94, "।": 95, "$": 0, "[UNK]": 96, "[PAD]": 97}
|