upd eval code
Browse files
src/bash_runners/{run_eval_cv11.sh → eval_cv11_test.sh}
RENAMED
@@ -1,9 +1,10 @@
|
|
1 |
-
python src/run_eval_whisper_streaming \
|
2 |
-
--model_id="
|
3 |
--language="be" \
|
4 |
--dataset="mozilla-foundation/common_voice_11_0" \
|
5 |
--config="be" \
|
6 |
--split="test" \
|
|
|
7 |
--device="0" \
|
8 |
--batch_size="32" \
|
9 |
--streaming="True"
|
|
|
1 |
+
python src/run_eval_whisper_streaming.py \
|
2 |
+
--model_id="$1" \
|
3 |
--language="be" \
|
4 |
--dataset="mozilla-foundation/common_voice_11_0" \
|
5 |
--config="be" \
|
6 |
--split="test" \
|
7 |
+
--text_column="sentence" \
|
8 |
--device="0" \
|
9 |
--batch_size="32" \
|
10 |
--streaming="True"
|
src/bash_runners/eval_fleurs_test.sh
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
python src/run_eval_whisper_streaming.py \
|
2 |
+
--model_id="$1" \
|
3 |
+
--language="be" \
|
4 |
+
--dataset="google/fleurs" \
|
5 |
+
--config="be_by" \
|
6 |
+
--split="test" \
|
7 |
+
--text_column="transcription" \
|
8 |
+
--device="0" \
|
9 |
+
--batch_size="32" \
|
10 |
+
--streaming="True"
|
src/run_eval_whisper_streaming.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
import argparse
|
|
|
|
|
|
|
2 |
|
3 |
from transformers import pipeline
|
4 |
from transformers.models.whisper.english_normalizer import BasicTextNormalizer
|
@@ -8,7 +11,23 @@ import evaluate
|
|
8 |
from belarusian_text_normalizer import BelarusianTextNormalizer
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
wer_metric = evaluate.load("wer")
|
|
|
12 |
|
13 |
|
14 |
def is_target_text_in_range(ref):
|
@@ -18,30 +37,9 @@ def is_target_text_in_range(ref):
|
|
18 |
return ref.strip() != ""
|
19 |
|
20 |
|
21 |
-
def
|
22 |
-
|
23 |
-
|
24 |
-
elif "sentence" in sample:
|
25 |
-
return sample["sentence"]
|
26 |
-
elif "normalized_text" in sample:
|
27 |
-
return sample["normalized_text"]
|
28 |
-
elif "transcript" in sample:
|
29 |
-
return sample["transcript"]
|
30 |
-
elif "transcription" in sample:
|
31 |
-
return sample["transcription"]
|
32 |
-
else:
|
33 |
-
raise ValueError(
|
34 |
-
f"Expected transcript column of either 'text', 'sentence', 'normalized_text' or 'transcript'. Got sample of "
|
35 |
-
".join{sample.keys()}. Ensure a text column name is present in the dataset."
|
36 |
-
)
|
37 |
-
|
38 |
-
|
39 |
-
whisper_norm = BelarusianTextNormalizer()
|
40 |
-
|
41 |
-
|
42 |
-
def normalise(batch):
|
43 |
-
batch["norm_text"] = whisper_norm(get_text(batch))
|
44 |
-
return batch
|
45 |
|
46 |
|
47 |
def data(dataset):
|
@@ -50,10 +48,11 @@ def data(dataset):
|
|
50 |
|
51 |
|
52 |
def main(args):
|
|
|
|
|
|
|
53 |
batch_size = args.batch_size
|
54 |
-
whisper_asr = pipeline(
|
55 |
-
"automatic-speech-recognition", model=args.model_id, device=args.device
|
56 |
-
)
|
57 |
|
58 |
whisper_asr.model.config.forced_decoder_ids = (
|
59 |
whisper_asr.tokenizer.get_decoder_prompt_ids(
|
@@ -61,6 +60,7 @@ def main(args):
|
|
61 |
)
|
62 |
)
|
63 |
|
|
|
64 |
dataset = load_dataset(
|
65 |
args.dataset,
|
66 |
args.config,
|
@@ -73,30 +73,36 @@ def main(args):
|
|
73 |
dataset = dataset.take(args.max_eval_samples)
|
74 |
|
75 |
dataset = dataset.cast_column("audio", Audio(sampling_rate=16000))
|
76 |
-
dataset = dataset.map(normalise)
|
77 |
dataset = dataset.filter(is_target_text_in_range, input_columns=["norm_text"])
|
78 |
|
79 |
predictions = []
|
80 |
references = []
|
81 |
|
82 |
-
|
83 |
for out in whisper_asr(data(dataset), batch_size=batch_size):
|
84 |
predictions.append(whisper_norm(out["text"]))
|
85 |
references.append(out["reference"][0])
|
86 |
|
|
|
87 |
wer = wer_metric.compute(references=references, predictions=predictions)
|
88 |
-
wer =
|
|
|
|
|
|
|
89 |
|
90 |
-
print("WER:", wer)
|
91 |
evaluate.push_to_hub(
|
92 |
model_id=args.model_id,
|
|
|
93 |
metric_value=wer,
|
94 |
metric_type="wer",
|
95 |
metric_name="WER",
|
|
|
96 |
dataset_name=args.dataset,
|
97 |
dataset_type=args.dataset,
|
98 |
-
dataset_split=args.split,
|
99 |
dataset_config=args.config,
|
|
|
|
|
100 |
task_type="automatic-speech-recognition",
|
101 |
task_name="Automatic Speech Recognition"
|
102 |
)
|
@@ -129,7 +135,12 @@ if __name__ == "__main__":
|
|
129 |
default="test",
|
130 |
help="Split of the dataset. *E.g.* `'test'`",
|
131 |
)
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
133 |
parser.add_argument(
|
134 |
"--device",
|
135 |
type=int,
|
|
|
1 |
import argparse
|
2 |
+
import logging
|
3 |
+
import sys
|
4 |
+
import datetime
|
5 |
|
6 |
from transformers import pipeline
|
7 |
from transformers.models.whisper.english_normalizer import BasicTextNormalizer
|
|
|
11 |
from belarusian_text_normalizer import BelarusianTextNormalizer
|
12 |
|
13 |
|
14 |
+
now_str = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
|
15 |
+
|
16 |
+
|
17 |
+
logger = logging.getLogger(__name__)
|
18 |
+
logging.basicConfig(
|
19 |
+
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
|
20 |
+
datefmt="%m/%d/%Y %H:%M:%S",
|
21 |
+
handlers=[
|
22 |
+
logging.StreamHandler(sys.stdout),
|
23 |
+
logging.FileHandler(filename=f'eval_{now_str}.log', mode='w')
|
24 |
+
],
|
25 |
+
)
|
26 |
+
logger.setLevel(logging.INFO)
|
27 |
+
|
28 |
+
|
29 |
wer_metric = evaluate.load("wer")
|
30 |
+
whisper_norm = BelarusianTextNormalizer()
|
31 |
|
32 |
|
33 |
def is_target_text_in_range(ref):
|
|
|
37 |
return ref.strip() != ""
|
38 |
|
39 |
|
40 |
+
def normalise(sample, text_column: str):
|
41 |
+
sample["norm_text"] = whisper_norm(sample[text_column])
|
42 |
+
return sample
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
def data(dataset):
|
|
|
48 |
|
49 |
|
50 |
def main(args):
|
51 |
+
logger.info(f'running evaluation script with following parameters: {args}')
|
52 |
+
logger.info(f'using following text normalier: {whisper_norm}')
|
53 |
+
|
54 |
batch_size = args.batch_size
|
55 |
+
whisper_asr = pipeline("automatic-speech-recognition", model=args.model_id, device=args.device)
|
|
|
|
|
56 |
|
57 |
whisper_asr.model.config.forced_decoder_ids = (
|
58 |
whisper_asr.tokenizer.get_decoder_prompt_ids(
|
|
|
60 |
)
|
61 |
)
|
62 |
|
63 |
+
logger.info('loading dataset')
|
64 |
dataset = load_dataset(
|
65 |
args.dataset,
|
66 |
args.config,
|
|
|
73 |
dataset = dataset.take(args.max_eval_samples)
|
74 |
|
75 |
dataset = dataset.cast_column("audio", Audio(sampling_rate=16000))
|
76 |
+
dataset = dataset.map(normalise, fn_kwargs=dict(text_column=args.text_column))
|
77 |
dataset = dataset.filter(is_target_text_in_range, input_columns=["norm_text"])
|
78 |
|
79 |
predictions = []
|
80 |
references = []
|
81 |
|
82 |
+
logger.info('running inference')
|
83 |
for out in whisper_asr(data(dataset), batch_size=batch_size):
|
84 |
predictions.append(whisper_norm(out["text"]))
|
85 |
references.append(out["reference"][0])
|
86 |
|
87 |
+
logger.info('computing metrics')
|
88 |
wer = wer_metric.compute(references=references, predictions=predictions)
|
89 |
+
wer = wer * 100
|
90 |
+
|
91 |
+
logger.info('metrics computed')
|
92 |
+
logger.info(f'WER: {wer}')
|
93 |
|
|
|
94 |
evaluate.push_to_hub(
|
95 |
model_id=args.model_id,
|
96 |
+
|
97 |
metric_value=wer,
|
98 |
metric_type="wer",
|
99 |
metric_name="WER",
|
100 |
+
|
101 |
dataset_name=args.dataset,
|
102 |
dataset_type=args.dataset,
|
|
|
103 |
dataset_config=args.config,
|
104 |
+
dataset_split=args.split,
|
105 |
+
|
106 |
task_type="automatic-speech-recognition",
|
107 |
task_name="Automatic Speech Recognition"
|
108 |
)
|
|
|
135 |
default="test",
|
136 |
help="Split of the dataset. *E.g.* `'test'`",
|
137 |
)
|
138 |
+
parser.add_argument(
|
139 |
+
"--text_column",
|
140 |
+
type=str,
|
141 |
+
required=True,
|
142 |
+
help="Dataset column name containing target transcription of an audiofile"
|
143 |
+
)
|
144 |
parser.add_argument(
|
145 |
"--device",
|
146 |
type=int,
|