first
Browse files- .gitattributes +2 -0
- README.md +12 -13
- add_kenlm.py +34 -0
- added_tokens.json +1 -0
- all_results.json +14 -0
- alphabet.json +1 -0
- config.json +115 -0
- eval.py +151 -0
- eval_results.json +9 -0
- grid.csv +101 -0
- grid.py +34 -0
- language_model/5gram.bin +3 -0
- language_model/attrs.json +1 -0
- language_model/unigrams.txt +3 -0
- log_NbAiLab_NPSC_16K_mp3_bokmaal_test_eval_results.txt +3 -0
- log_NbAiLab_NPSC_16K_mp3_bokmaal_test_predictions.txt +3 -0
- log_NbAiLab_NPSC_16K_mp3_bokmaal_test_targets.txt +3 -0
- preprocessor_config.json +10 -0
- pytorch_model.bin +3 -0
- run.sh +39 -0
- run_speech_recognition_ctc.py +792 -0
- runs/Feb04_12-19-59_dante/1643973630.5333126/events.out.tfevents.1643973630.dante.1786377.1 +3 -0
- runs/Feb04_12-19-59_dante/events.out.tfevents.1643973630.dante.1786377.0 +3 -0
- runs/Feb05_11-55-40_dante/1644058575.319772/events.out.tfevents.1644058575.dante.2573362.1 +3 -0
- runs/Feb05_11-55-40_dante/events.out.tfevents.1644058575.dante.2573362.0 +3 -0
- runs/Feb05_11-55-40_dante/events.out.tfevents.1644066583.dante.2573362.2 +3 -0
- runs/Feb06_00-33-18_dante/1644104059.4582894/events.out.tfevents.1644104059.dante.2706942.1 +3 -0
- runs/Feb06_00-33-18_dante/events.out.tfevents.1644104059.dante.2706942.0 +3 -0
- runs/Feb06_12-59-06_dante/1644148807.511835/events.out.tfevents.1644148807.dante.2790531.1 +3 -0
- runs/Feb06_12-59-06_dante/events.out.tfevents.1644148807.dante.2790531.0 +3 -0
- runs/Feb06_13-01-43_dante/1644148960.1271484/events.out.tfevents.1644148960.dante.2793694.1 +3 -0
- runs/Feb06_13-01-43_dante/events.out.tfevents.1644148960.dante.2793694.0 +3 -0
- runs/Feb06_13-01-43_dante/events.out.tfevents.1644149411.dante.2793694.2 +3 -0
- special_tokens_map.json +1 -0
- tokenizer_config.json +1 -0
- train_results.json +8 -0
- trainer_state.json +217 -0
- training_args.bin +3 -0
- vocab.json +1 -0
.gitattributes
CHANGED
@@ -25,3 +25,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*unigram*.* filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.txt filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -63,16 +63,16 @@ As you see from the results above, adding even a simple 5-gram language will imp
|
|
63 |
### Parameters
|
64 |
The final model was run using these parameters:
|
65 |
```
|
66 |
-
--dataset_name="NbAiLab/NPSC"
|
67 |
-
--model_name_or_path="
|
68 |
-
--dataset_config_name="16K_mp3_bokmaal"
|
69 |
-
--output_dir="./"
|
70 |
-
--overwrite_output_dir
|
71 |
-
--num_train_epochs="
|
72 |
-
--per_device_train_batch_size="
|
73 |
-
--per_device_eval_batch_size="
|
74 |
--gradient_accumulation_steps="2"
|
75 |
-
--learning_rate="
|
76 |
--warmup_steps="2000"
|
77 |
--length_column_name="input_length"
|
78 |
--evaluation_strategy="steps"
|
@@ -84,24 +84,23 @@ The final model was run using these parameters:
|
|
84 |
--attention_dropout="0.094"
|
85 |
--activation_dropout="0.055"
|
86 |
--hidden_dropout="0.047"
|
87 |
-
--save_total_limit="3"
|
88 |
--freeze_feature_encoder
|
89 |
--feat_proj_dropout="0.04"
|
90 |
--mask_time_prob="0.082"
|
91 |
--mask_time_length="10"
|
92 |
--mask_feature_prob="0.25"
|
93 |
--mask_feature_length="64"
|
94 |
-
--gradient_checkpointing
|
95 |
--min_duration_in_seconds="0.5"
|
96 |
--max_duration_in_seconds="30.0"
|
97 |
-
--ctc_zero_infinity=True
|
98 |
--use_auth_token
|
99 |
--seed="42"
|
100 |
--fp16
|
101 |
--group_by_length
|
102 |
--do_train --do_eval
|
103 |
--push_to_hub
|
104 |
-
--preprocessing_num_workers="
|
105 |
```
|
106 |
|
107 |
Following this settings, the training might take 3-4 days on an average GPU. You should however get a decent model and faster results by tweaking these parameters
|
|
|
63 |
### Parameters
|
64 |
The final model was run using these parameters:
|
65 |
```
|
66 |
+
--dataset_name="NbAiLab/NPSC"
|
67 |
+
--model_name_or_path="KBLab/wav2vec2-large-voxrex"
|
68 |
+
--dataset_config_name="16K_mp3_bokmaal"
|
69 |
+
--output_dir="./"
|
70 |
+
--overwrite_output_dir
|
71 |
+
--num_train_epochs="15"
|
72 |
+
--per_device_train_batch_size="16"
|
73 |
+
--per_device_eval_batch_size="16"
|
74 |
--gradient_accumulation_steps="2"
|
75 |
+
--learning_rate="1e-4"
|
76 |
--warmup_steps="2000"
|
77 |
--length_column_name="input_length"
|
78 |
--evaluation_strategy="steps"
|
|
|
84 |
--attention_dropout="0.094"
|
85 |
--activation_dropout="0.055"
|
86 |
--hidden_dropout="0.047"
|
87 |
+
--save_total_limit="3"
|
88 |
--freeze_feature_encoder
|
89 |
--feat_proj_dropout="0.04"
|
90 |
--mask_time_prob="0.082"
|
91 |
--mask_time_length="10"
|
92 |
--mask_feature_prob="0.25"
|
93 |
--mask_feature_length="64"
|
94 |
+
--gradient_checkpointing
|
95 |
--min_duration_in_seconds="0.5"
|
96 |
--max_duration_in_seconds="30.0"
|
|
|
97 |
--use_auth_token
|
98 |
--seed="42"
|
99 |
--fp16
|
100 |
--group_by_length
|
101 |
--do_train --do_eval
|
102 |
--push_to_hub
|
103 |
+
--preprocessing_num_workers="32"
|
104 |
```
|
105 |
|
106 |
Following this settings, the training might take 3-4 days on an average GPU. You should however get a decent model and faster results by tweaking these parameters
|
add_kenlm.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
from transformers import AutoProcessor
|
3 |
+
from transformers import Wav2Vec2ProcessorWithLM
|
4 |
+
from pyctcdecode import build_ctcdecoder
|
5 |
+
|
6 |
+
|
7 |
+
def main(args):
|
8 |
+
processor = AutoProcessor.from_pretrained(args.model_name_or_path)
|
9 |
+
vocab_dict = processor.tokenizer.get_vocab()
|
10 |
+
sorted_vocab_dict = {
|
11 |
+
k.lower(): v for k, v in sorted(vocab_dict.items(), key=lambda item: item[1])
|
12 |
+
}
|
13 |
+
decoder = build_ctcdecoder(
|
14 |
+
labels=list(sorted_vocab_dict.keys()),
|
15 |
+
kenlm_model_path=args.kenlm_model_path,
|
16 |
+
)
|
17 |
+
processor_with_lm = Wav2Vec2ProcessorWithLM(
|
18 |
+
feature_extractor=processor.feature_extractor,
|
19 |
+
tokenizer=processor.tokenizer,
|
20 |
+
decoder=decoder,
|
21 |
+
)
|
22 |
+
processor_with_lm.save_pretrained(args.model_name_or_path)
|
23 |
+
print(f"Run: ~/bin/build_binary language_model/*.arpa language_model/5gram.bin -T $(pwd) && rm language_model/*.arpa")
|
24 |
+
|
25 |
+
def parse_args():
|
26 |
+
parser = argparse.ArgumentParser()
|
27 |
+
parser.add_argument('--model_name_or_path', default="./", help='Model name or path. Defaults to ./')
|
28 |
+
parser.add_argument('--kenlm_model_path', required=True, help='Path to KenLM arpa file.')
|
29 |
+
args = parser.parse_args()
|
30 |
+
return args
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
args = parse_args()
|
34 |
+
main(args)
|
added_tokens.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"<s>": 32, "</s>": 33}
|
all_results.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"epoch": 1.5,
|
3 |
+
"eval_loss": 0.12273009121417999,
|
4 |
+
"eval_runtime": 399.7312,
|
5 |
+
"eval_samples": 5437,
|
6 |
+
"eval_samples_per_second": 13.602,
|
7 |
+
"eval_steps_per_second": 0.851,
|
8 |
+
"eval_wer": 0.0989537882279114,
|
9 |
+
"train_loss": 0.0,
|
10 |
+
"train_runtime": 5.9011,
|
11 |
+
"train_samples": 49645,
|
12 |
+
"train_samples_per_second": 841.279,
|
13 |
+
"train_steps_per_second": 26.436
|
14 |
+
}
|
alphabet.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"labels": [" ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\u00e5", "\u00e6", "\u00f8", "\u2047", "", "<s>", "</s>"], "is_bpe": false}
|
config.json
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "./",
|
3 |
+
"activation_dropout": 0.055,
|
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.094,
|
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": true,
|
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.04,
|
53 |
+
"feat_quantizer_dropout": 0.0,
|
54 |
+
"final_dropout": 0.0,
|
55 |
+
"hidden_act": "gelu",
|
56 |
+
"hidden_dropout": 0.047,
|
57 |
+
"hidden_size": 1024,
|
58 |
+
"initializer_range": 0.02,
|
59 |
+
"intermediate_size": 4096,
|
60 |
+
"layer_norm_eps": 1e-05,
|
61 |
+
"layerdrop": 0.041,
|
62 |
+
"mask_channel_length": 10,
|
63 |
+
"mask_channel_min_space": 1,
|
64 |
+
"mask_channel_other": 0.0,
|
65 |
+
"mask_channel_prob": 0.0,
|
66 |
+
"mask_channel_selection": "static",
|
67 |
+
"mask_feature_length": 64,
|
68 |
+
"mask_feature_min_masks": 0,
|
69 |
+
"mask_feature_prob": 0.25,
|
70 |
+
"mask_time_length": 10,
|
71 |
+
"mask_time_min_masks": 2,
|
72 |
+
"mask_time_min_space": 1,
|
73 |
+
"mask_time_other": 0.0,
|
74 |
+
"mask_time_prob": 0.082,
|
75 |
+
"mask_time_selection": "static",
|
76 |
+
"model_type": "wav2vec2",
|
77 |
+
"num_adapter_layers": 3,
|
78 |
+
"num_attention_heads": 16,
|
79 |
+
"num_codevector_groups": 2,
|
80 |
+
"num_codevectors_per_group": 320,
|
81 |
+
"num_conv_pos_embedding_groups": 16,
|
82 |
+
"num_conv_pos_embeddings": 128,
|
83 |
+
"num_feat_extract_layers": 7,
|
84 |
+
"num_hidden_layers": 24,
|
85 |
+
"num_negatives": 100,
|
86 |
+
"output_hidden_size": 1024,
|
87 |
+
"pad_token_id": 31,
|
88 |
+
"proj_codevector_dim": 768,
|
89 |
+
"tdnn_dilation": [
|
90 |
+
1,
|
91 |
+
2,
|
92 |
+
3,
|
93 |
+
1,
|
94 |
+
1
|
95 |
+
],
|
96 |
+
"tdnn_dim": [
|
97 |
+
512,
|
98 |
+
512,
|
99 |
+
512,
|
100 |
+
512,
|
101 |
+
1500
|
102 |
+
],
|
103 |
+
"tdnn_kernel": [
|
104 |
+
5,
|
105 |
+
3,
|
106 |
+
3,
|
107 |
+
1,
|
108 |
+
1
|
109 |
+
],
|
110 |
+
"torch_dtype": "float32",
|
111 |
+
"transformers_version": "4.17.0.dev0",
|
112 |
+
"use_weighted_layer_sum": false,
|
113 |
+
"vocab_size": 34,
|
114 |
+
"xvector_output_dim": 512
|
115 |
+
}
|
eval.py
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import argparse
|
3 |
+
import re
|
4 |
+
from typing import Dict
|
5 |
+
|
6 |
+
import torch
|
7 |
+
from datasets import Audio, Dataset, load_dataset, load_metric
|
8 |
+
|
9 |
+
from transformers import AutoFeatureExtractor, pipeline
|
10 |
+
|
11 |
+
|
12 |
+
def log_results(result: Dataset, args: Dict[str, str]):
|
13 |
+
"""DO NOT CHANGE. This function computes and logs the result metrics."""
|
14 |
+
|
15 |
+
log_outputs = args.log_outputs
|
16 |
+
dataset_id = "_".join(args.dataset.split("/") + [args.config, args.split])
|
17 |
+
|
18 |
+
# load metric
|
19 |
+
wer = load_metric("wer")
|
20 |
+
cer = load_metric("cer")
|
21 |
+
|
22 |
+
# compute metrics
|
23 |
+
wer_result = wer.compute(references=result["target"], predictions=result["prediction"])
|
24 |
+
cer_result = cer.compute(references=result["target"], predictions=result["prediction"])
|
25 |
+
|
26 |
+
# print & log results
|
27 |
+
result_str = f"WER: {wer_result}\n" f"CER: {cer_result}"
|
28 |
+
print(result_str)
|
29 |
+
|
30 |
+
with open(f"{dataset_id}_eval_results.txt", "w") as f:
|
31 |
+
f.write(result_str)
|
32 |
+
|
33 |
+
# log all results in text file. Possibly interesting for analysis
|
34 |
+
if log_outputs is not None:
|
35 |
+
pred_file = f"log_{dataset_id}_predictions.txt"
|
36 |
+
target_file = f"log_{dataset_id}_targets.txt"
|
37 |
+
|
38 |
+
with open(pred_file, "w") as p, open(target_file, "w") as t:
|
39 |
+
|
40 |
+
# mapping function to write output
|
41 |
+
def write_to_file(batch, i):
|
42 |
+
p.write(f"{i}" + "\n")
|
43 |
+
p.write(batch["prediction"] + "\n")
|
44 |
+
t.write(f"{i}" + "\n")
|
45 |
+
t.write(batch["target"] + "\n")
|
46 |
+
|
47 |
+
result.map(write_to_file, with_indices=True)
|
48 |
+
|
49 |
+
|
50 |
+
def normalize_text(text: str) -> str:
|
51 |
+
"""DO ADAPT FOR YOUR USE CASE. this function normalizes the target text."""
|
52 |
+
|
53 |
+
chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�\'\–\_\\\+\#\/]' # noqa: W605 IMPORTANT: this should correspond to the chars that were ignored during training
|
54 |
+
|
55 |
+
text = re.sub(chars_to_ignore_regex, "", text.lower()) + " "
|
56 |
+
text = re.sub('[áàâ]', 'a', text)
|
57 |
+
text = re.sub('[ä]', 'æ', text)
|
58 |
+
text = re.sub('[éèëê]', 'e', text)
|
59 |
+
text = re.sub('[íìïî]', 'i', text)
|
60 |
+
text = re.sub('[óòöô]', 'o', text)
|
61 |
+
text = re.sub('[ö]', 'ø', text)
|
62 |
+
text = re.sub('[ç]', 'c', text)
|
63 |
+
text = re.sub('[úùüû]', 'u', text)
|
64 |
+
text = re.sub('\s', ' ', text)
|
65 |
+
text = re.sub('<ee>', 'eee', text)
|
66 |
+
text = re.sub('<qq>', 'qqq', text)
|
67 |
+
text = re.sub('<mm>', 'mmm', text)
|
68 |
+
text = re.sub('<inaudible>', 'xxx', text)
|
69 |
+
text = re.sub('[<>]', '', text)
|
70 |
+
|
71 |
+
# # In addition, we can normalize the target text, e.g. removing new lines characters etc...
|
72 |
+
# # note that order is important here!
|
73 |
+
# token_sequences_to_ignore = ["\n\n", "\n", " ", " "]
|
74 |
+
|
75 |
+
# for t in token_sequences_to_ignore:
|
76 |
+
# text = " ".join(text.split(t))
|
77 |
+
|
78 |
+
return text
|
79 |
+
|
80 |
+
|
81 |
+
def main(args):
|
82 |
+
# load dataset
|
83 |
+
dataset = load_dataset(args.dataset, args.config, split=args.split, use_auth_token=True)
|
84 |
+
|
85 |
+
# for testing: only process the first two examples as a test
|
86 |
+
# dataset = dataset.select(range(10))
|
87 |
+
|
88 |
+
# load processor
|
89 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(args.model_id)
|
90 |
+
sampling_rate = feature_extractor.sampling_rate
|
91 |
+
|
92 |
+
# resample audio
|
93 |
+
dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
|
94 |
+
|
95 |
+
# load eval pipeline
|
96 |
+
if args.device is None:
|
97 |
+
args.device = 0 if torch.cuda.is_available() else -1
|
98 |
+
asr = pipeline("automatic-speech-recognition", model=args.model_id, device=args.device)
|
99 |
+
|
100 |
+
# map function to decode audio
|
101 |
+
def map_to_pred(batch):
|
102 |
+
prediction = asr(
|
103 |
+
batch["audio"]["array"], chunk_length_s=args.chunk_length_s, stride_length_s=args.stride_length_s
|
104 |
+
)
|
105 |
+
|
106 |
+
batch["prediction"] = prediction["text"]
|
107 |
+
batch["target"] = normalize_text(batch["text"])
|
108 |
+
return batch
|
109 |
+
|
110 |
+
# run inference on all examples
|
111 |
+
result = dataset.map(map_to_pred, remove_columns=dataset.column_names)
|
112 |
+
|
113 |
+
# compute and log_results
|
114 |
+
# do not change function below
|
115 |
+
log_results(result, args)
|
116 |
+
|
117 |
+
|
118 |
+
if __name__ == "__main__":
|
119 |
+
parser = argparse.ArgumentParser()
|
120 |
+
|
121 |
+
parser.add_argument(
|
122 |
+
"--model_id", type=str, required=True, help="Model identifier. Should be loadable with 🤗 Transformers"
|
123 |
+
)
|
124 |
+
parser.add_argument(
|
125 |
+
"--dataset",
|
126 |
+
type=str,
|
127 |
+
required=True,
|
128 |
+
help="Dataset name to evaluate the `model_id`. Should be loadable with 🤗 Datasets",
|
129 |
+
)
|
130 |
+
parser.add_argument(
|
131 |
+
"--config", type=str, required=True, help="Config of the dataset. *E.g.* `'en'` for Common Voice"
|
132 |
+
)
|
133 |
+
parser.add_argument("--split", type=str, required=True, help="Split of the dataset. *E.g.* `'test'`")
|
134 |
+
parser.add_argument(
|
135 |
+
"--chunk_length_s", type=float, default=None, help="Chunk length in seconds. Defaults to 5 seconds."
|
136 |
+
)
|
137 |
+
parser.add_argument(
|
138 |
+
"--stride_length_s", type=float, default=None, help="Stride of the audio chunks. Defaults to 1 second."
|
139 |
+
)
|
140 |
+
parser.add_argument(
|
141 |
+
"--log_outputs", action="store_true", help="If defined, write outputs to log file for analysis."
|
142 |
+
)
|
143 |
+
parser.add_argument(
|
144 |
+
"--device",
|
145 |
+
type=int,
|
146 |
+
default=None,
|
147 |
+
help="The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on.",
|
148 |
+
)
|
149 |
+
args = parser.parse_args()
|
150 |
+
|
151 |
+
main(args)
|
eval_results.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"epoch": 1.5,
|
3 |
+
"eval_loss": 0.12273009121417999,
|
4 |
+
"eval_runtime": 399.7312,
|
5 |
+
"eval_samples": 5437,
|
6 |
+
"eval_samples_per_second": 13.602,
|
7 |
+
"eval_steps_per_second": 0.851,
|
8 |
+
"eval_wer": 0.0989537882279114
|
9 |
+
}
|
grid.csv
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
alpha,beta,wer,cer
|
2 |
+
0.001,0.001,0.09547085935319984,0.029674778514815793
|
3 |
+
0.001,0.01,0.09553821432351554,0.029683084728361897
|
4 |
+
0.001,0.1,0.09571141281861306,0.029724615796092424
|
5 |
+
0.001,0.25,0.096019321254342,0.029746211951312298
|
6 |
+
0.001,0.5,0.0972509549972577,0.029950544804546488
|
7 |
+
0.001,0.75,0.09849221087878993,0.030179796298418996
|
8 |
+
0.001,1,0.09977195531478826,0.030379145423525523
|
9 |
+
0.001,1.5,0.1028799060879271,0.03088914693525639
|
10 |
+
0.001,2,0.10715213563366593,0.031522080407469615
|
11 |
+
0.001,3,0.1189200111616808,0.03319495181565522
|
12 |
+
0.01,0.001,0.09309419111491721,0.02945051074907095
|
13 |
+
0.01,0.01,0.09311343539215026,0.029443865778234067
|
14 |
+
0.01,0.1,0.09344058810511224,0.02948373560325537
|
15 |
+
0.01,0.25,0.09395056145178828,0.029523605428276676
|
16 |
+
0.01,0.5,0.09508597380853868,0.02965816608772358
|
17 |
+
0.01,0.75,0.0962887411356048,0.029847547756574784
|
18 |
+
0.01,1,0.09774168406670067,0.030105040376504046
|
19 |
+
0.01,1.5,0.1008496348398395,0.030596768218433483
|
20 |
+
0.01,2,0.10507375369249569,0.031251297845866575
|
21 |
+
0.01,3,0.11661069789371385,0.03288928315715854
|
22 |
+
0.1,0.001,0.08018128109153541,0.027892265087821597
|
23 |
+
0.1,0.01,0.08017165895291888,0.027895587573240038
|
24 |
+
0.1,0.1,0.0802775024777007,0.027907216272204584
|
25 |
+
0.1,0.25,0.0806142773292792,0.027893926330530817
|
26 |
+
0.1,0.5,0.08166309043848086,0.028045099417069935
|
27 |
+
0.1,0.75,0.08281774707246432,0.028191288775481386
|
28 |
+
0.1,1,0.08378958307273375,0.02827435091094244
|
29 |
+
0.1,1.5,0.08655113685567754,0.028596631996531324
|
30 |
+
0.1,2,0.08970719832189902,0.02901194267383659
|
31 |
+
0.1,3,0.09869427578973702,0.03040738654958228
|
32 |
+
0.25,0.001,0.07359973827782963,0.027008483966515992
|
33 |
+
0.25,0.01,0.07358049400059657,0.027008483966515992
|
34 |
+
0.25,0.1,0.07362860469367921,0.026993532782133
|
35 |
+
0.25,0.25,0.07380180318877674,0.026963630413367023
|
36 |
+
0.25,0.5,0.07414820017897178,0.02695698544253014
|
37 |
+
0.25,0.75,0.07442724219885112,0.02695698544253014
|
38 |
+
0.25,1,0.07499494837722633,0.027063304975920285
|
39 |
+
0.25,1.5,0.07606300576366103,0.027172946994728876
|
40 |
+
0.25,2,0.07761217008092218,0.027242719188516163
|
41 |
+
0.25,3,0.08315452192404284,0.02800689083475785
|
42 |
+
0.5,0.001,0.07044367681160815,0.026963630413367023
|
43 |
+
0.5,0.01,0.0704244325343751,0.02695532419982092
|
44 |
+
0.5,0.1,0.07028972259374369,0.026870600821650645
|
45 |
+
0.5,0.25,0.07050140964330733,0.02688222952061519
|
46 |
+
0.5,0.5,0.07065536386117179,0.026905486918544285
|
47 |
+
0.5,0.75,0.07108836009891559,0.02694037301543793
|
48 |
+
0.5,1,0.07091516160381807,0.026809134841409465
|
49 |
+
0.5,1.5,0.0711942036236974,0.026624736900685928
|
50 |
+
0.5,2,0.07201208540610236,0.026729395191366852
|
51 |
+
0.5,3,0.0740904673472726,0.026917115617508834
|
52 |
+
0.75,0.001,0.07321485273316847,0.02827767339636088
|
53 |
+
0.75,0.01,0.07318598631731889,0.028264383454687115
|
54 |
+
0.75,0.1,0.07289732215882302,0.028197933746318272
|
55 |
+
0.75,0.25,0.07285883360435691,0.028173015105679954
|
56 |
+
0.75,0.5,0.07246432592107922,0.02800855207746707
|
57 |
+
0.75,0.75,0.07206981823780154,0.027877313903438606
|
58 |
+
0.75,1,0.07177153194068914,0.027717834603353385
|
59 |
+
0.75,1.5,0.07124231431678005,0.02735069996461553
|
60 |
+
0.75,2,0.07131929142571228,0.027231090489551614
|
61 |
+
0.75,3,0.07209868465365112,0.027249364159353046
|
62 |
+
1,0.001,0.08050843380449739,0.030586800762178155
|
63 |
+
1,0.01,0.08048918952726433,0.030598429461142704
|
64 |
+
1,0.1,0.08019090323015193,0.03053197975277386
|
65 |
+
1,0.25,0.07958470849731061,0.03034758181205032
|
66 |
+
1,0.5,0.07864173891289078,0.030065170551482744
|
67 |
+
1,0.75,0.07811252128898169,0.029845886513865563
|
68 |
+
1,1,0.07759292580368912,0.029613312534574613
|
69 |
+
1,1.5,0.07614960501120979,0.029111617236389855
|
70 |
+
1,2,0.07533172322880484,0.0288076098206024
|
71 |
+
1,3,0.07439837578300153,0.028271028425523998
|
72 |
+
1.5,0.001,0.10399607416744445,0.035783167956621634
|
73 |
+
1.5,0.01,0.10393834133574528,0.03576987801494786
|
74 |
+
1.5,0.1,0.10341874585045273,0.0356070762294442
|
75 |
+
1.5,0.25,0.10243728771156678,0.035369518522025585
|
76 |
+
1.5,0.5,0.10124414252311718,0.035130299571897755
|
77 |
+
1.5,0.75,0.1000798637505172,0.03490270932073447
|
78 |
+
1.5,1,0.09854032157187256,0.034550525866379606
|
79 |
+
1.5,1.5,0.09586536703647752,0.03397573588898912
|
80 |
+
1.5,2,0.09308456897630067,0.03324811158235029
|
81 |
+
1.5,3,0.08891818295534365,0.032244720985980774
|
82 |
+
2,0.001,0.12878270324362293,0.040386471503873186
|
83 |
+
2,0.01,0.1287730811050064,0.04037650404761786
|
84 |
+
2,0.1,0.12826310775833036,0.04026520078610005
|
85 |
+
2,0.25,0.12718542823327914,0.040067512903702744
|
86 |
+
2,0.5,0.1253187333416725,0.03970037826496489
|
87 |
+
2,0.75,0.1241833209849221,0.03952096405236902
|
88 |
+
2,1,0.12279773302414194,0.03930500250017028
|
89 |
+
2,1.5,0.11951658375590558,0.0386836977269216
|
90 |
+
2,2,0.11614883524012047,0.03804578052658071
|
91 |
+
2,3,0.11092401397134527,0.03697760146455157
|
92 |
+
3,0.001,0.15472398895378486,0.04477547474163523
|
93 |
+
3,0.01,0.15461814542900304,0.04474889485828769
|
94 |
+
3,0.1,0.15435834768635676,0.04472895994577704
|
95 |
+
3,0.25,0.15378101936936503,0.044596060529039354
|
96 |
+
3,0.5,0.1530016261414262,0.0444498711706279
|
97 |
+
3,0.75,0.15221261077487083,0.04431863299659944
|
98 |
+
3,1,0.15129850760630056,0.04415416996838655
|
99 |
+
3,1.5,0.14928748063544603,0.04384351758176221
|
100 |
+
3,2,0.14715136586257663,0.04347472170031514
|
101 |
+
3,3,0.14315817833671712,0.042783644733279176
|
grid.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
from argparse import ArgumentDefaultsHelpFormatter
|
3 |
+
from collections import namedtuple
|
4 |
+
from functools import partialmethod
|
5 |
+
import json
|
6 |
+
|
7 |
+
from tqdm import tqdm
|
8 |
+
from eval import main
|
9 |
+
|
10 |
+
|
11 |
+
# tqdm.__init__ = partialmethod(tqdm.__init__, disable=True)
|
12 |
+
|
13 |
+
Args = namedtuple("Args", "model_id dataset config split log_outputs chunk_length_s stride_length_s device")
|
14 |
+
args = Args("./", "NbAiLab/NPSC", "16K_mp3_bokmaal", "test", True, None, None, 0)
|
15 |
+
with open("grid.csv", "w") as grid:
|
16 |
+
grid.write("alpha,beta,wer,cer")
|
17 |
+
for alpha in [0.001, 0.01, 0.1, 0.25, 0.5, 0.75, 1, 1.5, 2, 3]:
|
18 |
+
for beta in [0.001, 0.01, 0.1, 0.25, 0.5, 0.75, 1, 1.5, 2, 3]:
|
19 |
+
with open("./language_model/attrs.json", "r") as attrs_file:
|
20 |
+
attrs = json.load(attrs_file)
|
21 |
+
attrs["alpha"] = alpha
|
22 |
+
attrs["beta"] = beta
|
23 |
+
with open("./language_model/attrs.json", "w") as attrs_file:
|
24 |
+
json.dump(attrs, attrs_file)
|
25 |
+
print(f"alpha = {alpha}, beta = {beta}")
|
26 |
+
main(args)
|
27 |
+
with open("NbAiLab_NPSC_16K_mp3_bokmaal_test_eval_results.txt") as results_file:
|
28 |
+
results = results_file.read().strip().split("\n")
|
29 |
+
wer = float(results[0][5:])
|
30 |
+
cer = float(results[1][5:])
|
31 |
+
grid.write(f"\n{alpha},{beta},{wer},{cer}")
|
32 |
+
print("--------------")
|
33 |
+
|
34 |
+
|
language_model/5gram.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7b41c24c63f2f0585bea83666369593f3b3e6d047f327a90f36ebca2c35ef0ff
|
3 |
+
size 4243671427
|
language_model/attrs.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"alpha": 0.5, "beta": 0.1, "unk_score_offset": -10.0, "score_boundary": true}
|
language_model/unigrams.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ac3e71ca49838ca355df6fdcb8d89344a5a9bf9e1a76587cdf5df1367c19b9a9
|
3 |
+
size 16759269
|
log_NbAiLab_NPSC_16K_mp3_bokmaal_test_eval_results.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b1ee0d706882f015034b183fde35453b0c0c02f69e5143fb9fc329780fea0f27
|
3 |
+
size 50
|
log_NbAiLab_NPSC_16K_mp3_bokmaal_test_predictions.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:60928a28777980ce5e8abb4fed8c3b823135c1e5b5247c6b7dfdde0435440d08
|
3 |
+
size 644626
|
log_NbAiLab_NPSC_16K_mp3_bokmaal_test_targets.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d7e27a71ec76c0ded0b0cf852b9d42c620e1c5863bcf9a06fcbbbbd924e9d1b9
|
3 |
+
size 654671
|
preprocessor_config.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_normalize": true,
|
3 |
+
"feature_extractor_type": "Wav2Vec2FeatureExtractor",
|
4 |
+
"feature_size": 1,
|
5 |
+
"padding_side": "right",
|
6 |
+
"padding_value": 0,
|
7 |
+
"processor_class": "Wav2Vec2ProcessorWithLM",
|
8 |
+
"return_attention_mask": true,
|
9 |
+
"sampling_rate": 16000
|
10 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:146aae60aca5aad96c2d676908ba62300d18e34ec2cc31c921f29458eacbf2a7
|
3 |
+
size 1262063089
|
run.sh
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
python run_speech_recognition_ctc.py \
|
2 |
+
--dataset_name="NbAiLab/NPSC" \
|
3 |
+
--model_name_or_path="KBLab/wav2vec2-large-voxrex" \
|
4 |
+
--dataset_config_name="16K_mp3" \
|
5 |
+
--output_dir="./" \
|
6 |
+
--overwrite_output_dir \
|
7 |
+
--num_train_epochs="15" \
|
8 |
+
--per_device_train_batch_size="16" \
|
9 |
+
--per_device_eval_batch_size="16" \
|
10 |
+
--gradient_accumulation_steps="2" \
|
11 |
+
--learning_rate="1e-4" \
|
12 |
+
--warmup_steps="2000" \
|
13 |
+
--length_column_name="input_length" \
|
14 |
+
--evaluation_strategy="steps" \
|
15 |
+
--text_column_name="text" \
|
16 |
+
--save_steps="500" \
|
17 |
+
--eval_steps="500" \
|
18 |
+
--logging_steps="100" \
|
19 |
+
--layerdrop="0.041" \
|
20 |
+
--attention_dropout="0.094" \
|
21 |
+
--activation_dropout="0.055" \
|
22 |
+
--hidden_dropout="0.047" \
|
23 |
+
--save_total_limit="3" \
|
24 |
+
--freeze_feature_encoder \
|
25 |
+
--feat_proj_dropout="0.04" \
|
26 |
+
--mask_time_prob="0.082" \
|
27 |
+
--mask_time_length="10" \
|
28 |
+
--mask_feature_prob="0.25" \
|
29 |
+
--mask_feature_length="64" \
|
30 |
+
--gradient_checkpointing \
|
31 |
+
--min_duration_in_seconds="0.5" \
|
32 |
+
--max_duration_in_seconds="30.0" \
|
33 |
+
--use_auth_token \
|
34 |
+
--seed="42" \
|
35 |
+
--fp16 \
|
36 |
+
--group_by_length \
|
37 |
+
--do_train --do_eval \
|
38 |
+
--push_to_hub \
|
39 |
+
--preprocessing_num_workers="32"
|
run_speech_recognition_ctc.py
ADDED
@@ -0,0 +1,792 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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://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 |
+
|
16 |
+
""" Fine-tuning a 🤗 Transformers CTC model for automatic speech recognition"""
|
17 |
+
|
18 |
+
import functools
|
19 |
+
import json
|
20 |
+
import logging
|
21 |
+
import os
|
22 |
+
import re
|
23 |
+
import sys
|
24 |
+
import warnings
|
25 |
+
from dataclasses import dataclass, field
|
26 |
+
from typing import Dict, List, Optional, Union
|
27 |
+
|
28 |
+
import datasets
|
29 |
+
import numpy as np
|
30 |
+
import torch
|
31 |
+
from datasets import DatasetDict, load_dataset, load_metric
|
32 |
+
|
33 |
+
import transformers
|
34 |
+
from transformers import (
|
35 |
+
AutoConfig,
|
36 |
+
AutoFeatureExtractor,
|
37 |
+
AutoModelForCTC,
|
38 |
+
AutoProcessor,
|
39 |
+
AutoTokenizer,
|
40 |
+
HfArgumentParser,
|
41 |
+
Trainer,
|
42 |
+
TrainingArguments,
|
43 |
+
Wav2Vec2Processor,
|
44 |
+
set_seed,
|
45 |
+
)
|
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 |
+
|
50 |
+
|
51 |
+
# Will error if the minimal version of Transformers is not installed. Remove at your own risks.
|
52 |
+
check_min_version("4.16.0.dev0")
|
53 |
+
|
54 |
+
require_version("datasets>=1.13.3", "To fix: pip install -r examples/pytorch/text-classification/requirements.txt")
|
55 |
+
|
56 |
+
|
57 |
+
logger = logging.getLogger(__name__)
|
58 |
+
|
59 |
+
|
60 |
+
def list_field(default=None, metadata=None):
|
61 |
+
return field(default_factory=lambda: default, metadata=metadata)
|
62 |
+
|
63 |
+
|
64 |
+
@dataclass
|
65 |
+
class ModelArguments:
|
66 |
+
"""
|
67 |
+
Arguments pertaining to which model/config/tokenizer we are going to fine-tune from.
|
68 |
+
"""
|
69 |
+
|
70 |
+
model_name_or_path: str = field(
|
71 |
+
metadata={"help": "Path to pretrained model or model identifier from huggingface.co/models"}
|
72 |
+
)
|
73 |
+
tokenizer_name_or_path: Optional[str] = field(
|
74 |
+
default=None,
|
75 |
+
metadata={"help": "Path to pretrained tokenizer or tokenizer identifier from huggingface.co/models"},
|
76 |
+
)
|
77 |
+
cache_dir: Optional[str] = field(
|
78 |
+
default=None,
|
79 |
+
metadata={"help": "Where do you want to store the pretrained models downloaded from huggingface.co"},
|
80 |
+
)
|
81 |
+
freeze_feature_encoder: bool = field(
|
82 |
+
default=True, metadata={"help": "Whether to freeze the feature encoder layers of the model."}
|
83 |
+
)
|
84 |
+
attention_dropout: float = field(
|
85 |
+
default=0.0, metadata={"help": "The dropout ratio for the attention probabilities."}
|
86 |
+
)
|
87 |
+
activation_dropout: float = field(
|
88 |
+
default=0.0, metadata={"help": "The dropout ratio for activations inside the fully connected layer."}
|
89 |
+
)
|
90 |
+
feat_proj_dropout: float = field(default=0.0, metadata={"help": "The dropout ratio for the projected features."})
|
91 |
+
hidden_dropout: float = field(
|
92 |
+
default=0.0,
|
93 |
+
metadata={
|
94 |
+
"help": "The dropout probability for all fully connected layers in the embeddings, encoder, and pooler."
|
95 |
+
},
|
96 |
+
)
|
97 |
+
final_dropout: float = field(
|
98 |
+
default=0.0,
|
99 |
+
metadata={"help": "The dropout probability for the final projection layer."},
|
100 |
+
)
|
101 |
+
mask_time_prob: float = field(
|
102 |
+
default=0.05,
|
103 |
+
metadata={
|
104 |
+
"help": "Probability of each feature vector along the time axis to be chosen as the start of the vector"
|
105 |
+
"span to be masked. Approximately ``mask_time_prob * sequence_length // mask_time_length`` feature"
|
106 |
+
"vectors will be masked along the time axis."
|
107 |
+
},
|
108 |
+
)
|
109 |
+
mask_time_length: int = field(
|
110 |
+
default=10,
|
111 |
+
metadata={"help": "Length of vector span to mask along the time axis."},
|
112 |
+
)
|
113 |
+
mask_feature_prob: float = field(
|
114 |
+
default=0.0,
|
115 |
+
metadata={
|
116 |
+
"help": "Probability of each feature vector along the feature axis to be chosen as the start of the vector"
|
117 |
+
"span to be masked. Approximately ``mask_feature_prob * sequence_length // mask_feature_length`` feature bins will be masked along the time axis."
|
118 |
+
},
|
119 |
+
)
|
120 |
+
mask_feature_length: int = field(
|
121 |
+
default=10,
|
122 |
+
metadata={"help": "Length of vector span to mask along the feature axis."},
|
123 |
+
)
|
124 |
+
layerdrop: float = field(default=0.0, metadata={"help": "The LayerDrop probability."})
|
125 |
+
ctc_loss_reduction: Optional[str] = field(
|
126 |
+
default="mean", metadata={"help": "The way the ctc loss should be reduced. Should be one of 'mean' or 'sum'."}
|
127 |
+
)
|
128 |
+
ctc_zero_infinity: Optional[bool] = field(
|
129 |
+
default=False, metadata={"help": "If True, will try yo aboud the CTC loss goinf to infinity."}
|
130 |
+
)
|
131 |
+
|
132 |
+
@dataclass
|
133 |
+
class DataTrainingArguments:
|
134 |
+
"""
|
135 |
+
Arguments pertaining to what data we are going to input our model for training and eval.
|
136 |
+
|
137 |
+
Using `HfArgumentParser` we can turn this class
|
138 |
+
into argparse arguments to be able to specify them on
|
139 |
+
the command line.
|
140 |
+
"""
|
141 |
+
|
142 |
+
dataset_name: str = field(
|
143 |
+
metadata={"help": "The configuration name of the dataset to use (via the datasets library)."}
|
144 |
+
)
|
145 |
+
dataset_config_name: str = field(
|
146 |
+
default=None, metadata={"help": "The configuration name of the dataset to use (via the datasets library)."}
|
147 |
+
)
|
148 |
+
train_split_name: str = field(
|
149 |
+
default="train+validation",
|
150 |
+
metadata={
|
151 |
+
"help": "The name of the training data set split to use (via the datasets library). Defaults to 'train'"
|
152 |
+
},
|
153 |
+
)
|
154 |
+
eval_split_name: str = field(
|
155 |
+
default="test",
|
156 |
+
metadata={
|
157 |
+
"help": "The name of the training data set split to use (via the datasets library). Defaults to 'train'"
|
158 |
+
},
|
159 |
+
)
|
160 |
+
audio_column_name: str = field(
|
161 |
+
default="audio",
|
162 |
+
metadata={"help": "The name of the dataset column containing the audio data. Defaults to 'audio'"},
|
163 |
+
)
|
164 |
+
text_column_name: str = field(
|
165 |
+
default="text",
|
166 |
+
metadata={"help": "The name of the dataset column containing the text data. Defaults to 'text'"},
|
167 |
+
)
|
168 |
+
overwrite_cache: bool = field(
|
169 |
+
default=False, metadata={"help": "Overwrite the cached preprocessed datasets or not."}
|
170 |
+
)
|
171 |
+
preprocessing_num_workers: Optional[int] = field(
|
172 |
+
default=None,
|
173 |
+
metadata={"help": "The number of processes to use for the preprocessing."},
|
174 |
+
)
|
175 |
+
max_train_samples: Optional[int] = field(
|
176 |
+
default=None,
|
177 |
+
metadata={
|
178 |
+
"help": "For debugging purposes or quicker training, truncate the number of training examples to this "
|
179 |
+
"value if set."
|
180 |
+
},
|
181 |
+
)
|
182 |
+
max_eval_samples: Optional[int] = field(
|
183 |
+
default=None,
|
184 |
+
metadata={
|
185 |
+
"help": "For debugging purposes or quicker training, truncate the number of validation examples to this "
|
186 |
+
"value if set."
|
187 |
+
},
|
188 |
+
)
|
189 |
+
chars_to_ignore: Optional[List[str]] = list_field(
|
190 |
+
default=None,
|
191 |
+
metadata={"help": "A list of characters to remove from the transcripts."},
|
192 |
+
)
|
193 |
+
eval_metrics: List[str] = list_field(
|
194 |
+
default=["wer"],
|
195 |
+
metadata={"help": "A list of metrics the model should be evaluated on. E.g. `'wer cer'`"},
|
196 |
+
)
|
197 |
+
max_duration_in_seconds: float = field(
|
198 |
+
default=20.0,
|
199 |
+
metadata={
|
200 |
+
"help": "Filter audio files that are longer than `max_duration_in_seconds` seconds to 'max_duration_in_seconds`"
|
201 |
+
},
|
202 |
+
)
|
203 |
+
min_duration_in_seconds: float = field(
|
204 |
+
default=0.0, metadata={"help": "Filter audio files that are shorter than `min_duration_in_seconds` seconds"}
|
205 |
+
)
|
206 |
+
preprocessing_only: bool = field(
|
207 |
+
default=False,
|
208 |
+
metadata={
|
209 |
+
"help": "Whether to only do data preprocessing and skip training. "
|
210 |
+
"This is especially useful when data preprocessing errors out in distributed training due to timeout. "
|
211 |
+
"In this case, one should run the preprocessing in a non-distributed setup with `preprocessing_only=True` "
|
212 |
+
"so that the cached datasets can consequently be loaded in distributed training"
|
213 |
+
},
|
214 |
+
)
|
215 |
+
use_auth_token: bool = field(
|
216 |
+
default=False,
|
217 |
+
metadata={
|
218 |
+
"help": "If :obj:`True`, will use the token generated when running"
|
219 |
+
":obj:`transformers-cli login` as HTTP bearer authorization for remote files."
|
220 |
+
},
|
221 |
+
)
|
222 |
+
unk_token: str = field(
|
223 |
+
default="[UNK]",
|
224 |
+
metadata={"help": "The unk token for the tokenizer"},
|
225 |
+
)
|
226 |
+
pad_token: str = field(
|
227 |
+
default="[PAD]",
|
228 |
+
metadata={"help": "The padding token for the tokenizer"},
|
229 |
+
)
|
230 |
+
word_delimiter_token: str = field(
|
231 |
+
default="|",
|
232 |
+
metadata={"help": "The word delimiter token for the tokenizer"},
|
233 |
+
)
|
234 |
+
phoneme_language: Optional[str] = field(
|
235 |
+
default=None,
|
236 |
+
metadata={
|
237 |
+
"help": "The target language that should be used be"
|
238 |
+
" passed to the tokenizer for tokenization. Note that"
|
239 |
+
" this is only relevant if the model classifies the"
|
240 |
+
" input audio to a sequence of phoneme sequences."
|
241 |
+
},
|
242 |
+
)
|
243 |
+
|
244 |
+
|
245 |
+
@dataclass
|
246 |
+
class DataCollatorCTCWithPadding:
|
247 |
+
"""
|
248 |
+
Data collator that will dynamically pad the inputs received.
|
249 |
+
Args:
|
250 |
+
processor (:class:`~transformers.AutoProcessor`)
|
251 |
+
The processor used for proccessing the data.
|
252 |
+
padding (:obj:`bool`, :obj:`str` or :class:`~transformers.tokenization_utils_base.PaddingStrategy`, `optional`, defaults to :obj:`True`):
|
253 |
+
Select a strategy to pad the returned sequences (according to the model's padding side and padding index)
|
254 |
+
among:
|
255 |
+
* :obj:`True` or :obj:`'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
|
256 |
+
sequence if provided).
|
257 |
+
* :obj:`'max_length'`: Pad to a maximum length specified with the argument :obj:`max_length` or to the
|
258 |
+
maximum acceptable input length for the model if that argument is not provided.
|
259 |
+
* :obj:`False` or :obj:`'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of
|
260 |
+
different lengths).
|
261 |
+
max_length (:obj:`int`, `optional`):
|
262 |
+
Maximum length of the ``input_values`` of the returned list and optionally padding length (see above).
|
263 |
+
max_length_labels (:obj:`int`, `optional`):
|
264 |
+
Maximum length of the ``labels`` returned list and optionally padding length (see above).
|
265 |
+
pad_to_multiple_of (:obj:`int`, `optional`):
|
266 |
+
If set will pad the sequence to a multiple of the provided value.
|
267 |
+
This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability >=
|
268 |
+
7.5 (Volta).
|
269 |
+
"""
|
270 |
+
|
271 |
+
processor: AutoProcessor
|
272 |
+
padding: Union[bool, str] = "longest"
|
273 |
+
pad_to_multiple_of: Optional[int] = None
|
274 |
+
pad_to_multiple_of_labels: Optional[int] = None
|
275 |
+
|
276 |
+
def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:
|
277 |
+
# split inputs and labels since they have to be of different lenghts and need
|
278 |
+
# different padding methods
|
279 |
+
input_features = [{"input_values": feature["input_values"]} for feature in features]
|
280 |
+
label_features = [{"input_ids": feature["labels"]} for feature in features]
|
281 |
+
|
282 |
+
batch = self.processor.pad(
|
283 |
+
input_features,
|
284 |
+
padding=self.padding,
|
285 |
+
pad_to_multiple_of=self.pad_to_multiple_of,
|
286 |
+
return_tensors="pt",
|
287 |
+
)
|
288 |
+
|
289 |
+
with self.processor.as_target_processor():
|
290 |
+
labels_batch = self.processor.pad(
|
291 |
+
label_features,
|
292 |
+
padding=self.padding,
|
293 |
+
pad_to_multiple_of=self.pad_to_multiple_of_labels,
|
294 |
+
return_tensors="pt",
|
295 |
+
)
|
296 |
+
|
297 |
+
# replace padding with -100 to ignore loss correctly
|
298 |
+
labels = labels_batch["input_ids"].masked_fill(labels_batch.attention_mask.ne(1), -100)
|
299 |
+
|
300 |
+
batch["labels"] = labels
|
301 |
+
|
302 |
+
return batch
|
303 |
+
|
304 |
+
|
305 |
+
def create_vocabulary_from_data(
|
306 |
+
datasets: DatasetDict,
|
307 |
+
word_delimiter_token: Optional[str] = None,
|
308 |
+
unk_token: Optional[str] = None,
|
309 |
+
pad_token: Optional[str] = None,
|
310 |
+
):
|
311 |
+
# Given training and test labels create vocabulary
|
312 |
+
def extract_all_chars(batch):
|
313 |
+
all_text = " ".join(batch["target_text"])
|
314 |
+
vocab = list(set(all_text))
|
315 |
+
return {"vocab": [vocab], "all_text": [all_text]}
|
316 |
+
|
317 |
+
vocabs = datasets.map(
|
318 |
+
extract_all_chars,
|
319 |
+
batched=True,
|
320 |
+
batch_size=-1,
|
321 |
+
keep_in_memory=True,
|
322 |
+
remove_columns=datasets["train"].column_names,
|
323 |
+
)
|
324 |
+
|
325 |
+
# take union of all unique characters in each dataset
|
326 |
+
vocab_set = functools.reduce(
|
327 |
+
lambda vocab_1, vocab_2: set(vocab_1["vocab"][0]) | set(vocab_2["vocab"][0]), vocabs.values()
|
328 |
+
)
|
329 |
+
|
330 |
+
vocab_dict = {v: k for k, v in enumerate(sorted(list(vocab_set)))}
|
331 |
+
|
332 |
+
# replace white space with delimiter token
|
333 |
+
if word_delimiter_token is not None:
|
334 |
+
vocab_dict[word_delimiter_token] = vocab_dict[" "]
|
335 |
+
del vocab_dict[" "]
|
336 |
+
|
337 |
+
# add unk and pad token
|
338 |
+
if unk_token is not None:
|
339 |
+
vocab_dict[unk_token] = len(vocab_dict)
|
340 |
+
|
341 |
+
if pad_token is not None:
|
342 |
+
vocab_dict[pad_token] = len(vocab_dict)
|
343 |
+
|
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 |
+
# Pre-processing dataset
|
397 |
+
import re
|
398 |
+
def filter_numeric(entry):
|
399 |
+
return (
|
400 |
+
"0" not in entry["text"]
|
401 |
+
and "1" not in entry["text"]
|
402 |
+
and "2" not in entry["text"]
|
403 |
+
and "3" not in entry["text"]
|
404 |
+
and "4" not in entry["text"]
|
405 |
+
and "5" not in entry["text"]
|
406 |
+
and "6" not in entry["text"]
|
407 |
+
and "7" not in entry["text"]
|
408 |
+
and "8" not in entry["text"]
|
409 |
+
and "9" not in entry["text"]
|
410 |
+
)
|
411 |
+
|
412 |
+
def filter_inaudible(entry):
|
413 |
+
return not re.search("\d|<inaudible>", entry["text"], flags=re.IGNORECASE)
|
414 |
+
|
415 |
+
#def filter_nynorsk(entry):
|
416 |
+
# return re.search("nb-no", entry["sentence_language_code"], flags=re.IGNORECASE)
|
417 |
+
|
418 |
+
def filter_tooshort(entry):
|
419 |
+
#print(f"The audio sample ({entry["audio"]["path"]}) is too small, and has been omitted. "
|
420 |
+
return (len(entry["text"]) <= len(entry["audio"]["array"]) // 320) and (len(entry["text"].strip()) >= 3)
|
421 |
+
|
422 |
+
def map_dataset(entry):
|
423 |
+
batch = {"text": entry["text"].lower()}
|
424 |
+
batch["text"] = re.sub('[áàâ]', 'a', batch["text"])
|
425 |
+
batch["text"] = re.sub('[ä]', 'æ', batch["text"])
|
426 |
+
batch["text"] = re.sub('[éèëê]', 'e', batch["text"])
|
427 |
+
batch["text"] = re.sub('[íìïî]', 'i', batch["text"])
|
428 |
+
batch["text"] = re.sub('[óòöô]', 'o', batch["text"])
|
429 |
+
batch["text"] = re.sub('[ö]', 'ø', batch["text"])
|
430 |
+
batch["text"] = re.sub('[ç]', 'c', batch["text"])
|
431 |
+
batch["text"] = re.sub('[úùüû]', 'u', batch["text"])
|
432 |
+
batch["text"] = re.sub('\s', ' ', batch["text"])
|
433 |
+
batch["text"] = re.sub('<ee>', 'eee', batch["text"])
|
434 |
+
batch["text"] = re.sub('<qq>', 'qqq', batch["text"])
|
435 |
+
batch["text"] = re.sub('<mm>', 'mmm', batch["text"])
|
436 |
+
# batch["text"] = re.sub('<inaudible>', '?', batch["text"])
|
437 |
+
if "<" in batch["text"]:
|
438 |
+
raise ValueError(batch["text"])
|
439 |
+
return batch
|
440 |
+
|
441 |
+
# 1. First, let's load the dataset
|
442 |
+
raw_datasets = DatasetDict()
|
443 |
+
|
444 |
+
if training_args.do_train:
|
445 |
+
raw_datasets["train"] = load_dataset(
|
446 |
+
data_args.dataset_name,
|
447 |
+
data_args.dataset_config_name,
|
448 |
+
split=data_args.train_split_name,
|
449 |
+
use_auth_token=data_args.use_auth_token,
|
450 |
+
).shuffle()
|
451 |
+
raw_datasets["train"] = raw_datasets["train"].filter(filter_numeric).filter(filter_inaudible).filter(filter_tooshort)
|
452 |
+
raw_datasets["train"] = raw_datasets["train"].map(map_dataset)
|
453 |
+
|
454 |
+
if data_args.audio_column_name not in raw_datasets["train"].column_names:
|
455 |
+
raise ValueError(
|
456 |
+
f"--audio_column_name '{data_args.audio_column_name}' not found in dataset '{data_args.dataset_name}'. "
|
457 |
+
"Make sure to set `--audio_column_name` to the correct audio column - one of "
|
458 |
+
f"{', '.join(raw_datasets['train'].column_names)}."
|
459 |
+
)
|
460 |
+
|
461 |
+
if data_args.text_column_name not in raw_datasets["train"].column_names:
|
462 |
+
raise ValueError(
|
463 |
+
f"--text_column_name {data_args.text_column_name} not found in dataset '{data_args.dataset_name}'. "
|
464 |
+
"Make sure to set `--text_column_name` to the correct text column - one of "
|
465 |
+
f"{', '.join(raw_datasets['train'].column_names)}."
|
466 |
+
)
|
467 |
+
|
468 |
+
if data_args.max_train_samples is not None:
|
469 |
+
raw_datasets["train"] = raw_datasets["train"].select(range(data_args.max_train_samples))
|
470 |
+
|
471 |
+
if training_args.do_eval:
|
472 |
+
raw_datasets["eval"] = load_dataset(
|
473 |
+
data_args.dataset_name,
|
474 |
+
data_args.dataset_config_name,
|
475 |
+
split=data_args.eval_split_name,
|
476 |
+
use_auth_token=data_args.use_auth_token,
|
477 |
+
).shuffle()
|
478 |
+
raw_datasets["eval"] = raw_datasets["eval"].filter(filter_numeric).filter(filter_inaudible).filter(filter_tooshort)
|
479 |
+
raw_datasets["eval"] = raw_datasets["eval"].map(map_dataset)
|
480 |
+
|
481 |
+
if data_args.max_eval_samples is not None:
|
482 |
+
raw_datasets["eval"] = raw_datasets["eval"].select(range(data_args.max_eval_samples))
|
483 |
+
|
484 |
+
|
485 |
+
# 2. We remove some special characters from the datasets
|
486 |
+
# that make training complicated and do not help in transcribing the speech
|
487 |
+
# E.g. characters, such as `,` and `.` do not really have an acoustic characteristic
|
488 |
+
# that could be easily picked up by the model
|
489 |
+
#chars_to_ignore_regex = (
|
490 |
+
# f'[{"".join(data_args.chars_to_ignore)}]' if data_args.chars_to_ignore is not None else None
|
491 |
+
#)
|
492 |
+
chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�\'\–\_\\\+\#\/]'
|
493 |
+
|
494 |
+
text_column_name = data_args.text_column_name
|
495 |
+
|
496 |
+
def remove_special_characters(batch):
|
497 |
+
if chars_to_ignore_regex is not None:
|
498 |
+
batch["target_text"] = re.sub(chars_to_ignore_regex, "", batch[text_column_name]).lower() + " "
|
499 |
+
else:
|
500 |
+
batch["target_text"] = batch[text_column_name].lower() + " "
|
501 |
+
return batch
|
502 |
+
|
503 |
+
with training_args.main_process_first(desc="dataset map special characters removal"):
|
504 |
+
raw_datasets = raw_datasets.map(
|
505 |
+
remove_special_characters,
|
506 |
+
remove_columns=[text_column_name],
|
507 |
+
desc="remove special characters from datasets",
|
508 |
+
)
|
509 |
+
|
510 |
+
# save special tokens for tokenizer
|
511 |
+
word_delimiter_token = data_args.word_delimiter_token
|
512 |
+
unk_token = data_args.unk_token
|
513 |
+
pad_token = data_args.pad_token
|
514 |
+
|
515 |
+
# 3. Next, let's load the config as we might need it to create
|
516 |
+
# the tokenizer
|
517 |
+
# load config
|
518 |
+
config = AutoConfig.from_pretrained(
|
519 |
+
model_args.model_name_or_path, cache_dir=model_args.cache_dir, use_auth_token=data_args.use_auth_token
|
520 |
+
)
|
521 |
+
|
522 |
+
# 4. Next, if no tokenizer file is defined,
|
523 |
+
# we create the vocabulary of the model by extracting all unique characters from
|
524 |
+
# the training and evaluation datasets
|
525 |
+
# We need to make sure that only first rank saves vocabulary
|
526 |
+
# make sure all processes wait until vocab is created
|
527 |
+
tokenizer_name_or_path = model_args.tokenizer_name_or_path
|
528 |
+
tokenizer_kwargs = {}
|
529 |
+
if tokenizer_name_or_path is None:
|
530 |
+
# save vocab in training output dir
|
531 |
+
tokenizer_name_or_path = training_args.output_dir
|
532 |
+
|
533 |
+
vocab_file = os.path.join(tokenizer_name_or_path, "vocab.json")
|
534 |
+
|
535 |
+
with training_args.main_process_first():
|
536 |
+
if training_args.overwrite_output_dir and os.path.isfile(vocab_file):
|
537 |
+
os.remove(vocab_file)
|
538 |
+
|
539 |
+
with training_args.main_process_first(desc="dataset map vocabulary creation"):
|
540 |
+
if not os.path.isfile(vocab_file):
|
541 |
+
os.makedirs(tokenizer_name_or_path, exist_ok=True)
|
542 |
+
vocab_dict = create_vocabulary_from_data(
|
543 |
+
raw_datasets,
|
544 |
+
word_delimiter_token=word_delimiter_token,
|
545 |
+
unk_token=unk_token,
|
546 |
+
pad_token=pad_token,
|
547 |
+
)
|
548 |
+
|
549 |
+
# save vocab dict to be loaded into tokenizer
|
550 |
+
with open(vocab_file, "w") as file:
|
551 |
+
json.dump(vocab_dict, file)
|
552 |
+
|
553 |
+
# if tokenizer has just been created
|
554 |
+
# it is defined by `tokenizer_class` if present in config else by `model_type`
|
555 |
+
tokenizer_kwargs = {
|
556 |
+
"config": config if config.tokenizer_class is not None else None,
|
557 |
+
"tokenizer_type": config.model_type if config.tokenizer_class is None else None,
|
558 |
+
"unk_token": unk_token,
|
559 |
+
"pad_token": pad_token,
|
560 |
+
"word_delimiter_token": word_delimiter_token,
|
561 |
+
}
|
562 |
+
|
563 |
+
# 5. Now we can instantiate the feature extractor, tokenizer and model
|
564 |
+
# Note for distributed training, the .from_pretrained methods guarantee that only
|
565 |
+
# one local process can concurrently download model & vocab.
|
566 |
+
|
567 |
+
# load feature_extractor and tokenizer
|
568 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
569 |
+
tokenizer_name_or_path,
|
570 |
+
use_auth_token=data_args.use_auth_token,
|
571 |
+
**tokenizer_kwargs,
|
572 |
+
)
|
573 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(
|
574 |
+
model_args.model_name_or_path, cache_dir=model_args.cache_dir, use_auth_token=data_args.use_auth_token
|
575 |
+
)
|
576 |
+
|
577 |
+
# adapt config
|
578 |
+
config.update(
|
579 |
+
{
|
580 |
+
"feat_proj_dropout": model_args.feat_proj_dropout,
|
581 |
+
"attention_dropout": model_args.attention_dropout,
|
582 |
+
"hidden_dropout": model_args.hidden_dropout,
|
583 |
+
"final_dropout": model_args.final_dropout,
|
584 |
+
"mask_time_prob": model_args.mask_time_prob,
|
585 |
+
"mask_time_length": model_args.mask_time_length,
|
586 |
+
"mask_feature_prob": model_args.mask_feature_prob,
|
587 |
+
"mask_feature_length": model_args.mask_feature_length,
|
588 |
+
"gradient_checkpointing": training_args.gradient_checkpointing,
|
589 |
+
"layerdrop": model_args.layerdrop,
|
590 |
+
"ctc_loss_reduction": model_args.ctc_loss_reduction,
|
591 |
+
"ctc_zero_infinity": model_args.ctc_zero_infinity,
|
592 |
+
"pad_token_id": tokenizer.pad_token_id,
|
593 |
+
"vocab_size": len(tokenizer),
|
594 |
+
"activation_dropout": model_args.activation_dropout,
|
595 |
+
}
|
596 |
+
)
|
597 |
+
|
598 |
+
# create model
|
599 |
+
model = AutoModelForCTC.from_pretrained(
|
600 |
+
model_args.model_name_or_path,
|
601 |
+
cache_dir=model_args.cache_dir,
|
602 |
+
config=config,
|
603 |
+
use_auth_token=data_args.use_auth_token,
|
604 |
+
)
|
605 |
+
|
606 |
+
# freeze encoder
|
607 |
+
if model_args.freeze_feature_encoder:
|
608 |
+
model.freeze_feature_encoder()
|
609 |
+
|
610 |
+
# 6. Now we preprocess the datasets including loading the audio, resampling and normalization
|
611 |
+
# Thankfully, `datasets` takes care of automatically loading and resampling the audio,
|
612 |
+
# so that we just need to set the correct target sampling rate and normalize the input
|
613 |
+
# via the `feature_extractor`
|
614 |
+
|
615 |
+
# make sure that dataset decodes audio with correct sampling rate
|
616 |
+
dataset_sampling_rate = next(iter(raw_datasets.values())).features[data_args.audio_column_name].sampling_rate
|
617 |
+
if dataset_sampling_rate != feature_extractor.sampling_rate:
|
618 |
+
raw_datasets = raw_datasets.cast_column(
|
619 |
+
data_args.audio_column_name, datasets.features.Audio(sampling_rate=feature_extractor.sampling_rate)
|
620 |
+
)
|
621 |
+
|
622 |
+
# derive max & min input length for sample rate & max duration
|
623 |
+
max_input_length = data_args.max_duration_in_seconds * feature_extractor.sampling_rate
|
624 |
+
min_input_length = data_args.min_duration_in_seconds * feature_extractor.sampling_rate
|
625 |
+
audio_column_name = data_args.audio_column_name
|
626 |
+
num_workers = data_args.preprocessing_num_workers
|
627 |
+
|
628 |
+
# `phoneme_language` is only relevant if the model is fine-tuned on phoneme classification
|
629 |
+
phoneme_language = data_args.phoneme_language
|
630 |
+
|
631 |
+
# Preprocessing the datasets.
|
632 |
+
# We need to read the audio files as arrays and tokenize the targets.
|
633 |
+
def prepare_dataset(batch):
|
634 |
+
# load audio
|
635 |
+
sample = batch[audio_column_name]
|
636 |
+
|
637 |
+
inputs = feature_extractor(sample["array"], sampling_rate=sample["sampling_rate"])
|
638 |
+
batch["input_values"] = inputs.input_values[0]
|
639 |
+
batch["input_length"] = len(batch["input_values"])
|
640 |
+
|
641 |
+
# encode targets
|
642 |
+
additional_kwargs = {}
|
643 |
+
if phoneme_language is not None:
|
644 |
+
additional_kwargs["phonemizer_lang"] = phoneme_language
|
645 |
+
|
646 |
+
batch["labels"] = tokenizer(batch["target_text"], **additional_kwargs).input_ids
|
647 |
+
return batch
|
648 |
+
|
649 |
+
with training_args.main_process_first(desc="dataset map preprocessing"):
|
650 |
+
vectorized_datasets = raw_datasets.map(
|
651 |
+
prepare_dataset,
|
652 |
+
remove_columns=next(iter(raw_datasets.values())).column_names,
|
653 |
+
num_proc=num_workers,
|
654 |
+
desc="preprocess datasets",
|
655 |
+
)
|
656 |
+
|
657 |
+
def is_audio_in_length_range(length):
|
658 |
+
return length > min_input_length and length < max_input_length
|
659 |
+
|
660 |
+
# filter data that is shorter than min_input_length
|
661 |
+
vectorized_datasets = vectorized_datasets.filter(
|
662 |
+
is_audio_in_length_range,
|
663 |
+
num_proc=num_workers,
|
664 |
+
input_columns=["input_length"],
|
665 |
+
)
|
666 |
+
|
667 |
+
# 7. Next, we can prepare the training.
|
668 |
+
# Let's use word error rate (WER) as our evaluation metric,
|
669 |
+
# instantiate a data collator and the trainer
|
670 |
+
|
671 |
+
# Define evaluation metrics during training, *i.e.* word error rate, character error rate
|
672 |
+
eval_metrics = {metric: load_metric(metric) for metric in data_args.eval_metrics}
|
673 |
+
|
674 |
+
# for large datasets it is advised to run the preprocessing on a
|
675 |
+
# single machine first with ``args.preprocessing_only`` since there will mostly likely
|
676 |
+
# be a timeout when running the script in distributed mode.
|
677 |
+
# In a second step ``args.preprocessing_only`` can then be set to `False` to load the
|
678 |
+
# cached dataset
|
679 |
+
if data_args.preprocessing_only:
|
680 |
+
logger.info(f"Data preprocessing finished. Files cached at {vectorized_datasets.cache_files}")
|
681 |
+
return
|
682 |
+
|
683 |
+
def compute_metrics(pred):
|
684 |
+
pred_logits = pred.predictions
|
685 |
+
pred_ids = np.argmax(pred_logits, axis=-1)
|
686 |
+
|
687 |
+
pred.label_ids[pred.label_ids == -100] = tokenizer.pad_token_id
|
688 |
+
|
689 |
+
pred_str = tokenizer.batch_decode(pred_ids)
|
690 |
+
# we do not want to group tokens when computing the metrics
|
691 |
+
label_str = tokenizer.batch_decode(pred.label_ids, group_tokens=False)
|
692 |
+
|
693 |
+
metrics = {k: v.compute(predictions=pred_str, references=label_str) for k, v in eval_metrics.items()}
|
694 |
+
|
695 |
+
return metrics
|
696 |
+
|
697 |
+
# Now save everything to be able to create a single processor later
|
698 |
+
if is_main_process(training_args.local_rank):
|
699 |
+
# save feature extractor, tokenizer and config
|
700 |
+
feature_extractor.save_pretrained(training_args.output_dir)
|
701 |
+
tokenizer.save_pretrained(training_args.output_dir)
|
702 |
+
config.save_pretrained(training_args.output_dir)
|
703 |
+
|
704 |
+
try:
|
705 |
+
processor = AutoProcessor.from_pretrained(training_args.output_dir)
|
706 |
+
except (OSError, KeyError):
|
707 |
+
warnings.warn(
|
708 |
+
"Loading a processor from a feature extractor config that does not"
|
709 |
+
" include a `processor_class` attribute is deprecated and will be removed in v5. Please add the following "
|
710 |
+
" attribute to your `preprocessor_config.json` file to suppress this warning: "
|
711 |
+
" `'processor_class': 'Wav2Vec2Processor'`",
|
712 |
+
FutureWarning,
|
713 |
+
)
|
714 |
+
processor = Wav2Vec2Processor.from_pretrained(training_args.output_dir)
|
715 |
+
|
716 |
+
# Instantiate custom data collator
|
717 |
+
data_collator = DataCollatorCTCWithPadding(processor=processor)
|
718 |
+
|
719 |
+
# Initialize Trainer
|
720 |
+
trainer = Trainer(
|
721 |
+
model=model,
|
722 |
+
data_collator=data_collator,
|
723 |
+
args=training_args,
|
724 |
+
compute_metrics=compute_metrics,
|
725 |
+
train_dataset=vectorized_datasets["train"] if training_args.do_train else None,
|
726 |
+
eval_dataset=vectorized_datasets["eval"] if training_args.do_eval else None,
|
727 |
+
tokenizer=feature_extractor,
|
728 |
+
)
|
729 |
+
|
730 |
+
# 8. Finally, we can start training
|
731 |
+
|
732 |
+
# Training
|
733 |
+
if training_args.do_train:
|
734 |
+
|
735 |
+
# use last checkpoint if exist
|
736 |
+
if last_checkpoint is not None:
|
737 |
+
checkpoint = last_checkpoint
|
738 |
+
elif os.path.isdir(model_args.model_name_or_path):
|
739 |
+
checkpoint = model_args.model_name_or_path
|
740 |
+
else:
|
741 |
+
checkpoint = None
|
742 |
+
|
743 |
+
train_result = trainer.train(resume_from_checkpoint=checkpoint)
|
744 |
+
trainer.save_model()
|
745 |
+
|
746 |
+
metrics = train_result.metrics
|
747 |
+
max_train_samples = (
|
748 |
+
data_args.max_train_samples
|
749 |
+
if data_args.max_train_samples is not None
|
750 |
+
else len(vectorized_datasets["train"])
|
751 |
+
)
|
752 |
+
metrics["train_samples"] = min(max_train_samples, len(vectorized_datasets["train"]))
|
753 |
+
|
754 |
+
trainer.log_metrics("train", metrics)
|
755 |
+
trainer.save_metrics("train", metrics)
|
756 |
+
trainer.save_state()
|
757 |
+
|
758 |
+
# Evaluation
|
759 |
+
results = {}
|
760 |
+
if training_args.do_eval:
|
761 |
+
logger.info("*** Evaluate ***")
|
762 |
+
metrics = trainer.evaluate()
|
763 |
+
max_eval_samples = (
|
764 |
+
data_args.max_eval_samples if data_args.max_eval_samples is not None else len(vectorized_datasets["eval"])
|
765 |
+
)
|
766 |
+
metrics["eval_samples"] = min(max_eval_samples, len(vectorized_datasets["eval"]))
|
767 |
+
|
768 |
+
trainer.log_metrics("eval", metrics)
|
769 |
+
trainer.save_metrics("eval", metrics)
|
770 |
+
|
771 |
+
# Write model card and (optionally) push to hub
|
772 |
+
config_name = data_args.dataset_config_name if data_args.dataset_config_name is not None else "na"
|
773 |
+
kwargs = {
|
774 |
+
"finetuned_from": model_args.model_name_or_path,
|
775 |
+
"tasks": "speech-recognition",
|
776 |
+
"tags": ["automatic-speech-recognition", data_args.dataset_name],
|
777 |
+
"dataset_args": f"Config: {config_name}, Training split: {data_args.train_split_name}, Eval split: {data_args.eval_split_name}",
|
778 |
+
"dataset": f"{data_args.dataset_name.upper()} - {config_name.upper()}",
|
779 |
+
}
|
780 |
+
if "common_voice" in data_args.dataset_name:
|
781 |
+
kwargs["language"] = config_name
|
782 |
+
|
783 |
+
if training_args.push_to_hub:
|
784 |
+
trainer.push_to_hub(**kwargs)
|
785 |
+
else:
|
786 |
+
trainer.create_model_card(**kwargs)
|
787 |
+
|
788 |
+
return results
|
789 |
+
|
790 |
+
|
791 |
+
if __name__ == "__main__":
|
792 |
+
main()
|
runs/Feb04_12-19-59_dante/1643973630.5333126/events.out.tfevents.1643973630.dante.1786377.1
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:102d4a9860ed99fb120d6b61b95f00e0e274e6481585e1e630824a6b75940f95
|
3 |
+
size 4765
|
runs/Feb04_12-19-59_dante/events.out.tfevents.1643973630.dante.1786377.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:48a422de8738b9c59fa5e4bc553d5b0167e3b63a95af435473a699f5b81aa178
|
3 |
+
size 52574
|
runs/Feb05_11-55-40_dante/1644058575.319772/events.out.tfevents.1644058575.dante.2573362.1
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:956f52ac1957263e06ed215d081ab32f3b0e5a37d3abf6613fbf63b0e1e5d732
|
3 |
+
size 4765
|
runs/Feb05_11-55-40_dante/events.out.tfevents.1644058575.dante.2573362.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4ed0c086f730c38fc09d64f5ffafdcefd8d80c2a6cc2cf5adabbf7b7255345a3
|
3 |
+
size 10165
|
runs/Feb05_11-55-40_dante/events.out.tfevents.1644066583.dante.2573362.2
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c5e49ff79ccc0ad21eb2833b98a8f46f3dd861968bd63986f8da5f15ddc0a81f
|
3 |
+
size 358
|
runs/Feb06_00-33-18_dante/1644104059.4582894/events.out.tfevents.1644104059.dante.2706942.1
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:adc02f1aa0c8de2f18a4eb7567614d49955912b374acf7bb2d7d4402b22715a2
|
3 |
+
size 4765
|
runs/Feb06_00-33-18_dante/events.out.tfevents.1644104059.dante.2706942.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:be31c7c9940fea61350188c3c5852d842fea96dfcf4b1e3d73fef55dc677c878
|
3 |
+
size 34596
|
runs/Feb06_12-59-06_dante/1644148807.511835/events.out.tfevents.1644148807.dante.2790531.1
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:de29a2a4263b81525551cc6a8648135a9470f06fdbc742c6b46db893fe00ab19
|
3 |
+
size 4765
|
runs/Feb06_12-59-06_dante/events.out.tfevents.1644148807.dante.2790531.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b4bd6d012fbd254fed1b5d06c38715b576b2c2c5bb7dd25ae0428906ff3fa494
|
3 |
+
size 5285
|
runs/Feb06_13-01-43_dante/1644148960.1271484/events.out.tfevents.1644148960.dante.2793694.1
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:da37a286fbcdc1d8756d26fc45a4cc591b00979834d1e0ef7fecffb5d808b7ca
|
3 |
+
size 4765
|
runs/Feb06_13-01-43_dante/events.out.tfevents.1644148960.dante.2793694.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dc132a43de8b7d0a6133ee02cc3bdb5eb32925d411ed9f1bdc793156b35c14a4
|
3 |
+
size 5285
|
runs/Feb06_13-01-43_dante/events.out.tfevents.1644149411.dante.2793694.2
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9395b424df11af082ef53c2069f670a722ff315edcd97097a68909cfcf8b1cb9
|
3 |
+
size 358
|
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}, {"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"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", "processor_class": "Wav2Vec2ProcessorWithLM"}
|
train_results.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"epoch": 1.5,
|
3 |
+
"train_loss": 0.0,
|
4 |
+
"train_runtime": 5.9011,
|
5 |
+
"train_samples": 49645,
|
6 |
+
"train_samples_per_second": 841.279,
|
7 |
+
"train_steps_per_second": 26.436
|
8 |
+
}
|
trainer_state.json
ADDED
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"best_metric": null,
|
3 |
+
"best_model_checkpoint": null,
|
4 |
+
"epoch": 1.5001611343860781,
|
5 |
+
"global_step": 2327,
|
6 |
+
"is_hyper_param_search": false,
|
7 |
+
"is_local_process_zero": true,
|
8 |
+
"is_world_process_zero": true,
|
9 |
+
"log_history": [
|
10 |
+
{
|
11 |
+
"epoch": 0.06,
|
12 |
+
"learning_rate": 8.01984817006747e-06,
|
13 |
+
"loss": 0.2478,
|
14 |
+
"step": 100
|
15 |
+
},
|
16 |
+
{
|
17 |
+
"epoch": 0.13,
|
18 |
+
"learning_rate": 7.659729258075218e-06,
|
19 |
+
"loss": 0.222,
|
20 |
+
"step": 200
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"epoch": 0.19,
|
24 |
+
"learning_rate": 7.303211535202886e-06,
|
25 |
+
"loss": 0.283,
|
26 |
+
"step": 300
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"epoch": 0.26,
|
30 |
+
"learning_rate": 6.943092623210635e-06,
|
31 |
+
"loss": 0.2102,
|
32 |
+
"step": 400
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"epoch": 0.32,
|
36 |
+
"learning_rate": 6.5829737112183816e-06,
|
37 |
+
"loss": 0.2127,
|
38 |
+
"step": 500
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"epoch": 0.32,
|
42 |
+
"eval_loss": 0.13347241282463074,
|
43 |
+
"eval_runtime": 385.6175,
|
44 |
+
"eval_samples_per_second": 14.099,
|
45 |
+
"eval_steps_per_second": 0.882,
|
46 |
+
"eval_wer": 0.1047094237500858,
|
47 |
+
"step": 500
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"epoch": 0.39,
|
51 |
+
"learning_rate": 6.222854799226128e-06,
|
52 |
+
"loss": 0.1923,
|
53 |
+
"step": 600
|
54 |
+
},
|
55 |
+
{
|
56 |
+
"epoch": 0.45,
|
57 |
+
"learning_rate": 5.862735887233875e-06,
|
58 |
+
"loss": 0.2001,
|
59 |
+
"step": 700
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"epoch": 0.52,
|
63 |
+
"learning_rate": 5.502616975241623e-06,
|
64 |
+
"loss": 0.199,
|
65 |
+
"step": 800
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"epoch": 0.58,
|
69 |
+
"learning_rate": 5.14249806324937e-06,
|
70 |
+
"loss": 0.1944,
|
71 |
+
"step": 900
|
72 |
+
},
|
73 |
+
{
|
74 |
+
"epoch": 0.64,
|
75 |
+
"learning_rate": 4.782379151257117e-06,
|
76 |
+
"loss": 0.1976,
|
77 |
+
"step": 1000
|
78 |
+
},
|
79 |
+
{
|
80 |
+
"epoch": 0.64,
|
81 |
+
"eval_loss": 0.1308828443288803,
|
82 |
+
"eval_runtime": 385.5506,
|
83 |
+
"eval_samples_per_second": 14.102,
|
84 |
+
"eval_steps_per_second": 0.882,
|
85 |
+
"eval_wer": 0.10391520487905322,
|
86 |
+
"step": 1000
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"epoch": 0.71,
|
90 |
+
"learning_rate": 4.422260239264865e-06,
|
91 |
+
"loss": 0.1845,
|
92 |
+
"step": 1100
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"epoch": 0.77,
|
96 |
+
"learning_rate": 4.062141327272612e-06,
|
97 |
+
"loss": 0.1885,
|
98 |
+
"step": 1200
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"epoch": 0.84,
|
102 |
+
"learning_rate": 3.7020224152803586e-06,
|
103 |
+
"loss": 0.1799,
|
104 |
+
"step": 1300
|
105 |
+
},
|
106 |
+
{
|
107 |
+
"epoch": 0.9,
|
108 |
+
"learning_rate": 3.3419035032881062e-06,
|
109 |
+
"loss": 0.1749,
|
110 |
+
"step": 1400
|
111 |
+
},
|
112 |
+
{
|
113 |
+
"epoch": 0.97,
|
114 |
+
"learning_rate": 2.981784591295853e-06,
|
115 |
+
"loss": 0.1887,
|
116 |
+
"step": 1500
|
117 |
+
},
|
118 |
+
{
|
119 |
+
"epoch": 0.97,
|
120 |
+
"eval_loss": 0.13062627613544464,
|
121 |
+
"eval_runtime": 383.0748,
|
122 |
+
"eval_samples_per_second": 14.193,
|
123 |
+
"eval_steps_per_second": 0.888,
|
124 |
+
"eval_wer": 0.104032866934021,
|
125 |
+
"step": 1500
|
126 |
+
},
|
127 |
+
{
|
128 |
+
"epoch": 1.03,
|
129 |
+
"learning_rate": 2.6216656793036003e-06,
|
130 |
+
"loss": 0.1917,
|
131 |
+
"step": 1600
|
132 |
+
},
|
133 |
+
{
|
134 |
+
"epoch": 1.1,
|
135 |
+
"learning_rate": 2.261546767311348e-06,
|
136 |
+
"loss": 0.1737,
|
137 |
+
"step": 1700
|
138 |
+
},
|
139 |
+
{
|
140 |
+
"epoch": 1.16,
|
141 |
+
"learning_rate": 1.9014278553190947e-06,
|
142 |
+
"loss": 0.1758,
|
143 |
+
"step": 1800
|
144 |
+
},
|
145 |
+
{
|
146 |
+
"epoch": 1.22,
|
147 |
+
"learning_rate": 1.541308943326842e-06,
|
148 |
+
"loss": 0.174,
|
149 |
+
"step": 1900
|
150 |
+
},
|
151 |
+
{
|
152 |
+
"epoch": 1.29,
|
153 |
+
"learning_rate": 1.181190031334589e-06,
|
154 |
+
"loss": 0.18,
|
155 |
+
"step": 2000
|
156 |
+
},
|
157 |
+
{
|
158 |
+
"epoch": 1.29,
|
159 |
+
"eval_loss": 0.13111014664173126,
|
160 |
+
"eval_runtime": 382.6746,
|
161 |
+
"eval_samples_per_second": 14.208,
|
162 |
+
"eval_steps_per_second": 0.888,
|
163 |
+
"eval_wer": 0.10379754282408542,
|
164 |
+
"step": 2000
|
165 |
+
},
|
166 |
+
{
|
167 |
+
"epoch": 1.35,
|
168 |
+
"learning_rate": 8.210711193423363e-07,
|
169 |
+
"loss": 0.1667,
|
170 |
+
"step": 2100
|
171 |
+
},
|
172 |
+
{
|
173 |
+
"epoch": 1.42,
|
174 |
+
"learning_rate": 4.609522073500836e-07,
|
175 |
+
"loss": 0.1774,
|
176 |
+
"step": 2200
|
177 |
+
},
|
178 |
+
{
|
179 |
+
"epoch": 1.48,
|
180 |
+
"learning_rate": 1.0083329535783077e-07,
|
181 |
+
"loss": 0.1779,
|
182 |
+
"step": 2300
|
183 |
+
},
|
184 |
+
{
|
185 |
+
"epoch": 1.5,
|
186 |
+
"step": 2327,
|
187 |
+
"total_flos": 1.6280526756920635e+19,
|
188 |
+
"train_loss": 0.19505117766376623,
|
189 |
+
"train_runtime": 7387.6715,
|
190 |
+
"train_samples_per_second": 10.08,
|
191 |
+
"train_steps_per_second": 0.315
|
192 |
+
},
|
193 |
+
{
|
194 |
+
"epoch": 1.5,
|
195 |
+
"step": 2327,
|
196 |
+
"total_flos": 1.6280526756920635e+19,
|
197 |
+
"train_loss": 0.0,
|
198 |
+
"train_runtime": 12.046,
|
199 |
+
"train_samples_per_second": 412.128,
|
200 |
+
"train_steps_per_second": 6.475
|
201 |
+
},
|
202 |
+
{
|
203 |
+
"epoch": 1.5,
|
204 |
+
"step": 2327,
|
205 |
+
"total_flos": 1.6280526756920635e+19,
|
206 |
+
"train_loss": 0.0,
|
207 |
+
"train_runtime": 5.9011,
|
208 |
+
"train_samples_per_second": 841.279,
|
209 |
+
"train_steps_per_second": 26.436
|
210 |
+
}
|
211 |
+
],
|
212 |
+
"max_steps": 156,
|
213 |
+
"num_train_epochs": 1,
|
214 |
+
"total_flos": 1.6280526756920635e+19,
|
215 |
+
"trial_name": null,
|
216 |
+
"trial_params": null
|
217 |
+
}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cba0407afeb94e5c61fb60760555d3e67958b71b4ae430dc28c3be8ab33d4a2d
|
3 |
+
size 3055
|
vocab.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26, "å": 27, "æ": 28, "ø": 29, "|": 0, "[UNK]": 30, "[PAD]": 31}
|