AndrewMcDowell
commited on
Commit
·
9494cbb
1
Parent(s):
3a54f37
Training in progress, step 1000
Browse files- .ipynb_checkpoints/eval-checkpoint.py +134 -0
- .ipynb_checkpoints/eval_results-checkpoint.json +10 -0
- .ipynb_checkpoints/log_mozilla-foundation_common_voice_8_0_ja_test_predictions-checkpoint.txt +0 -0
- .ipynb_checkpoints/log_mozilla-foundation_common_voice_8_0_ja_test_targets-checkpoint.txt +0 -0
- .ipynb_checkpoints/log_speech-recognition-community-v2_dev_data_ja_validation_predictions-checkpoint.txt +0 -0
- .ipynb_checkpoints/log_speech-recognition-community-v2_dev_data_ja_validation_targets-checkpoint.txt +0 -0
- .ipynb_checkpoints/mozilla-foundation_common_voice_8_0_ja_test_eval_results-checkpoint.txt +2 -0
- .ipynb_checkpoints/run_speech_recognition_ctc_bnb-checkpoint.py +1 -1
- .ipynb_checkpoints/run_training-checkpoint.sh +3 -2
- pytorch_model.bin +1 -1
- run_speech_recognition_ctc_bnb.py +1 -1
- run_training.sh +3 -2
- special_tokens_map.json +1 -1
- training_args.bin +1 -1
.ipynb_checkpoints/eval-checkpoint.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from datasets import load_dataset, load_metric, Audio, Dataset
|
3 |
+
from transformers import pipeline, AutoFeatureExtractor
|
4 |
+
import re
|
5 |
+
import argparse
|
6 |
+
import unicodedata
|
7 |
+
from typing import Dict
|
8 |
+
|
9 |
+
|
10 |
+
def log_results(result: Dataset, args: Dict[str, str]):
|
11 |
+
""" DO NOT CHANGE. This function computes and logs the result metrics. """
|
12 |
+
|
13 |
+
log_outputs = args.log_outputs
|
14 |
+
dataset_id = "_".join(args.dataset.split("/") + [args.config, args.split])
|
15 |
+
|
16 |
+
# load metric
|
17 |
+
wer = load_metric("wer")
|
18 |
+
cer = load_metric("cer")
|
19 |
+
|
20 |
+
# compute metrics
|
21 |
+
wer_result = wer.compute(references=result["target"], predictions=result["prediction"])
|
22 |
+
cer_result = cer.compute(references=result["target"], predictions=result["prediction"])
|
23 |
+
|
24 |
+
# print & log results
|
25 |
+
result_str = (
|
26 |
+
f"WER: {wer_result}\n"
|
27 |
+
f"CER: {cer_result}"
|
28 |
+
)
|
29 |
+
print(result_str)
|
30 |
+
|
31 |
+
with open(f"{dataset_id}_eval_results.txt", "w") as f:
|
32 |
+
f.write(result_str)
|
33 |
+
|
34 |
+
# log all results in text file. Possibly interesting for analysis
|
35 |
+
if log_outputs is not None:
|
36 |
+
pred_file = f"log_{dataset_id}_predictions.txt"
|
37 |
+
target_file = f"log_{dataset_id}_targets.txt"
|
38 |
+
|
39 |
+
with open(pred_file, "w") as p, open(target_file, "w") as t:
|
40 |
+
|
41 |
+
# mapping function to write output
|
42 |
+
def write_to_file(batch, i):
|
43 |
+
p.write(f"{i}" + "\n")
|
44 |
+
p.write(batch["prediction"] + "\n")
|
45 |
+
t.write(f"{i}" + "\n")
|
46 |
+
t.write(batch["target"] + "\n")
|
47 |
+
|
48 |
+
result.map(write_to_file, with_indices=True)
|
49 |
+
|
50 |
+
|
51 |
+
def normalize_text(text: str) -> str:
|
52 |
+
""" DO ADAPT FOR YOUR USE CASE. this function normalizes the target text. """
|
53 |
+
|
54 |
+
from pykakasi import kakasi
|
55 |
+
|
56 |
+
kakasi = kakasi()
|
57 |
+
kakasi.setMode('J', 'H') #Convert from kanji to hiragana
|
58 |
+
conv = kakasi.getConverter()
|
59 |
+
chars_to_ignore_regex = '[\,\?\!\-\;\:\"\“\%\‘\”\�\—\’\…\–\(\,\[\]\)\(\!\/\「\」\『\』]' # noqa: W605 IMPORTANT: this should correspond to the chars that were ignored during training
|
60 |
+
|
61 |
+
|
62 |
+
# remove punctuation
|
63 |
+
text = conv.do(re.sub(chars_to_ignore_regex, "", text))
|
64 |
+
|
65 |
+
# In addition, we can normalize the target text, e.g. removing new lines characters etc...
|
66 |
+
# note that order is important here!
|
67 |
+
token_sequences_to_ignore = ["\n\n", "\n", " ", " "]
|
68 |
+
|
69 |
+
for t in token_sequences_to_ignore:
|
70 |
+
text = " ".join(text.split(t))
|
71 |
+
|
72 |
+
return text
|
73 |
+
|
74 |
+
|
75 |
+
def main(args):
|
76 |
+
# load dataset
|
77 |
+
dataset = load_dataset(args.dataset, args.config, split=args.split, use_auth_token=True)
|
78 |
+
|
79 |
+
# for testing: only process the first two examples as a test
|
80 |
+
# dataset = dataset.select(range(10))
|
81 |
+
|
82 |
+
# load processor
|
83 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(args.model_id)
|
84 |
+
sampling_rate = feature_extractor.sampling_rate
|
85 |
+
|
86 |
+
# resample audio
|
87 |
+
dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
|
88 |
+
|
89 |
+
# load eval pipeline
|
90 |
+
asr = pipeline("automatic-speech-recognition", model=args.model_id)
|
91 |
+
|
92 |
+
# map function to decode audio
|
93 |
+
def map_to_pred(batch):
|
94 |
+
prediction = asr(batch["audio"]["array"], chunk_length_s=args.chunk_length_s, stride_length_s=args.stride_length_s)
|
95 |
+
|
96 |
+
batch["prediction"] = prediction["text"]
|
97 |
+
batch["target"] = normalize_text(batch["sentence"])
|
98 |
+
return batch
|
99 |
+
|
100 |
+
# run inference on all examples
|
101 |
+
result = dataset.map(map_to_pred, remove_columns=dataset.column_names)
|
102 |
+
|
103 |
+
# compute and log_results
|
104 |
+
# do not change function below
|
105 |
+
log_results(result, args)
|
106 |
+
|
107 |
+
|
108 |
+
if __name__ == "__main__":
|
109 |
+
parser = argparse.ArgumentParser()
|
110 |
+
|
111 |
+
parser.add_argument(
|
112 |
+
"--model_id", type=str, required=True, help="Model identifier. Should be loadable with 🤗 Transformers"
|
113 |
+
)
|
114 |
+
parser.add_argument(
|
115 |
+
"--dataset", type=str, required=True, help="Dataset name to evaluate the `model_id`. Should be loadable with 🤗 Datasets"
|
116 |
+
)
|
117 |
+
parser.add_argument(
|
118 |
+
"--config", type=str, required=True, help="Config of the dataset. *E.g.* `'en'` for Common Voice"
|
119 |
+
)
|
120 |
+
parser.add_argument(
|
121 |
+
"--split", type=str, required=True, help="Split of the dataset. *E.g.* `'test'`"
|
122 |
+
)
|
123 |
+
parser.add_argument(
|
124 |
+
"--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."
|
125 |
+
)
|
126 |
+
parser.add_argument(
|
127 |
+
"--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."
|
128 |
+
)
|
129 |
+
parser.add_argument(
|
130 |
+
"--log_outputs", action='store_true', help="If defined, write outputs to log file for analysis."
|
131 |
+
)
|
132 |
+
args = parser.parse_args()
|
133 |
+
|
134 |
+
main(args)
|
.ipynb_checkpoints/eval_results-checkpoint.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"epoch": 50.0,
|
3 |
+
"eval_cer": 0.1826705782774121,
|
4 |
+
"eval_loss": 0.6643062829971313,
|
5 |
+
"eval_runtime": 307.697,
|
6 |
+
"eval_samples": 4466,
|
7 |
+
"eval_samples_per_second": 14.514,
|
8 |
+
"eval_steps_per_second": 1.817,
|
9 |
+
"eval_wer": 1.0241664801969121
|
10 |
+
}
|
.ipynb_checkpoints/log_mozilla-foundation_common_voice_8_0_ja_test_predictions-checkpoint.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
.ipynb_checkpoints/log_mozilla-foundation_common_voice_8_0_ja_test_targets-checkpoint.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
.ipynb_checkpoints/log_speech-recognition-community-v2_dev_data_ja_validation_predictions-checkpoint.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
.ipynb_checkpoints/log_speech-recognition-community-v2_dev_data_ja_validation_targets-checkpoint.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
.ipynb_checkpoints/mozilla-foundation_common_voice_8_0_ja_test_eval_results-checkpoint.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
WER: 0.9675266903914591
|
2 |
+
CER: 0.30694865529668464
|
.ipynb_checkpoints/run_speech_recognition_ctc_bnb-checkpoint.py
CHANGED
@@ -155,7 +155,7 @@ class DataTrainingArguments:
|
|
155 |
eval_split_name: str = field(
|
156 |
default="test",
|
157 |
metadata={
|
158 |
-
"help": "The name of the training data set split to use (via the datasets library). Defaults to '
|
159 |
},
|
160 |
)
|
161 |
audio_column_name: str = field(
|
|
|
155 |
eval_split_name: str = field(
|
156 |
default="test",
|
157 |
metadata={
|
158 |
+
"help": "The name of the training data set split to use (via the datasets library). Defaults to 'test'"
|
159 |
},
|
160 |
)
|
161 |
audio_column_name: str = field(
|
.ipynb_checkpoints/run_training-checkpoint.sh
CHANGED
@@ -7,8 +7,9 @@ python run_speech_recognition_ctc_bnb.py \
|
|
7 |
--num_train_epochs="50" \
|
8 |
--per_device_train_batch_size="32" \
|
9 |
--per_device_eval_batch_size="8" \
|
10 |
-
|
11 |
-
--
|
|
|
12 |
--length_column_name="input_length" \
|
13 |
--evaluation_strategy="steps" \
|
14 |
--text_column_name="sentence" \
|
|
|
7 |
--num_train_epochs="50" \
|
8 |
--per_device_train_batch_size="32" \
|
9 |
--per_device_eval_batch_size="8" \
|
10 |
+
--gradient_accumulation_steps="4" \
|
11 |
+
--learning_rate="7.5e-5" \
|
12 |
+
--warmup_steps="1500" \
|
13 |
--length_column_name="input_length" \
|
14 |
--evaluation_strategy="steps" \
|
15 |
--text_column_name="sentence" \
|
pytorch_model.bin
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 3851240177
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:490634cd84fbf3811afe86fb73dee322c6704b2e70e34a9b04adc71e593d0f24
|
3 |
size 3851240177
|
run_speech_recognition_ctc_bnb.py
CHANGED
@@ -155,7 +155,7 @@ class DataTrainingArguments:
|
|
155 |
eval_split_name: str = field(
|
156 |
default="test",
|
157 |
metadata={
|
158 |
-
"help": "The name of the training data set split to use (via the datasets library). Defaults to '
|
159 |
},
|
160 |
)
|
161 |
audio_column_name: str = field(
|
|
|
155 |
eval_split_name: str = field(
|
156 |
default="test",
|
157 |
metadata={
|
158 |
+
"help": "The name of the training data set split to use (via the datasets library). Defaults to 'test'"
|
159 |
},
|
160 |
)
|
161 |
audio_column_name: str = field(
|
run_training.sh
CHANGED
@@ -7,8 +7,9 @@ python run_speech_recognition_ctc_bnb.py \
|
|
7 |
--num_train_epochs="50" \
|
8 |
--per_device_train_batch_size="32" \
|
9 |
--per_device_eval_batch_size="8" \
|
10 |
-
|
11 |
-
--
|
|
|
12 |
--length_column_name="input_length" \
|
13 |
--evaluation_strategy="steps" \
|
14 |
--text_column_name="sentence" \
|
|
|
7 |
--num_train_epochs="50" \
|
8 |
--per_device_train_batch_size="32" \
|
9 |
--per_device_eval_batch_size="8" \
|
10 |
+
--gradient_accumulation_steps="4" \
|
11 |
+
--learning_rate="7.5e-5" \
|
12 |
+
--warmup_steps="1500" \
|
13 |
--length_column_name="input_length" \
|
14 |
--evaluation_strategy="steps" \
|
15 |
--text_column_name="sentence" \
|
special_tokens_map.json
CHANGED
@@ -1 +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}]}
|
|
|
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}]}
|
training_args.bin
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 2991
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0786d1d55e0806ed6c3ec835e9f4c65da62f2a569bf56129fbdf16fbc6e4d544
|
3 |
size 2991
|