Za6na commited on
Commit
2b287a4
·
verified ·
1 Parent(s): 240e0b0

Copying full model from Akashpb13 including all logs and scripts

Browse files
README.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - ckb
4
+ license: apache-2.0
5
+ tags:
6
+ - automatic-speech-recognition
7
+ - mozilla-foundation/common_voice_8_0
8
+ - generated_from_trainer
9
+ - ckb
10
+ - robust-speech-event
11
+ - model_for_talk
12
+ - hf-asr-leaderboard
13
+ datasets:
14
+ - mozilla-foundation/common_voice_8_0
15
+ model-index:
16
+ - name: Akashpb13/Central_kurdish_xlsr
17
+ results:
18
+ - task:
19
+ name: Automatic Speech Recognition
20
+ type: automatic-speech-recognition
21
+ dataset:
22
+ name: Common Voice 8
23
+ type: mozilla-foundation/common_voice_8_0
24
+ args: ckb
25
+ metrics:
26
+ - name: Test WER
27
+ type: wer
28
+ value: 0.36754389884276845
29
+ - name: Test CER
30
+ type: cer
31
+ value: 0.07827896768334217
32
+ - task:
33
+ name: Automatic Speech Recognition
34
+ type: automatic-speech-recognition
35
+ dataset:
36
+ name: Robust Speech Event - Dev Data
37
+ type: speech-recognition-community-v2/dev_data
38
+ args: ckb
39
+ metrics:
40
+ - name: Test WER
41
+ type: wer
42
+ value: 0.36754389884276845
43
+ - name: Test CER
44
+ type: cer
45
+ value: 0.07827896768334217
46
+ ---
47
+
48
+ # Akashpb13/Central_kurdish_xlsr
49
+
50
+ This model is a fine-tuned version of [facebook/wav2vec2-xls-r-300m](https://huggingface.co/facebook/wav2vec2-xls-r-300m) on the MOZILLA-FOUNDATION/COMMON_VOICE_7_0 - hu dataset.
51
+ It achieves the following results on evaluation set (which is 10 percent of train data set merged with invalidated data, reported, other and dev datasets):
52
+ - Loss: 0.348580
53
+ - Wer: 0.401147
54
+
55
+ ## Model description
56
+ "facebook/wav2vec2-xls-r-300m" was finetuned.
57
+
58
+ ## Intended uses & limitations
59
+ More information needed
60
+ ## Training and evaluation data
61
+ Training data -
62
+ Common voice Central Kurdish train.tsv, dev.tsv, invalidated.tsv, reported.tsv, and other.tsv
63
+ Only those points were considered where upvotes were greater than downvotes and duplicates were removed after concatenation of all the datasets given in common voice 7.0
64
+
65
+ ## Training procedure
66
+ For creating the train dataset, all possible datasets were appended and 90-10 split was used.
67
+
68
+ ### Training hyperparameters
69
+
70
+ The following hyperparameters were used during training:
71
+
72
+ - learning_rate: 0.000095637994662983496
73
+ - train_batch_size: 16
74
+ - eval_batch_size: 16
75
+ - seed: 13
76
+ - gradient_accumulation_steps: 2
77
+ - lr_scheduler_type: cosine_with_restarts
78
+ - lr_scheduler_warmup_steps: 200
79
+ - num_epochs: 100
80
+ - mixed_precision_training: Native AMP
81
+
82
+
83
+ ### Training results
84
+
85
+ | Step | Training Loss | Validation Loss | Wer |
86
+ |-------|---------------|-----------------|----------|
87
+ | 500 | 5.097800 | 2.190326 | 1.001207 |
88
+ | 1000 | 0.797500 | 0.331392 | 0.576819 |
89
+ | 1500 | 0.405100 | 0.262009 | 0.549049 |
90
+ | 2000 | 0.322100 | 0.248178 | 0.479626 |
91
+ | 2500 | 0.264600 | 0.258866 | 0.488983 |
92
+ | 3000 | 0.228300 | 0.261523 | 0.469665 |
93
+ | 3500 | 0.201000 | 0.270135 | 0.451856 |
94
+ | 4000 | 0.180900 | 0.279302 | 0.448536 |
95
+ | 4500 | 0.163800 | 0.280921 | 0.459704 |
96
+ | 5000 | 0.147300 | 0.319249 | 0.471778 |
97
+ | 5500 | 0.137600 | 0.289546 | 0.449140 |
98
+ | 6000 | 0.132000 | 0.311350 | 0.458195 |
99
+ | 6500 | 0.117100 | 0.316726 | 0.432840 |
100
+ | 7000 | 0.109200 | 0.302210 | 0.439481 |
101
+ | 7500 | 0.104900 | 0.325913 | 0.439481 |
102
+ | 8000 | 0.097500 | 0.329446 | 0.431935 |
103
+ | 8500 | 0.088600 | 0.345259 | 0.425898 |
104
+ | 9000 | 0.084900 | 0.342891 | 0.428313 |
105
+ | 9500 | 0.080900 | 0.353081 | 0.424389 |
106
+ | 10000 | 0.075600 | 0.347063 | 0.424992 |
107
+ | 10500 | 0.072800 | 0.330086 | 0.424691 |
108
+ | 11000 | 0.068100 | 0.350658 | 0.421974 |
109
+ | 11500 | 0.064700 | 0.342949 | 0.413522 |
110
+ | 12000 | 0.061500 | 0.341704 | 0.415334 |
111
+ | 12500 | 0.059500 | 0.346279 | 0.411410 |
112
+ | 13000 | 0.057400 | 0.349901 | 0.407184 |
113
+ | 13500 | 0.056400 | 0.347733 | 0.402656 |
114
+ | 14000 | 0.053300 | 0.344899 | 0.405976 |
115
+ | 14500 | 0.052900 | 0.346708 | 0.402656 |
116
+ | 15000 | 0.050600 | 0.344118 | 0.400845 |
117
+ | 15500 | 0.050200 | 0.348396 | 0.402958 |
118
+ | 16000 | 0.049800 | 0.348312 | 0.401751 |
119
+ | 16500 | 0.051900 | 0.348372 | 0.401147 |
120
+ | 17000 | 0.049800 | 0.348580 | 0.401147 |
121
+
122
+
123
+
124
+ ### Framework versions
125
+ - Transformers 4.16.0.dev0
126
+ - Pytorch 1.10.0+cu102
127
+ - Datasets 1.18.1
128
+ - Tokenizers 0.10.3
129
+
130
+ #### Evaluation Commands
131
+
132
+ 1. To evaluate on `mozilla-foundation/common_voice_8_0` with split `test`
133
+
134
+ ```bash
135
+ python eval.py --model_id Akashpb13/Central_kurdish_xlsr --dataset mozilla-foundation/common_voice_8_0 --config ckb --split test
136
+ ```
137
+
config.json ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "facebook/wav2vec2-xls-r-300m",
3
+ "activation_dropout": 0.05,
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.01,
12
+ "bos_token_id": 1,
13
+ "classifier_proj_size": 256,
14
+ "codevector_dim": 768,
15
+ "contrastive_logits_temperature": 0.1,
16
+ "conv_bias": true,
17
+ "conv_dim": [
18
+ 512,
19
+ 512,
20
+ 512,
21
+ 512,
22
+ 512,
23
+ 512,
24
+ 512
25
+ ],
26
+ "conv_kernel": [
27
+ 10,
28
+ 3,
29
+ 3,
30
+ 3,
31
+ 3,
32
+ 2,
33
+ 2
34
+ ],
35
+ "conv_stride": [
36
+ 5,
37
+ 2,
38
+ 2,
39
+ 2,
40
+ 2,
41
+ 2,
42
+ 2
43
+ ],
44
+ "ctc_loss_reduction": "mean",
45
+ "ctc_zero_infinity": false,
46
+ "diversity_loss_weight": 0.1,
47
+ "do_stable_layer_norm": true,
48
+ "eos_token_id": 2,
49
+ "feat_extract_activation": "gelu",
50
+ "feat_extract_dropout": 0.0,
51
+ "feat_extract_norm": "layer",
52
+ "feat_proj_dropout": 0.05,
53
+ "feat_quantizer_dropout": 0.0,
54
+ "final_dropout": 0.0,
55
+ "hidden_act": "gelu",
56
+ "hidden_dropout": 0.05,
57
+ "hidden_size": 1024,
58
+ "initializer_range": 0.02,
59
+ "intermediate_size": 4096,
60
+ "layer_norm_eps": 1e-05,
61
+ "layerdrop": 0.05,
62
+ "mask_feature_length": 10,
63
+ "mask_feature_min_masks": 0,
64
+ "mask_feature_prob": 0.0,
65
+ "mask_time_length": 10,
66
+ "mask_time_min_masks": 2,
67
+ "mask_time_prob": 0.05,
68
+ "model_type": "wav2vec2",
69
+ "num_adapter_layers": 3,
70
+ "num_attention_heads": 16,
71
+ "num_codevector_groups": 2,
72
+ "num_codevectors_per_group": 320,
73
+ "num_conv_pos_embedding_groups": 16,
74
+ "num_conv_pos_embeddings": 128,
75
+ "num_feat_extract_layers": 7,
76
+ "num_hidden_layers": 24,
77
+ "num_negatives": 100,
78
+ "output_hidden_size": 1024,
79
+ "pad_token_id": 42,
80
+ "proj_codevector_dim": 768,
81
+ "tdnn_dilation": [
82
+ 1,
83
+ 2,
84
+ 3,
85
+ 1,
86
+ 1
87
+ ],
88
+ "tdnn_dim": [
89
+ 512,
90
+ 512,
91
+ 512,
92
+ 512,
93
+ 1500
94
+ ],
95
+ "tdnn_kernel": [
96
+ 5,
97
+ 3,
98
+ 3,
99
+ 1,
100
+ 1
101
+ ],
102
+ "torch_dtype": "float32",
103
+ "transformers_version": "4.16.1",
104
+ "use_weighted_layer_sum": false,
105
+ "vocab_size": 43,
106
+ "xvector_output_dim": 512
107
+ }
eval.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset, load_metric, Audio, Dataset
2
+ from transformers import pipeline, AutoFeatureExtractor
3
+ import re
4
+ import argparse
5
+ import unicodedata
6
+ from typing import Dict
7
+
8
+
9
+ def log_results(result: Dataset, args: Dict[str, str]):
10
+ """ DO NOT CHANGE. This function computes and logs the result metrics. """
11
+
12
+ log_outputs = args.log_outputs
13
+ dataset_id = "_".join(args.dataset.split("/") + [args.config, args.split])
14
+
15
+ # load metric
16
+ wer = load_metric("wer")
17
+ cer = load_metric("cer")
18
+
19
+ # compute metrics
20
+ wer_result = wer.compute(references=result["target"], predictions=result["prediction"])
21
+ cer_result = cer.compute(references=result["target"], predictions=result["prediction"])
22
+
23
+ # print & log results
24
+ result_str = (
25
+ f"WER: {wer_result}\n"
26
+ f"CER: {cer_result}"
27
+ )
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 = [",", "?", "¿", ".", "!", "¡", ";", ";", ":", '""', "%", '"', "�", "ʿ", "·", "჻", "~", "՞",
54
+ "؟", "،", "।", "॥", "«", "»", "„", "“", "”", "「", "」", "‘", "’", "《", "》", "(", ")", "[", "]",
55
+ "{", "}", "=", "`", "_", "+", "<", ">", "…", "–", "°", "´", "ʾ", "‹", "›", "©", "®", "—", "→", "。",
56
+ "、", "﹂", "﹁", "‧", "~", "﹏", ",", "{", "}", "(", ")", "[", "]", "【", "】", "‥", "〽",
57
+ "『", "』", "〝", "〟", "⟨", "⟩", "〜", ":", "!", "?", "♪", "؛", "/", "\\",]
58
+ chars_to_ignore_regex = f"[{re.escape(''.join(CHARS_TO_IGNORE))}]"
59
+
60
+ text = text.lower()
61
+
62
+ text = re.sub(chars_to_ignore_regex, "", text)
63
+
64
+ text = " ".join(text.split())
65
+
66
+ return text
67
+
68
+
69
+ def main(args):
70
+ # load dataset
71
+ dataset = load_dataset(args.dataset, args.config, split=args.split, use_auth_token=True)
72
+
73
+ # for testing: only process the first two examples as a test
74
+ # dataset = dataset.select(range(10))
75
+
76
+ # load processor
77
+ feature_extractor = AutoFeatureExtractor.from_pretrained(args.model_id)
78
+ sampling_rate = feature_extractor.sampling_rate
79
+
80
+ # resample audio
81
+ dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
82
+
83
+ # load eval pipeline
84
+ asr = pipeline("automatic-speech-recognition", model=args.model_id)
85
+
86
+ # map function to decode audio
87
+ def map_to_pred(batch):
88
+ prediction = asr(batch["audio"]["array"], chunk_length_s=args.chunk_length_s, stride_length_s=args.stride_length_s)
89
+
90
+ batch["prediction"] = prediction["text"]
91
+ batch["target"] = normalize_text(batch["sentence"])
92
+ return batch
93
+
94
+ # run inference on all examples
95
+ result = dataset.map(map_to_pred, remove_columns=dataset.column_names)
96
+
97
+ # compute and log_results
98
+ # do not change function below
99
+ log_results(result, args)
100
+
101
+
102
+ if __name__ == "__main__":
103
+ parser = argparse.ArgumentParser()
104
+
105
+ parser.add_argument(
106
+ "--model_id", type=str, required=True, help="Model identifier. Should be loadable with 🤗 Transformers"
107
+ )
108
+ parser.add_argument(
109
+ "--dataset", type=str, required=True, help="Dataset name to evaluate the `model_id`. Should be loadable with 🤗 Datasets"
110
+ )
111
+ parser.add_argument(
112
+ "--config", type=str, required=True, help="Config of the dataset. *E.g.* `'en'` for Common Voice"
113
+ )
114
+ parser.add_argument(
115
+ "--split", type=str, required=True, help="Split of the dataset. *E.g.* `'test'`"
116
+ )
117
+ parser.add_argument(
118
+ "--chunk_length_s", type=float, default=None, help="Chunk length in seconds. Defaults to None. For long audio files a good value would be 5.0 seconds."
119
+ )
120
+ parser.add_argument(
121
+ "--stride_length_s", type=float, default=None, help="Stride of the audio chunks. Defaults to None. For long audio files a good value would be 1.0 seconds."
122
+ )
123
+ parser.add_argument(
124
+ "--log_outputs", action='store_true', help="If defined, write outputs to log file for analysis."
125
+ )
126
+ args = parser.parse_args()
127
+
128
+ main(args)
129
+
log_mozilla-foundation_common_voice_8_0_ckb_test_predictions.txt ADDED
The diff for this file is too large to render. See raw diff
 
log_mozilla-foundation_common_voice_8_0_ckb_test_targets.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:896f0159864e1ed83c339360f394da16ad4ec4a6c8f297fb1b3ea5aa4318f1a7
3
+ size 1261983732
mozilla-foundation_common_voice_8_0_ckb_test_eval_results.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ WER: 0.36754389884276845
2
+ CER: 0.07827896768334217
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.0,
7
+ "processor_class": "Wav2Vec2Processor",
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:389a8c7465980807312bc135a917d9a93683a889e8be2b3158dd3c4f743d73fd
3
+ size 1262099953
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "[UNK]", "pad_token": "[PAD]"}
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": "|", "tokenizer_class": "Wav2Vec2CTCTokenizer", "processor_class": "Wav2Vec2Processor"}
vocab.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"ێ": 0, "د": 1, "ي": 2, "ش": 3, "ڵ": 4, "ى": 5, "ر": 6, "غ": 7, "س": 8, "-": 9, "ک": 10, "خ": 11, "ث": 13, "ڕ": 14, "ە": 15, "ی": 16, "گ": 17, "ز": 18, "ژ": 19, "ؤ": 20, "ن": 21, "ڤ": 22, "ب": 23, "ج": 24, "ا": 25, "ف": 26, "ح": 27, "ت": 28, "پ": 29, "ھ": 30, "ل": 31, "ق": 32, "ع": 33, "ئ": 34, "ۆ": 35, "چ": 36, "ك": 37, "م": 38, "ه": 39, "و": 40, "|": 12, "[UNK]": 41, "[PAD]": 42}