Commit
•
b3bfd4e
1
Parent(s):
a83c2f3
up
Browse files- config.json +264 -0
- create_model.py +41 -0
- flax_model.msgpack +3 -0
- merges.txt +0 -0
- preprocessor_config.json +9 -0
- run_flax_speech_recognition_seq2seq.py +1 -0
- run_librispeech.sh +29 -0
- special_tokens_map.json +1 -0
- tokenizer_config.json +1 -0
- vocab.json +0 -0
config.json
ADDED
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"SpeechEncoderDecoderModel"
|
4 |
+
],
|
5 |
+
"decoder": {
|
6 |
+
"_name_or_path": "gpt2-medium",
|
7 |
+
"activation_function": "gelu_new",
|
8 |
+
"add_cross_attention": true,
|
9 |
+
"architectures": [
|
10 |
+
"GPT2LMHeadModel"
|
11 |
+
],
|
12 |
+
"attn_pdrop": 0.1,
|
13 |
+
"bad_words_ids": null,
|
14 |
+
"bos_token_id": 50256,
|
15 |
+
"chunk_size_feed_forward": 0,
|
16 |
+
"cross_attention_hidden_size": null,
|
17 |
+
"decoder_start_token_id": null,
|
18 |
+
"diversity_penalty": 0.0,
|
19 |
+
"do_sample": false,
|
20 |
+
"early_stopping": false,
|
21 |
+
"embd_pdrop": 0.1,
|
22 |
+
"encoder_no_repeat_ngram_size": 0,
|
23 |
+
"eos_token_id": 50256,
|
24 |
+
"finetuning_task": null,
|
25 |
+
"forced_bos_token_id": null,
|
26 |
+
"forced_eos_token_id": null,
|
27 |
+
"id2label": {
|
28 |
+
"0": "LABEL_0",
|
29 |
+
"1": "LABEL_1"
|
30 |
+
},
|
31 |
+
"initializer_range": 0.02,
|
32 |
+
"is_decoder": true,
|
33 |
+
"is_encoder_decoder": false,
|
34 |
+
"label2id": {
|
35 |
+
"LABEL_0": 0,
|
36 |
+
"LABEL_1": 1
|
37 |
+
},
|
38 |
+
"layer_norm_epsilon": 1e-05,
|
39 |
+
"length_penalty": 1.0,
|
40 |
+
"max_length": 20,
|
41 |
+
"min_length": 0,
|
42 |
+
"model_type": "gpt2",
|
43 |
+
"n_ctx": 1024,
|
44 |
+
"n_embd": 1024,
|
45 |
+
"n_head": 16,
|
46 |
+
"n_inner": null,
|
47 |
+
"n_layer": 24,
|
48 |
+
"n_positions": 1024,
|
49 |
+
"n_special": 0,
|
50 |
+
"no_repeat_ngram_size": 0,
|
51 |
+
"num_beam_groups": 1,
|
52 |
+
"num_beams": 1,
|
53 |
+
"num_return_sequences": 1,
|
54 |
+
"output_attentions": false,
|
55 |
+
"output_hidden_states": false,
|
56 |
+
"output_scores": false,
|
57 |
+
"pad_token_id": null,
|
58 |
+
"predict_special_tokens": true,
|
59 |
+
"prefix": null,
|
60 |
+
"problem_type": null,
|
61 |
+
"pruned_heads": {},
|
62 |
+
"remove_invalid_values": false,
|
63 |
+
"reorder_and_upcast_attn": false,
|
64 |
+
"repetition_penalty": 1.0,
|
65 |
+
"resid_pdrop": 0.1,
|
66 |
+
"return_dict": true,
|
67 |
+
"return_dict_in_generate": false,
|
68 |
+
"scale_attn_by_inverse_layer_idx": false,
|
69 |
+
"scale_attn_weights": true,
|
70 |
+
"sep_token_id": null,
|
71 |
+
"summary_activation": null,
|
72 |
+
"summary_first_dropout": 0.1,
|
73 |
+
"summary_proj_to_labels": true,
|
74 |
+
"summary_type": "cls_index",
|
75 |
+
"summary_use_proj": true,
|
76 |
+
"task_specific_params": {
|
77 |
+
"text-generation": {
|
78 |
+
"do_sample": true,
|
79 |
+
"max_length": 50
|
80 |
+
}
|
81 |
+
},
|
82 |
+
"temperature": 1.0,
|
83 |
+
"tie_encoder_decoder": false,
|
84 |
+
"tie_word_embeddings": true,
|
85 |
+
"tokenizer_class": null,
|
86 |
+
"top_k": 50,
|
87 |
+
"top_p": 1.0,
|
88 |
+
"torch_dtype": null,
|
89 |
+
"torchscript": false,
|
90 |
+
"transformers_version": "4.18.0.dev0",
|
91 |
+
"typical_p": 1.0,
|
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.1,
|
100 |
+
"adapter_kernel_size": 3,
|
101 |
+
"adapter_stride": 2,
|
102 |
+
"add_adapter": true,
|
103 |
+
"add_cross_attention": false,
|
104 |
+
"apply_spec_augment": true,
|
105 |
+
"architectures": [
|
106 |
+
"Wav2Vec2ForPreTraining"
|
107 |
+
],
|
108 |
+
"attention_dropout": 0.1,
|
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.1,
|
166 |
+
"hidden_dropout_prob": 0.1,
|
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.1,
|
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.18.0.dev0",
|
250 |
+
"typical_p": 1.0,
|
251 |
+
"use_bfloat16": false,
|
252 |
+
"use_weighted_layer_sum": false,
|
253 |
+
"vocab_size": 32,
|
254 |
+
"xvector_output_dim": 512
|
255 |
+
},
|
256 |
+
"eos_token_id": 50256,
|
257 |
+
"is_encoder_decoder": true,
|
258 |
+
"max_length": 50,
|
259 |
+
"model_type": "speech-encoder-decoder",
|
260 |
+
"pad_token_id": 50256,
|
261 |
+
"processor_class": "Wav2Vec2Processor",
|
262 |
+
"transformers_version": null,
|
263 |
+
"use_cache": false
|
264 |
+
}
|
create_model.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from transformers import AutoFeatureExtractor, AutoTokenizer, FlaxSpeechEncoderDecoderModel, GPT2Tokenizer
|
3 |
+
|
4 |
+
encoder_id = "facebook/wav2vec2-large-lv60"
|
5 |
+
decoder_id = "gpt2-medium"
|
6 |
+
|
7 |
+
model = FlaxSpeechEncoderDecoderModel.from_encoder_decoder_pretrained(encoder_id, decoder_id, encoder_add_adapter=True)
|
8 |
+
|
9 |
+
# force GPT2 to append EOS to begin and end of seq
|
10 |
+
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
|
11 |
+
outputs = [self.bos_token_id] + token_ids_0 + [self.eos_token_id]
|
12 |
+
return outputs
|
13 |
+
|
14 |
+
GPT2Tokenizer.build_inputs_with_special_tokens = build_inputs_with_special_tokens
|
15 |
+
gpt2_tokenizer = GPT2Tokenizer.from_pretrained(decoder_id)
|
16 |
+
# set pad_token_id to unk_token_id, note: unk_token_id == eos_token_id == bos_token_id
|
17 |
+
gpt2_tokenizer.pad_token = gpt2_tokenizer.unk_token
|
18 |
+
gpt2_tokenizer.save_pretrained("./")
|
19 |
+
|
20 |
+
model.config.pad_token_id = gpt2_tokenizer.pad_token_id
|
21 |
+
model.config.decoder_start_token_id = model.config.decoder.bos_token_id
|
22 |
+
model.config.eos_token_id = model.config.decoder.eos_token_id
|
23 |
+
model.config.max_length = 50
|
24 |
+
model.config.num_beams = 1
|
25 |
+
|
26 |
+
# same enc regularisation as wav2vec2-2-bart
|
27 |
+
model.config.encoder.feat_proj_dropout = 0.0
|
28 |
+
model.config.encoder.final_dropout = 0.0
|
29 |
+
model.config.encoder.mask_time_prob = 0.1
|
30 |
+
|
31 |
+
model.config.use_cache = False
|
32 |
+
model.config.decoder.use_cache = False
|
33 |
+
model.config.processor_class = "Wav2Vec2Processor"
|
34 |
+
|
35 |
+
# check if generation works
|
36 |
+
out = model.generate(np.ones((1, 2000)))
|
37 |
+
|
38 |
+
model.save_pretrained("./")
|
39 |
+
|
40 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(encoder_id)
|
41 |
+
feature_extractor.save_pretrained("./")
|
flax_model.msgpack
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:240e5d0555dce67f7eb5f3d95f29de05de215e913ea754d408ac72d91b1f95b7
|
3 |
+
size 3159844591
|
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 |
+
}
|
run_flax_speech_recognition_seq2seq.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
/home/sanchitgandhi/transformers/examples/flax/speech-recognition/run_flax_speech_recognition_seq2seq.py
|
run_librispeech.sh
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env bash
|
2 |
+
JAX_DEFAULT_MATMUL_PRECISION=float32 python run_flax_speech_recognition_seq2seq.py \
|
3 |
+
--dataset_name="librispeech_asr" \
|
4 |
+
--model_name_or_path="./" \
|
5 |
+
--dataset_config_name="clean" \
|
6 |
+
--train_split_name="train.100[:5%]" \
|
7 |
+
--eval_split_name="validation[:5%]" \
|
8 |
+
--output_dir="./" \
|
9 |
+
--preprocessing_num_workers="16" \
|
10 |
+
--length_column_name="input_length" \
|
11 |
+
--overwrite_output_dir \
|
12 |
+
--num_train_epochs="1" \
|
13 |
+
--per_device_train_batch_size="1" \
|
14 |
+
--per_device_eval_batch_size="1" \
|
15 |
+
--logging_steps="1" \
|
16 |
+
--max_duration_in_seconds="10" \
|
17 |
+
--max_target_length="32" \
|
18 |
+
--generation_max_length="40" \
|
19 |
+
--generation_num_beams="1" \
|
20 |
+
--learning_rate="3e-4" \
|
21 |
+
--warmup_steps="500" \
|
22 |
+
--text_column_name="text" \
|
23 |
+
--save_total_limit="1" \
|
24 |
+
--freeze_feature_encoder \
|
25 |
+
--predict_with_generate \
|
26 |
+
--do_lower_case \
|
27 |
+
--do_eval --do_train \
|
28 |
+
--push_to_hub \
|
29 |
+
--use_auth_token
|
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_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"errors": "replace", "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, "model_max_length": 1024, "special_tokens_map_file": null, "name_or_path": "gpt2-medium", "tokenizer_class": "GPT2Tokenizer"}
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|