File size: 2,510 Bytes
a02f7fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# coding=utf-8
# Copyright 2024  Bofeng Huang

import os
from collections import defaultdict

import fire
import numpy as np
import pandas as pd
from tqdm import tqdm

from meta import SUBSET_NAMES_AND_PATHS


def _print_ds_info(df, duration_column_name="duration"):
    print(f"#utterances: {df.shape[0]}")
    durations = df["duration"]
    print(
        f"Duration statistics: tot {durations.sum() / 3600:.2f} h, "
        f"mean {durations.mean():.2f} s, "
        f"min {durations.min():.2f} s, "
        f"max {durations.max():.2f} s"
    )
    print()


def main(output_file):

    dataset_dir = os.path.dirname(os.path.abspath(__file__))

    lang_manifests_dict = defaultdict(list)
    for k, v in SUBSET_NAMES_AND_PATHS.items():
        lang_manifests_dict[k.split("-")[0]].append((k, f'{dataset_dir}/{v["dir"]}/{v["text_file"]}'))

    # print(lang_manifests_dict)

    with open(output_file, "w") as f:
        for lang, manifest_files in lang_manifests_dict.items():
            f.write("\n" + lang + "\n" + "\n")
            f.write("| Split | 20% | 10% | 5% | 0% |" + "\n")
            f.write("| :--- | :---: | :---: | :---: | :---: |" + "\n")

            lines = []
            for split, manifest_file in tqdm(manifest_files):
                # load dataset
                df = pd.read_json(manifest_file, lines=True)
                # print("Raw dataset")
                # _print_ds_info(df)

                # line = f"| {split} |"

                # wer_cutoffs = [20, 10, 5, 0]
                # for wer_cutoff in wer_cutoffs:
                #     df_ = df[df["wer"] <= wer_cutoff]
                #     # print(f"wer_cutoff: {wer_cutoff}")
                #     # _print_ds_info(df_)

                #     line += f' {df_["duration"].sum() / 3600:.2f} |'

                # f.write(line + "\n")

                l = [df[df["wer"] <= wer_cutoff]["duration"].sum() / 3600 for wer_cutoff in [20, 10, 5, 0]]
                l.insert(0, split)
                lines.append(l)

            lines.append(
                [
                    "total",
                    sum(l[1] for l in lines),
                    sum(l[2] for l in lines),
                    sum(l[3] for l in lines),
                    sum(l[4] for l in lines),
                ]
            )

            for l in lines:
                f.write(f"| {l[0]} | " + " | ".join([f"{l_:,.2f}" for l_ in l[1:]]) + " |" + "\n")

            # break


if __name__ == "__main__":
    fire.Fire(main)