Datasets:
Delete curate_dataset.py
Browse files- curate_dataset.py +0 -82
curate_dataset.py
DELETED
|
@@ -1,82 +0,0 @@
|
|
| 1 |
-
def curate_dataset(
|
| 2 |
-
min_dur,
|
| 3 |
-
max_dur,
|
| 4 |
-
max_wer,
|
| 5 |
-
csv1_path,
|
| 6 |
-
csv2_path,
|
| 7 |
-
full_dataset_path,
|
| 8 |
-
output_path=None,
|
| 9 |
-
):
|
| 10 |
-
if output_path is None:
|
| 11 |
-
wer_str = str(max_wer).replace(".", "")
|
| 12 |
-
output_path = (
|
| 13 |
-
f"manifest_filtered_{min_dur}_{max_dur}_{wer_str}.csv"
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
# --- Read CSVs ---
|
| 17 |
-
df1 = pd.read_csv(csv1_path)
|
| 18 |
-
df2 = pd.read_csv(csv2_path)
|
| 19 |
-
|
| 20 |
-
# --- Ensure numeric types ---
|
| 21 |
-
for df in (df1, df2):
|
| 22 |
-
df["duration"] = pd.to_numeric(df["duration"], errors="coerce")
|
| 23 |
-
df["wer"] = pd.to_numeric(df["wer"], errors="coerce")
|
| 24 |
-
|
| 25 |
-
# --- Apply filters on each CSV ---
|
| 26 |
-
f1 = df1[
|
| 27 |
-
(df1["duration"] > min_dur)
|
| 28 |
-
& (df1["duration"] < max_dur)
|
| 29 |
-
& (df1["wer"] < max_wer)
|
| 30 |
-
]
|
| 31 |
-
|
| 32 |
-
f2 = df2[
|
| 33 |
-
(df2["duration"] > min_dur)
|
| 34 |
-
& (df2["duration"] < max_dur)
|
| 35 |
-
& (df2["wer"] < max_wer)
|
| 36 |
-
]
|
| 37 |
-
|
| 38 |
-
# --- Keep audio_id present in both filtered CSVs ---
|
| 39 |
-
ids1 = set(f1["audio_id"].dropna().astype(str))
|
| 40 |
-
ids2 = set(f2["audio_id"].dropna().astype(str))
|
| 41 |
-
kept_ids = ids1.intersection(ids2)
|
| 42 |
-
|
| 43 |
-
print(f"Kept audio_id count: {len(kept_ids)}")
|
| 44 |
-
|
| 45 |
-
# --- Filter the full dataset ---
|
| 46 |
-
full_df = pd.read_csv(full_dataset_path)
|
| 47 |
-
full_df["audio_id"] = full_df["audio_id"].astype(str)
|
| 48 |
-
|
| 49 |
-
filtered_full_df = full_df[full_df["audio_id"].isin(kept_ids)]
|
| 50 |
-
|
| 51 |
-
# --- Save result ---
|
| 52 |
-
filtered_full_df.to_csv(output_path, index=False)
|
| 53 |
-
|
| 54 |
-
print(f"Filtered dataset saved to: {output_path}")
|
| 55 |
-
print(f"Rows kept in full dataset: {len(filtered_full_df)}")
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if __name__ == "__main__":
|
| 59 |
-
parser = argparse.ArgumentParser(
|
| 60 |
-
description="Filter the dataset using duration and WER thresholds."
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
parser.add_argument("--min-dur", type=float, required=True)
|
| 64 |
-
parser.add_argument("--max-dur", type=float, required=True)
|
| 65 |
-
parser.add_argument("--max-wer", type=float, required=True)
|
| 66 |
-
|
| 67 |
-
parser.add_argument("--csv1-path", required=True)
|
| 68 |
-
parser.add_argument("--csv2-path", required=True)
|
| 69 |
-
parser.add_argument("--full-dataset-path", required=True)
|
| 70 |
-
parser.add_argument("--output-path", default=None)
|
| 71 |
-
|
| 72 |
-
args = parser.parse_args()
|
| 73 |
-
|
| 74 |
-
curate_dataset(
|
| 75 |
-
min_dur=args.min_dur,
|
| 76 |
-
max_dur=args.max_dur,
|
| 77 |
-
max_wer=args.max_wer,
|
| 78 |
-
csv1_path=args.csv1_path,
|
| 79 |
-
csv2_path=args.csv2_path,
|
| 80 |
-
full_dataset_path=args.full_dataset_path,
|
| 81 |
-
output_path=args.output_path,
|
| 82 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|