m3hrdadfi commited on
Commit
6a6f772
1 Parent(s): bab2747

Prepare the runner

Browse files
config.json ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation_dropout": 0.0,
3
+ "apply_spec_augment": true,
4
+ "architectures": [
5
+ "Wav2Vec2ForPreTraining"
6
+ ],
7
+ "attention_dropout": 0.1,
8
+ "bos_token_id": 1,
9
+ "codevector_dim": 256,
10
+ "contrastive_logits_temperature": 0.1,
11
+ "conv_bias": false,
12
+ "conv_dim": [
13
+ 512,
14
+ 512,
15
+ 512,
16
+ 512,
17
+ 512,
18
+ 512,
19
+ 512
20
+ ],
21
+ "conv_kernel": [
22
+ 10,
23
+ 3,
24
+ 3,
25
+ 3,
26
+ 3,
27
+ 2,
28
+ 2
29
+ ],
30
+ "conv_stride": [
31
+ 5,
32
+ 2,
33
+ 2,
34
+ 2,
35
+ 2,
36
+ 2,
37
+ 2
38
+ ],
39
+ "ctc_loss_reduction": "sum",
40
+ "ctc_zero_infinity": false,
41
+ "diversity_loss_weight": 0.1,
42
+ "do_stable_layer_norm": true,
43
+ "eos_token_id": 2,
44
+ "feat_extract_activation": "gelu",
45
+ "feat_extract_norm": "layer",
46
+ "feat_proj_dropout": 0.1,
47
+ "feat_quantizer_dropout": 0.0,
48
+ "final_dropout": 0.0,
49
+ "freeze_feat_extract_train": true,
50
+ "gradient_checkpointing": true,
51
+ "hidden_act": "gelu",
52
+ "hidden_dropout": 0.1,
53
+ "hidden_size": 768,
54
+ "initializer_range": 0.02,
55
+ "intermediate_size": 3072,
56
+ "layer_norm_eps": 1e-05,
57
+ "layerdrop": 0.05,
58
+ "mask_channel_length": 10,
59
+ "mask_channel_min_space": 1,
60
+ "mask_channel_other": 0.0,
61
+ "mask_channel_prob": 0.0,
62
+ "mask_channel_selection": "static",
63
+ "mask_feature_length": 10,
64
+ "mask_feature_prob": 0.0,
65
+ "mask_time_length": 10,
66
+ "mask_time_min_space": 1,
67
+ "mask_time_other": 0.0,
68
+ "mask_time_prob": 0.05,
69
+ "mask_time_selection": "static",
70
+ "model_type": "wav2vec2",
71
+ "no_mask_channel_overlap": false,
72
+ "no_mask_time_overlap": false,
73
+ "num_attention_heads": 12,
74
+ "num_codevector_groups": 2,
75
+ "num_codevectors_per_group": 320,
76
+ "num_conv_pos_embedding_groups": 16,
77
+ "num_conv_pos_embeddings": 128,
78
+ "num_feat_extract_layers": 7,
79
+ "num_hidden_layers": 12,
80
+ "num_negatives": 100,
81
+ "pad_token_id": 0,
82
+ "proj_codevector_dim": 256,
83
+ "transformers_version": "4.9.0.dev0",
84
+ "vocab_size": 40
85
+ }
notes/data_preparation_pt.ipynb CHANGED
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
+ }
src/run_config.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ export LC_ALL=C.UTF-8
3
+ export LANG=C.UTF-8
4
+
5
+
6
+ # export OUTPUT_DIR=./
7
+ export OUTPUT_DIR=/home/m3hrdadfi/code/wav2vec2-base-persian
8
+ export NAME_OR_PATH=facebook/wav2vec2-base
9
+
10
+
11
+ python src/run_config.py \
12
+ --output_dir="$OUTPUT_DIR" \
13
+ --name_or_path="$NAME_OR_PATH"
src/run_persian.sh CHANGED
@@ -4,22 +4,23 @@ export LC_ALL=C.UTF-8
4
  export LANG=C.UTF-8
5
 
6
  export OUTPUT_DIR=/home/m3hrdadfi/code/wav2vec2-base-persian
 
7
  export MODEL_NAME_OR_PATH=/home/m3hrdadfi/code/wav2vec2-base-persian
8
 
9
 
10
- export TRAIN_FILE=/home/m3hrdadfi/code/data/train.csv
11
- export VALIDATION_FILE=/home/m3hrdadfi/code/data/test.csv
12
  export SPEECH_FILE_COLUMN=path
13
 
14
 
15
  #export MAX_EVAL_SAMPLES=5000
16
- export PER_DEVICE_TRAIN_BATCH_SIZE=32
17
- export PER_DEVICE_EVAL_BATCH_SIZE=32
18
  #export GRADIENT_ACCUMULATION_STEPS=2
19
  export NUM_TRAIN_EPOCHS=5.0
20
  export LEARNING_RATE=5e-4
21
  export WARMUP_STEPS=1000
22
- #export LOGGING_STEPS=500
23
  #export EVAL_STEPS=2500
24
  #export SAVE_STEPS=2500
25
  export PREPROCESSING_NUM_WORKERS=4
@@ -32,6 +33,7 @@ export PAD_TO_MULTIPLE_OF=16384
32
 
33
  python src/run_wav2vec2_pretrain_flax.py \
34
  --output_dir="$OUTPUT_DIR" \
 
35
  --train_file="$TRAIN_FILE" \
36
  --validation_file="$VALIDATION_FILE" \
37
  --speech_file_column="$SPEECH_FILE_COLUMN" \
@@ -48,4 +50,5 @@ python src/run_wav2vec2_pretrain_flax.py \
48
  --adam_beta2=$ADAM_BETA_2 \
49
  --dtype="$D_TYPE" \
50
  --pad_to_multiple_of=$PAD_TO_MULTIPLE_OF \
 
51
  --push_to_hub
 
4
  export LANG=C.UTF-8
5
 
6
  export OUTPUT_DIR=/home/m3hrdadfi/code/wav2vec2-base-persian
7
+ export OUTPUT_DIR=/home/m3hrdadfi/data_cache/
8
  export MODEL_NAME_OR_PATH=/home/m3hrdadfi/code/wav2vec2-base-persian
9
 
10
 
11
+ export TRAIN_FILE=/home/m3hrdadfi/data/fa/train.csv
12
+ export VALIDATION_FILE=/home/m3hrdadfi/data/fa/test.csv
13
  export SPEECH_FILE_COLUMN=path
14
 
15
 
16
  #export MAX_EVAL_SAMPLES=5000
17
+ export PER_DEVICE_TRAIN_BATCH_SIZE=8
18
+ export PER_DEVICE_EVAL_BATCH_SIZE=8
19
  #export GRADIENT_ACCUMULATION_STEPS=2
20
  export NUM_TRAIN_EPOCHS=5.0
21
  export LEARNING_RATE=5e-4
22
  export WARMUP_STEPS=1000
23
+ export LOGGING_STEPS=500
24
  #export EVAL_STEPS=2500
25
  #export SAVE_STEPS=2500
26
  export PREPROCESSING_NUM_WORKERS=4
 
33
 
34
  python src/run_wav2vec2_pretrain_flax.py \
35
  --output_dir="$OUTPUT_DIR" \
36
+ --cache_dir="$CACHE_DIR" \
37
  --train_file="$TRAIN_FILE" \
38
  --validation_file="$VALIDATION_FILE" \
39
  --speech_file_column="$SPEECH_FILE_COLUMN" \
 
50
  --adam_beta2=$ADAM_BETA_2 \
51
  --dtype="$D_TYPE" \
52
  --pad_to_multiple_of=$PAD_TO_MULTIPLE_OF \
53
+ --logging_steps=$LOGGING_STEPS \
54
  --push_to_hub
src/run_wav2vec2_pretrain_flax.py CHANGED
@@ -349,9 +349,14 @@ def main():
349
  do_normalize=True
350
  )
351
 
 
352
  def prepare_dataset(batch):
353
  # check that all files have the correct sampling rate
354
- batch["speech"], _ = librosa.load(batch[data_args.speech_file_column], sr=feature_extractor.sampling_rate)
 
 
 
 
355
  return batch
356
 
357
  # load audio files into numpy arrays
@@ -377,6 +382,7 @@ def main():
377
  load_from_cache_file=not data_args.overwrite_cache,
378
  remove_columns=vectorized_datasets["train"].column_names,
379
  )
 
380
 
381
  # pretraining is only supported for "newer" stable layer norm architecture
382
  # apply_spec_augment has to be True, mask_feature_prob has to be 0.0
 
349
  do_normalize=True
350
  )
351
 
352
+ target_sampling_rate = 16_000
353
  def prepare_dataset(batch):
354
  # check that all files have the correct sampling rate
355
+ # batch["speech"], _ = librosa.load(batch[data_args.speech_file_column], sr=feature_extractor.sampling_rate)
356
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
357
+ resampler = torchaudio.transforms.Resample(sampling_rate, target_sampling_rate)
358
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
359
+
360
  return batch
361
 
362
  # load audio files into numpy arrays
 
382
  load_from_cache_file=not data_args.overwrite_cache,
383
  remove_columns=vectorized_datasets["train"].column_names,
384
  )
385
+ vectorized_datasets.save_to_disk(model_args.cache_dir)
386
 
387
  # pretraining is only supported for "newer" stable layer norm architecture
388
  # apply_spec_augment has to be True, mask_feature_prob has to be 0.0