sanchit-gandhi HF staff commited on
Commit
c09faa6
1 Parent(s): 6a89764
create_model.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import jax.numpy as jnp
2
+ from transformers import AutoFeatureExtractor, AutoTokenizer, FlaxSpeechEncoderDecoderModel
3
+
4
+ encoder_id = "facebook/wav2vec2-large-lv60"
5
+ decoder_id = "facebook/bart-large-cnn"
6
+
7
+ model = FlaxSpeechEncoderDecoderModel.from_encoder_decoder_pretrained(encoder_id, decoder_id, encoder_add_adapter=True, decoder_from_pt=True)
8
+
9
+ model.config.encoder.feat_proj_dropout = 0.0
10
+ model.config.encoder.final_dropout = 0.0
11
+ model.config.encoder.mask_time_prob = 0.1
12
+ model.config.decoder_start_token_id = model.config.decoder.bos_token_id
13
+ model.config.pad_token_id = model.config.decoder.pad_token_id
14
+ model.config.eos_token_id = model.config.decoder.eos_token_id
15
+ model.config.max_length = 40
16
+ model.config.num_beams = 1
17
+ model.config.encoder.layerdrop = 0.0
18
+ model.config.use_cache = False
19
+ model.config.processor_class = "Wav2Vec2Processor"
20
+
21
+ # check if generation works
22
+ out = model.generate(jnp.ones((1, 2000)))
23
+
24
+ model.save_pretrained("./")
25
+
26
+ feature_extractor = AutoFeatureExtractor.from_pretrained(encoder_id)
27
+ feature_extractor.save_pretrained("./")
28
+ tokenizer = AutoTokenizer.from_pretrained(decoder_id)
29
+ tokenizer.save_pretrained("./")
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,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ 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" \
7
+ --eval_split_name="validation" \
8
+ --dataset_cache_dir="~/cache/huggingface/datasets" \
9
+ --output_dir="./" \
10
+ --preprocessing_num_workers="16" \
11
+ --length_column_name="input_length" \
12
+ --overwrite_output_dir \
13
+ --num_train_epochs="15" \
14
+ --per_device_train_batch_size="2" \
15
+ --per_device_eval_batch_size="2" \
16
+ --gradient_accumulation_steps="1" \
17
+ --logging_steps="25" \
18
+ --max_duration_in_seconds="15" \
19
+ --max_target_length="64" \
20
+ --generation_max_length="40" \
21
+ --generation_num_beams="1" \
22
+ --learning_rate="3e-4" \
23
+ --warmup_steps="500" \
24
+ --text_column_name="text" \
25
+ --save_total_limit="1" \
26
+ --freeze_feature_encoder \
27
+ --predict_with_generate \
28
+ --do_lower_case \
29
+ --do_eval \
30
+ --do_train \
31
+ --push_to_hub \
32
+ --use_auth_token \
33
+ --wandb_project="flax-wav2vec2-2-bart-large-cnn"
34
+