File size: 5,193 Bytes
d4101a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import io
import os
import time

import truststore

truststore.inject_into_ssl()

import numpy as np
import pyarrow.parquet as pq
import soundfile as sf
from huggingface_hub import snapshot_download


def main():
    ds_dir = r"C:\dev\AjudaEstudos\experiments\lua-nova-v1\hf_dataset"
    t0 = time.perf_counter()
    snapshot_download(
        repo_id="oProfM/LuaNovaDataset",
        repo_type="dataset",
        local_dir=ds_dir,
        allow_patterns=["README.md", "data/*.parquet"],
    )
    dl_sec = time.perf_counter() - t0
    print(f"Download finished in {dl_sec:.1f}s")

    data_files = sorted(
        f for f in os.listdir(os.path.join(ds_dir, "data")) if f.endswith(".parquet")
    )
    print("Data shards:", len(data_files), data_files[0], "...", data_files[-1])

    total = 0
    low_utmos_cnt = 0
    cer_le_008 = 0
    cer_le_005 = 0
    lang_ge_08 = 0
    clean_all = 0
    clean_strict = 0
    dur_all = 0.0
    dur_clean = 0.0
    dur_strict = 0.0
    diff_text_norm = []
    unique_texts = set()
    unique_clean_texts = set()
    digits_in_text = 0
    digits_in_norm = 0
    utmos_clean = []

    for fn in data_files:
        pf = pq.read_table(
            os.path.join(ds_dir, "data", fn),
            columns=[
                "id",
                "text",
                "normalized_text",
                "duration",
                "utmos",
                "cer",
                "lang_prob_pt",
                "low_utmos",
            ],
        )
        d = pf.to_pydict()
        n = len(d["id"])
        total += n
        for i in range(n):
            t = (d["text"][i] or "").strip()
            nt = (d["normalized_text"][i] or "").strip()
            dur = float(d["duration"][i])
            dur_all += dur
            unique_texts.add(t)
            if any(c.isdigit() for c in t):
                digits_in_text += 1
            if any(c.isdigit() for c in nt):
                digits_in_norm += 1
            if t != nt and len(diff_text_norm) < 10:
                diff_text_norm.append((d["id"][i], t, nt))
            lu = bool(d["low_utmos"][i])
            cer = float(d["cer"][i])
            lp = float(d["lang_prob_pt"][i])
            utm = float(d["utmos"][i])
            if lu:
                low_utmos_cnt += 1
            if cer <= 0.08:
                cer_le_008 += 1
            if cer <= 0.05:
                cer_le_005 += 1
            if lp >= 0.8:
                lang_ge_08 += 1
            if not lu and 0.6 <= dur <= 20.0:
                clean_all += 1
                dur_clean += dur
                unique_clean_texts.add(t)
                utmos_clean.append(utm)
                if cer <= 0.08 and lp >= 0.8:
                    clean_strict += 1
                    dur_strict += dur

    print(f"Total rows: {total}, total dur: {dur_all/3600:.2f}h, unique texts: {len(unique_texts)}")
    print(f"Digits in text: {digits_in_text}, in normalized_text: {digits_in_norm}")
    print(f"low_utmos True: {low_utmos_cnt}, cer<=0.08: {cer_le_008}, cer<=0.05: {cer_le_005}, lang_prob_pt>=0.8: {lang_ge_08}")
    print(f"Clean (not low_utmos): {clean_all} rows, {dur_clean/3600:.2f}h, unique: {len(unique_clean_texts)}, mean utmos: {np.mean(utmos_clean):.3f}")
    print(f"Strict (not low_utmos & cer<=0.08 & lang>=0.8): {clean_strict} rows, {dur_strict/3600:.2f}h")
    print("Sample text != normalized_text count (capped 10):", len(diff_text_norm))
    for item in diff_text_norm[:5]:
        print("  DIFF:", item)

    # Compare shard 0 data vs raw audio stats on 100 items
    t_data = pq.read_table(
        os.path.join(ds_dir, "data", "train-00000.parquet"),
        columns=["id", "audio", "breath_removed_ms", "duration"],
    ).to_pydict()
    t_raw = pq.read_table(
        os.path.join(ds_dir, "raw", "train-00000.parquet"),
        columns=["id", "audio", "duration"],
    ).to_pydict()
    raw_by_id = {t_raw["id"][i]: t_raw["audio"][i] for i in range(len(t_raw["id"]))}

    srs = set()
    peaks_d, peaks_r, rms_d, rms_r, silence_frac_d, silence_frac_r = [], [], [], [], [], []
    zero_rms_d = 0
    for i in range(100):
        uid = t_data["id"][i]
        yd, sr_d = sf.read(io.BytesIO(t_data["audio"][i]["bytes"]), dtype="float32")
        yr, sr_r = sf.read(io.BytesIO(raw_by_id[uid]["bytes"]), dtype="float32")
        srs.add((sr_d, sr_r, yd.ndim, yr.ndim))
        peaks_d.append(float(np.max(np.abs(yd))))
        peaks_r.append(float(np.max(np.abs(yr))))
        rd = float(np.sqrt(np.mean(yd ** 2)))
        rr = float(np.sqrt(np.mean(yr ** 2)))
        if rd < 1e-5:
            zero_rms_d += 1
        rms_d.append(rd)
        rms_r.append(rr)
        silence_frac_d.append(float(np.mean(np.abs(yd) < 1e-4)))
        silence_frac_r.append(float(np.mean(np.abs(yr) < 1e-4)))

    print("Sample rate/ndim pairs:", srs, "zero_rms_d:", zero_rms_d)
    print(f"data  mean peak={np.mean(peaks_d):.3f} max={np.max(peaks_d):.3f} mean_rms={np.mean(rms_d):.4f} silence_frac={np.mean(silence_frac_d):.3f}")
    print(f"raw   mean peak={np.mean(peaks_r):.3f} max={np.max(peaks_r):.3f} mean_rms={np.mean(rms_r):.4f} silence_frac={np.mean(silence_frac_r):.3f}")


if __name__ == "__main__":
    main()