kingabzpro commited on
Commit
f3b84ab
1 Parent(s): 1cece73
added_tokens.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"<s>": 55, "</s>": 56}
config.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
- "_name_or_path": "Harveenchadha/vakyansh-wav2vec2-urdu-urm-60",
3
- "activation_dropout": 0.1,
4
  "adapter_kernel_size": 3,
5
  "adapter_stride": 2,
6
  "add_adapter": false,
@@ -9,12 +9,11 @@
9
  "Wav2Vec2ForCTC"
10
  ],
11
  "attention_dropout": 0.1,
12
- "bos_token": "<s>",
13
- "bos_token_id": 0,
14
  "classifier_proj_size": 256,
15
- "codevector_dim": 256,
16
  "contrastive_logits_temperature": 0.1,
17
- "conv_bias": false,
18
  "conv_dim": [
19
  512,
20
  512,
@@ -45,43 +44,41 @@
45
  "ctc_loss_reduction": "mean",
46
  "ctc_zero_infinity": false,
47
  "diversity_loss_weight": 0.1,
48
- "do_lower_case": false,
49
- "do_stable_layer_norm": false,
50
- "eos_token": "</s>",
51
  "eos_token_id": 2,
52
  "feat_extract_activation": "gelu",
53
- "feat_extract_norm": "group",
 
54
  "feat_proj_dropout": 0.0,
55
  "feat_quantizer_dropout": 0.0,
56
- "final_dropout": 0.1,
57
  "gradient_checkpointing": false,
58
  "hidden_act": "gelu",
59
  "hidden_dropout": 0.1,
60
- "hidden_size": 768,
61
  "initializer_range": 0.02,
62
- "intermediate_size": 3072,
63
  "layer_norm_eps": 1e-05,
64
  "layerdrop": 0.0,
65
- "mask_feature_length": 10,
66
  "mask_feature_min_masks": 0,
67
- "mask_feature_prob": 0.0,
68
  "mask_time_length": 10,
69
  "mask_time_min_masks": 2,
70
- "mask_time_prob": 0.05,
71
  "model_type": "wav2vec2",
72
  "num_adapter_layers": 3,
73
- "num_attention_heads": 12,
74
  "num_codevector_groups": 2,
75
  "num_codevectors_per_group": 320,
76
  "num_conv_pos_embedding_groups": 16,
77
  "num_conv_pos_embeddings": 128,
78
  "num_feat_extract_layers": 7,
79
- "num_hidden_layers": 12,
80
  "num_negatives": 100,
81
- "output_hidden_size": 768,
82
- "pad_token": "[PAD]",
83
- "pad_token_id": 1,
84
- "proj_codevector_dim": 256,
85
  "tdnn_dilation": [
86
  1,
87
  2,
@@ -104,10 +101,8 @@
104
  1
105
  ],
106
  "torch_dtype": "float32",
107
- "transformers_version": "4.16.2",
108
- "unk_token": "[UNK]",
109
  "use_weighted_layer_sum": false,
110
- "vocab_size": 48,
111
- "word_delimiter_token": "|",
112
  "xvector_output_dim": 512
113
  }
 
1
  {
2
+ "_name_or_path": "facebook/wav2vec2-xls-r-300m",
3
+ "activation_dropout": 0.0,
4
  "adapter_kernel_size": 3,
5
  "adapter_stride": 2,
6
  "add_adapter": false,
 
9
  "Wav2Vec2ForCTC"
10
  ],
11
  "attention_dropout": 0.1,
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,
 
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.0,
53
  "feat_quantizer_dropout": 0.0,
54
+ "final_dropout": 0.0,
55
  "gradient_checkpointing": false,
56
  "hidden_act": "gelu",
57
  "hidden_dropout": 0.1,
58
+ "hidden_size": 1024,
59
  "initializer_range": 0.02,
60
+ "intermediate_size": 4096,
61
  "layer_norm_eps": 1e-05,
62
  "layerdrop": 0.0,
63
+ "mask_feature_length": 64,
64
  "mask_feature_min_masks": 0,
65
+ "mask_feature_prob": 0.25,
66
  "mask_time_length": 10,
67
  "mask_time_min_masks": 2,
68
+ "mask_time_prob": 0.75,
69
  "model_type": "wav2vec2",
70
  "num_adapter_layers": 3,
71
+ "num_attention_heads": 16,
72
  "num_codevector_groups": 2,
73
  "num_codevectors_per_group": 320,
74
  "num_conv_pos_embedding_groups": 16,
75
  "num_conv_pos_embeddings": 128,
76
  "num_feat_extract_layers": 7,
77
+ "num_hidden_layers": 24,
78
  "num_negatives": 100,
79
+ "output_hidden_size": 1024,
80
+ "pad_token_id": 54,
81
+ "proj_codevector_dim": 768,
 
82
  "tdnn_dilation": [
83
  1,
84
  2,
 
101
  1
102
  ],
103
  "torch_dtype": "float32",
104
+ "transformers_version": "4.16.0",
 
105
  "use_weighted_layer_sum": false,
106
+ "vocab_size": 57,
 
107
  "xvector_output_dim": 512
108
  }
eval.py CHANGED
@@ -1,153 +1,153 @@
1
- #!/usr/bin/env python3
2
- import argparse
3
- import re
4
- import unicodedata
5
- from typing import Dict
6
-
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(
24
- references=result["target"], predictions=result["prediction"]
25
- )
26
- cer_result = cer.compute(
27
- references=result["target"], predictions=result["prediction"]
28
- )
29
-
30
- # print & log results
31
- result_str = f"WER: {wer_result}\n" f"CER: {cer_result}"
32
- print(result_str)
33
-
34
- with open(f"{dataset_id}_eval_results.txt", "w") as f:
35
- f.write(result_str)
36
-
37
- # log all results in text file. Possibly interesting for analysis
38
- if log_outputs is not None:
39
- pred_file = f"log_{dataset_id}_predictions.txt"
40
- target_file = f"log_{dataset_id}_targets.txt"
41
-
42
- with open(pred_file, "w") as p, open(target_file, "w") as t:
43
-
44
- # mapping function to write output
45
- def write_to_file(batch, i):
46
- p.write(f"{i}" + "\n")
47
- p.write(batch["prediction"] + "\n")
48
- t.write(f"{i}" + "\n")
49
- t.write(batch["target"] + "\n")
50
-
51
- result.map(write_to_file, with_indices=True)
52
-
53
-
54
- def normalize_text(text: str) -> str:
55
- """DO ADAPT FOR YOUR USE CASE. this function normalizes the target text."""
56
-
57
- chars_to_ignore_regex = """[\!\؛\،\٫\؟\۔\٪\"\'\:\-\‘\’]""" # noqa: W605 IMPORTANT: this should correspond to the chars that were ignored during training
58
- text = re.sub(chars_to_ignore_regex, "", text.lower())
59
- text = unicodedata.normalize("NFKC", text)
60
-
61
- # In addition, we can normalize the target text, e.g. removing new lines characters etc...
62
- # note that order is important here!
63
- token_sequences_to_ignore = ["\n\n", "\n", " ", " "]
64
-
65
- for t in token_sequences_to_ignore:
66
- text = " ".join(text.split(t))
67
-
68
- return text
69
-
70
-
71
- def main(args):
72
- # load dataset
73
- dataset = load_dataset(
74
- args.dataset, args.config, split=args.split, use_auth_token=True
75
- )
76
-
77
- # for testing: only process the first two examples as a test
78
- # dataset = dataset.select(range(10))
79
-
80
- # load processor
81
- feature_extractor = AutoFeatureExtractor.from_pretrained(args.model_id)
82
- sampling_rate = feature_extractor.sampling_rate
83
-
84
- # resample audio
85
- dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
86
-
87
- # load eval pipeline
88
- asr = pipeline("automatic-speech-recognition", model=args.model_id, device=0)
89
-
90
- # map function to decode audio
91
- def map_to_pred(batch):
92
- prediction = asr(
93
- batch["audio"]["array"],
94
- chunk_length_s=args.chunk_length_s,
95
- stride_length_s=args.stride_length_s,
96
- )
97
-
98
- batch["prediction"] = prediction["text"]
99
- batch["target"] = normalize_text(batch["sentence"])
100
- return batch
101
-
102
- # run inference on all examples
103
- result = dataset.map(map_to_pred, remove_columns=dataset.column_names)
104
-
105
- # compute and log_results
106
- # do not change function below
107
- log_results(result, args)
108
-
109
-
110
- if __name__ == "__main__":
111
- parser = argparse.ArgumentParser()
112
-
113
- parser.add_argument(
114
- "--model_id",
115
- type=str,
116
- required=True,
117
- help="Model identifier. Should be loadable with 🤗 Transformers",
118
- )
119
- parser.add_argument(
120
- "--dataset",
121
- type=str,
122
- required=True,
123
- help="Dataset name to evaluate the `model_id`. Should be loadable with 🤗 Datasets",
124
- )
125
- parser.add_argument(
126
- "--config",
127
- type=str,
128
- required=True,
129
- help="Config of the dataset. *E.g.* `'en'` for Common Voice",
130
- )
131
- parser.add_argument(
132
- "--split", type=str, required=True, help="Split of the dataset. *E.g.* `'test'`"
133
- )
134
- parser.add_argument(
135
- "--chunk_length_s",
136
- type=float,
137
- default=None,
138
- help="Chunk length in seconds. Defaults to 5 seconds.",
139
- )
140
- parser.add_argument(
141
- "--stride_length_s",
142
- type=float,
143
- default=None,
144
- help="Stride of the audio chunks. Defaults to 1 second.",
145
- )
146
- parser.add_argument(
147
- "--log_outputs",
148
- action="store_true",
149
- help="If defined, write outputs to log file for analysis.",
150
- )
151
- args = parser.parse_args()
152
-
153
- main(args)
 
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("[،]", '', text)
57
+ text = re.sub("[؟]", '', text)
58
+ text = re.sub("['َ]", '', text)
59
+ text = re.sub("['ُ]", '', text)
60
+ text = re.sub("['ِ]", '', text)
61
+ text = re.sub("['ّ]", '', text)
62
+ text = re.sub("['ٔ]", '', text)
63
+ text = re.sub("['ٰ]", '', text)
64
+ # batch["sentence"] = re.sub("[ء]", '', batch["sentence"])
65
+ # batch["sentence"] = re.sub("[آ]", 'ا', batch["sentence"])
66
+ text = re.sub("[ۂ]", 'ہ', text)
67
+ text = re.sub("[ي]", "ی",text)
68
+ text = re.sub("[ؤ]", "و", text)
69
+ # batch["sentence"] = re.sub("[ئ]", 'ى', batch["sentence"])
70
+ text = re.sub("[ى]", 'ی', text)
71
+ text = re.sub("[۔]", '', text)
72
+
73
+ # In addition, we can normalize the target text, e.g. removing new lines characters etc...
74
+ # note that order is important here!
75
+ token_sequences_to_ignore = ["\n\n", "\n", " ", " "]
76
+
77
+ for t in token_sequences_to_ignore:
78
+ text = " ".join(text.split(t))
79
+
80
+ return text
81
+
82
+
83
+ def main(args):
84
+ # load dataset
85
+ dataset = load_dataset(args.dataset, args.config, split=args.split, use_auth_token=True)
86
+
87
+ # for testing: only process the first two examples as a test
88
+ # dataset = dataset.select(range(10))
89
+
90
+ # load processor
91
+ feature_extractor = AutoFeatureExtractor.from_pretrained(args.model_id)
92
+ sampling_rate = feature_extractor.sampling_rate
93
+
94
+ # resample audio
95
+ dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
96
+
97
+ # load eval pipeline
98
+ if args.device is None:
99
+ args.device = 0 if torch.cuda.is_available() else -1
100
+ asr = pipeline("automatic-speech-recognition", model=args.model_id, device=args.device)
101
+
102
+ # map function to decode audio
103
+ def map_to_pred(batch):
104
+ prediction = asr(
105
+ batch["audio"]["array"], chunk_length_s=args.chunk_length_s, stride_length_s=args.stride_length_s
106
+ )
107
+
108
+ batch["prediction"] = prediction["text"]
109
+ batch["target"] = normalize_text(batch["sentence"])
110
+ return batch
111
+
112
+ # run inference on all examples
113
+ result = dataset.map(map_to_pred, remove_columns=dataset.column_names)
114
+
115
+ # compute and log_results
116
+ # do not change function below
117
+ log_results(result, args)
118
+
119
+
120
+ if __name__ == "__main__":
121
+ parser = argparse.ArgumentParser()
122
+
123
+ parser.add_argument(
124
+ "--model_id", type=str, required=True, help="Model identifier. Should be loadable with 🤗 Transformers"
125
+ )
126
+ parser.add_argument(
127
+ "--dataset",
128
+ type=str,
129
+ required=True,
130
+ help="Dataset name to evaluate the `model_id`. Should be loadable with 🤗 Datasets",
131
+ )
132
+ parser.add_argument(
133
+ "--config", type=str, required=True, help="Config of the dataset. *E.g.* `'en'` for Common Voice"
134
+ )
135
+ parser.add_argument("--split", type=str, required=True, help="Split of the dataset. *E.g.* `'test'`")
136
+ parser.add_argument(
137
+ "--chunk_length_s", type=float, default=None, help="Chunk length in seconds. Defaults to 5 seconds."
138
+ )
139
+ parser.add_argument(
140
+ "--stride_length_s", type=float, default=None, help="Stride of the audio chunks. Defaults to 1 second."
141
+ )
142
+ parser.add_argument(
143
+ "--log_outputs", action="store_true", help="If defined, write outputs to log file for analysis."
144
+ )
145
+ parser.add_argument(
146
+ "--device",
147
+ type=int,
148
+ default=None,
149
+ help="The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on.",
150
+ )
151
+ args = parser.parse_args()
152
+
153
+ main(args)
preprocessor_config.json CHANGED
@@ -3,7 +3,8 @@
3
  "feature_extractor_type": "Wav2Vec2FeatureExtractor",
4
  "feature_size": 1,
5
  "padding_side": "right",
6
- "padding_value": 0,
7
- "return_attention_mask": false,
 
8
  "sampling_rate": 16000
9
  }
 
3
  "feature_extractor_type": "Wav2Vec2FeatureExtractor",
4
  "feature_size": 1,
5
  "padding_side": "right",
6
+ "padding_value": 0.0,
7
+ "processor_class": "Wav2Vec2ProcessorWithLM",
8
+ "return_attention_mask": true,
9
  "sampling_rate": 16000
10
  }
special_tokens_map.json CHANGED
@@ -1 +1 @@
1
- {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "pad_token": "<pad>"}
 
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}]}
tokenizer_config.json CHANGED
@@ -1 +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": "/root/.cache/huggingface/transformers/898afae2faf3d20dd22149b80863bb5d448c67d9c9b821dd66753253a4d77c64.9d6cd81ef646692fb1c169a880161ea1cb95f49694f220aced9b704b457e51dd", "tokenizer_file": null, "name_or_path": "Harveenchadha/vakyansh-wav2vec2-urdu-urm-60", "tokenizer_class": "Wav2Vec2CTCTokenizer"}
 
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": "anuragshas/wav2vec2-large-xls-r-300m-ur-cv8", "tokenizer_class": "Wav2Vec2CTCTokenizer", "processor_class": "Wav2Vec2ProcessorWithLM"}
vocab.json CHANGED
@@ -1 +1 @@
1
- {"<s>": 0, "<pad>": 1, "</s>": 2, "<unk>": 3, "|": 4, "ء": 5, "آ": 6, "ؤ": 7, "ئ": 8, "ا": 9, "ب": 10, "ت": 11, "ث": 12, "ج": 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, "گ": 41, "ں": 42, "ھ": 43, "ہ": 44, "ی": 45, "ے": 46, "ۓ": 47}
 
1
+ {"ء": 1, "آ": 2, "ؤ": 3, "ئ": 4, "ا": 5, "ب": 6, "ت": 7, "ث": 8, "ج": 9, "ح": 10, "خ": 11, "د": 12, "ذ": 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, "چ": 41, "ڈ": 42, "ڑ": 43, "ژ": 44, "ک": 45, "گ": 46, "ں": 47, "ھ": 48, "ہ": 49, "ۂ": 50, "ی": 51, "ے": 52, "|": 0, "[UNK]": 53, "[PAD]": 54}