Datasets:
Delete extract_shards.py
Browse files- extract_shards.py +0 -101
extract_shards.py
DELETED
|
@@ -1,101 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
"""
|
| 3 |
-
Extract tar shards back to original structure
|
| 4 |
-
"""
|
| 5 |
-
import argparse
|
| 6 |
-
import tarfile
|
| 7 |
-
import csv
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
from tqdm import tqdm
|
| 10 |
-
from collections import defaultdict
|
| 11 |
-
import shutil
|
| 12 |
-
|
| 13 |
-
def parse_args():
|
| 14 |
-
parser = argparse.ArgumentParser(
|
| 15 |
-
description="Extract tar shards to recreate dataset"
|
| 16 |
-
)
|
| 17 |
-
parser.add_argument(
|
| 18 |
-
"--sharded-dir",
|
| 19 |
-
type=Path,
|
| 20 |
-
default=".",
|
| 21 |
-
help="Directory containing audio/ and metadata/ folders"
|
| 22 |
-
)
|
| 23 |
-
parser.add_argument(
|
| 24 |
-
"--output-dir",
|
| 25 |
-
type=Path,
|
| 26 |
-
default="extracted",
|
| 27 |
-
help="Output directory for extracted dataset"
|
| 28 |
-
)
|
| 29 |
-
return parser.parse_args()
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
def main():
|
| 33 |
-
args = parse_args()
|
| 34 |
-
|
| 35 |
-
audio_dir = args.sharded_dir / "audio"
|
| 36 |
-
metadata_file = args.sharded_dir / "metadata" / "metadata.csv"
|
| 37 |
-
|
| 38 |
-
if not audio_dir.exists():
|
| 39 |
-
raise FileNotFoundError(f"Audio directory not found: {audio_dir}")
|
| 40 |
-
if not metadata_file.exists():
|
| 41 |
-
raise FileNotFoundError(f"Metadata not found: {metadata_file}")
|
| 42 |
-
|
| 43 |
-
# Read metadata to understand structure
|
| 44 |
-
print("Reading metadata...")
|
| 45 |
-
with open(metadata_file, 'r', encoding='utf-8') as f:
|
| 46 |
-
reader = csv.DictReader(f)
|
| 47 |
-
rows = list(reader)
|
| 48 |
-
|
| 49 |
-
# Group by subset and shard
|
| 50 |
-
shards_by_subset = defaultdict(set)
|
| 51 |
-
for row in rows:
|
| 52 |
-
subset = row['subset']
|
| 53 |
-
shard = row['shard']
|
| 54 |
-
shards_by_subset[subset].add(shard)
|
| 55 |
-
|
| 56 |
-
print(f"Found {len(rows):,} samples across {len(shards_by_subset)} subsets")
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# Extract all shards
|
| 60 |
-
for subset in sorted(shards_by_subset.keys()):
|
| 61 |
-
print(f"\nExtracting {subset}...")
|
| 62 |
-
subset_output = args.output_dir / subset / "audio"
|
| 63 |
-
subset_output.mkdir(parents=True, exist_ok=True)
|
| 64 |
-
|
| 65 |
-
shards = sorted(shards_by_subset[subset])
|
| 66 |
-
|
| 67 |
-
for shard_name in tqdm(shards, desc=f" {subset}"):
|
| 68 |
-
shard_path = audio_dir / subset / shard_name
|
| 69 |
-
|
| 70 |
-
if not shard_path.exists():
|
| 71 |
-
print(f"Warning: {shard_path} not found, skipping")
|
| 72 |
-
continue
|
| 73 |
-
|
| 74 |
-
# Extract tar
|
| 75 |
-
with tarfile.open(shard_path, 'r') as tar:
|
| 76 |
-
tar.extractall(path=subset_output)
|
| 77 |
-
|
| 78 |
-
metadata_dir = Path(args.sharded_dir) / "metadata"
|
| 79 |
-
output_dir = Path(args.output_dir)
|
| 80 |
-
|
| 81 |
-
# Create the output directory if it does not exist
|
| 82 |
-
output_dir.mkdir(parents=True, exist_ok=True)
|
| 83 |
-
|
| 84 |
-
# Copy every CSV file
|
| 85 |
-
for csv_file in metadata_dir.glob("*.csv"):
|
| 86 |
-
destination = output_dir / csv_file.name
|
| 87 |
-
shutil.copy2(csv_file, destination)
|
| 88 |
-
|
| 89 |
-
print("\n" + "="*60)
|
| 90 |
-
print("Extraction complete!")
|
| 91 |
-
print("="*60)
|
| 92 |
-
print(f"Output directory: {args.output_dir}")
|
| 93 |
-
print(f"\nTo process the dataset:")
|
| 94 |
-
print(f"python process_dataset.py \\")
|
| 95 |
-
print(f" --taskmaster-root-dir {args.output_dir} \\")
|
| 96 |
-
print(f" --aug-dataset-save-dir ./processed \\")
|
| 97 |
-
print(f" --normalize-text")
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
if __name__ == "__main__":
|
| 101 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|