lgris commited on
Commit
974fc86
1 Parent(s): 5f53a1d

evaluation

Browse files
README.md CHANGED
@@ -8,7 +8,21 @@ datasets:
8
  - mozilla-foundation/common_voice_7_0
9
  model-index:
10
  - name: wav2vec2-xls-r-gn-cv7
11
- results: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
8
  - mozilla-foundation/common_voice_7_0
9
  model-index:
10
  - name: wav2vec2-xls-r-gn-cv7
11
+ results:
12
+ - task:
13
+ name: Automatic Speech Recognition
14
+ type: automatic-speech-recognition
15
+ dataset:
16
+ name: Common Voice 7
17
+ type: mozilla-foundation/common_voice_7_0
18
+ args: pt
19
+ metrics:
20
+ - name: Validation WER
21
+ type: wer
22
+ value: 73.02
23
+ - name: Validation CER
24
+ type: cer
25
+ value: 17.79
26
  ---
27
 
28
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
eval.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
57
+ # In addition, we can normalize the target text, e.g. removing new lines characters etc...
58
+ # note that order is important here!
59
+ token_sequences_to_ignore = ["\n\n", "\n", " ", " "]
60
+
61
+ for t in token_sequences_to_ignore:
62
+ text = " ".join(text.split(t))
63
+
64
+ return text
65
+
66
+
67
+ def main(args):
68
+ # load dataset
69
+ dataset = load_dataset(args.dataset, args.config, split=args.split, use_auth_token=True)
70
+
71
+ # for testing: only process the first two examples as a test
72
+ # dataset = dataset.select(range(10))
73
+
74
+ # load processor
75
+ feature_extractor = AutoFeatureExtractor.from_pretrained(args.model_id)
76
+ sampling_rate = feature_extractor.sampling_rate
77
+
78
+ # resample audio
79
+ dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
80
+
81
+ # load eval pipeline
82
+ if args.device is None:
83
+ args.device = 0 if torch.cuda.is_available() else -1
84
+ asr = pipeline("automatic-speech-recognition", model=args.model_id, device=args.device)
85
+
86
+ # map function to decode audio
87
+ def map_to_pred(batch):
88
+ prediction = asr(
89
+ batch["audio"]["array"], chunk_length_s=args.chunk_length_s, stride_length_s=args.stride_length_s
90
+ )
91
+
92
+ batch["prediction"] = prediction["text"]
93
+ batch["target"] = normalize_text(batch["sentence"])
94
+ return batch
95
+
96
+ # run inference on all examples
97
+ result = dataset.map(map_to_pred, remove_columns=dataset.column_names)
98
+
99
+ # compute and log_results
100
+ # do not change function below
101
+ log_results(result, args)
102
+
103
+
104
+ if __name__ == "__main__":
105
+ parser = argparse.ArgumentParser()
106
+
107
+ parser.add_argument(
108
+ "--model_id", type=str, required=True, help="Model identifier. Should be loadable with 🤗 Transformers"
109
+ )
110
+ parser.add_argument(
111
+ "--dataset",
112
+ type=str,
113
+ required=True,
114
+ help="Dataset name to evaluate the `model_id`. Should be loadable with 🤗 Datasets",
115
+ )
116
+ parser.add_argument(
117
+ "--config", type=str, required=True, help="Config of the dataset. *E.g.* `'en'` for Common Voice"
118
+ )
119
+ parser.add_argument("--split", type=str, required=True, help="Split of the dataset. *E.g.* `'test'`")
120
+ parser.add_argument(
121
+ "--chunk_length_s", type=float, default=None, help="Chunk length in seconds. Defaults to 5 seconds."
122
+ )
123
+ parser.add_argument(
124
+ "--stride_length_s", type=float, default=None, help="Stride of the audio chunks. Defaults to 1 second."
125
+ )
126
+ parser.add_argument(
127
+ "--log_outputs", action="store_true", help="If defined, write outputs to log file for analysis."
128
+ )
129
+ parser.add_argument(
130
+ "--device",
131
+ type=int,
132
+ default=None,
133
+ help="The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on.",
134
+ )
135
+ args = parser.parse_args()
136
+
137
+ main(args)
eval.sh ADDED
@@ -0,0 +1 @@
 
1
+ ./eval.py --model_id lgris/wav2vec2-xls-r-gn-cv7 --dataset mozilla-foundation/common_voice_7_0 --config gn --split validation --log_outputs
log_mozilla-foundation_common_voice_7_0_gn_validation_predictions.txt ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 0
2
+ nykotererei ho oysã porã
3
+ 1
4
+ mávapape mba'e ikuakapáva poyvórape
5
+ 2
6
+ ikatuhá peve ahejande chupe
7
+ 3
8
+ povákuri iperiumguekuéra ndive tava parauguavýpe
9
+ 4
10
+ kui mba'e oiku vapynandiovasry ha oñemombeporaguáiva
11
+ 5
12
+ ohopáma piko
13
+ 6
14
+ nomberekyra
15
+ 7
16
+ he rembiapokue kuy
17
+ 8
18
+ ñe'epyrũrãme ndahe raivaʼekue
19
+ 9
20
+ ha upépe oĩjepe oheiakaʼe me lipiráriepe
21
+ 10
22
+ romaña porãva ojuhe noroñe'ẽi ojupe
23
+ 11
24
+ na chemandu'ái
25
+ 12
26
+ hoyhepyme'ẽ chupe
27
+ 13
28
+ oipurúrheikuái ka'a ha ho'ute rere
29
+ 14
30
+ oré rotuviatã lunekue
31
+ 15
32
+ mbapéipate hendume umi rugárpe
33
+ 16
34
+ mávapape mba'e ñanembopyʼáruribéga
35
+ 17
36
+ omosã umi mbaʼekuaa
37
+ 18
38
+ po'ã ka hape aréko heta mba'etuja ndaipotãvéi uma
39
+ 19
40
+ péia ha'e
41
+ 20
42
+ mba'e riko chépe
43
+ 21
44
+ aikéma katu porapýpe
45
+ 22
46
+ nápepe oĩ cherajyla pinsésa
47
+ 23
48
+ ohasahárupi a'ãraña voo karai purvensio
49
+ 24
50
+ aoñetépaʼere
51
+ 25
52
+ tata guasu opu'ãvo 'ojahéi tekoháre
53
+ 26
54
+ upéima niko ñelmo'ãku oñeñarundujevýva
55
+ 27
56
+ ohecha mba'éichapa ha'e oñemboja ha oike guasura'y mbive yro'õme
57
+ 28
58
+ ño nemborieahúko na ñandiapo'ãivavoi
59
+ 29
60
+ ha oporeíma hesy
61
+ 30
62
+ oopa umi mba'ére niko tapichakuéra ohaihúi chupe
63
+ 31
64
+ ndaipóri ivy pome'ẽ'aréva hi'a
65
+ 32
66
+ aravo opa jeike hagua
67
+ 33
68
+ oimérez nriko hovah hína plá ta yguy mba'e
69
+ 34
70
+ a upéicha avei ndoipotãete uñe'ẽkui mba'ekuéra ndive
71
+ 35
72
+ huungy ha morote
log_mozilla-foundation_common_voice_7_0_gn_validation_targets.txt ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 0
2
+ mmm ko terere hoysã porã
3
+ 1
4
+ mávapa pe mbaʼe ipuʼakapáva ko yvórape
5
+ 2
6
+ ikatuha peve ahejánte chupe
7
+ 3
8
+ ovákuri ipehẽnguekuéra ndive táva paraguaýpe
9
+ 4
10
+ kuimba'e oikóva pynandi hovasy ha oñemonde paraguáiva
11
+ 5
12
+ ohopámapiko
13
+ 6
14
+ ndekyra
15
+ 7
16
+ hembiapokue ypy
17
+ 8
18
+ ñepyrũrãme ndaheraivaʼekue
19
+ 9
20
+ ha upépe oĩjepe avei academia literariape
21
+ 10
22
+ romaña porã ojuehe noroñe'ẽi ojupe
23
+ 11
24
+ nachemandu'ái
25
+ 12
26
+ ohepyme'ẽ chupe
27
+ 13
28
+ oipuru hikuái ka'a ha ho'u terere
29
+ 14
30
+ ore rostudiáta luneskue
31
+ 15
32
+ mbaʼépa pehendúne umi lugarpe
33
+ 16
34
+ mávapa pe mbaʼe ñanembopyʼaroryvéva
35
+ 17
36
+ omosã umi mbaʼekuaa
37
+ 18
38
+ ko'ã cajape areko heta mba'e tuja ndaipotavéima
39
+ 19
40
+ péa ha'e
41
+ 20
42
+ mba'épiko chéve
43
+ 21
44
+ aikéma katu korapýpe
45
+ 22
46
+ napépe oĩ che rajy la princesa
47
+ 23
48
+ ohasaha rupi ára ñavõ karai prudencio
49
+ 24
50
+ añetépa ere
51
+ 25
52
+ tata guasu opu'ãvo ojahéi tekoháre
53
+ 26
54
+ upéima niko ñaimo'ã ku añeñandujeýva
55
+ 27
56
+ ohecha mba'éichapa ha'e oñemboja ha oike guasu ra'y ndive yno'õme
57
+ 28
58
+ ñande mboriahúko nañandepo'aivavoi
59
+ 29
60
+ ha ohoreíma heseve
61
+ 30
62
+ opa umi mba'ére niko tapichakuéra ohayhu ichupe
63
+ 31
64
+ ndaipóri yvy ome'ẽ'aréva hi'a
65
+ 32
66
+ aravo ojeike haguã
67
+ 33
68
+ oiméne niko kóva hína pláta yvyguy mba'e
69
+ 34
70
+ ha upéicha avei ndoipotaiete oñe'ẽ kuimba'ekuéra ndive
71
+ 35
72
+ hũngy ha morotĩ
mozilla-foundation_common_voice_7_0_gn_validation_eval_results.txt ADDED
@@ -0,0 +1,2 @@
 
 
1
+ WER: 0.7302631578947368
2
+ CER: 0.17799043062200956