| |
| """ |
| Example script to load and use the Common Voice Japanese test set. |
| """ |
|
|
| import json |
| from pathlib import Path |
| from collections import Counter |
|
|
| def load_cv_test_set(dataset_dir="."): |
| """ |
| Load Common Voice Japanese test set from all splits. |
| |
| Args: |
| dataset_dir: Path to the dataset directory |
| |
| Returns: |
| List of dicts with audio paths and metadata |
| """ |
| dataset_dir = Path(dataset_dir) |
| samples = [] |
|
|
| |
| for split_dir in sorted(dataset_dir.glob("ja_[0-9][0-9]")): |
| metadata_file = split_dir / "test.jsonl" |
|
|
| if not metadata_file.exists(): |
| continue |
|
|
| with open(metadata_file, 'r', encoding='utf-8') as f: |
| for line in f: |
| entry = json.loads(line) |
| entry['audio_path'] = str(split_dir / entry['path']) |
| entry['split'] = split_dir.name |
| samples.append(entry) |
|
|
| return samples |
|
|
|
|
| def get_dataset_stats(samples): |
| """Get statistics about the dataset.""" |
| stats = { |
| 'total_samples': len(samples), |
| 'gender_distribution': Counter(s.get('gender', '') for s in samples), |
| 'age_distribution': Counter(s.get('age', '') for s in samples), |
| 'split_distribution': Counter(s.get('split', '') for s in samples), |
| 'total_votes': sum(s.get('up_votes', 0) + s.get('down_votes', 0) for s in samples), |
| 'avg_up_votes': sum(s.get('up_votes', 0) for s in samples) / len(samples) if samples else 0, |
| } |
| return stats |
|
|
|
|
| if __name__ == "__main__": |
| |
| print("Loading Common Voice Japanese test set...\n") |
|
|
| samples = load_cv_test_set() |
| stats = get_dataset_stats(samples) |
|
|
| print(f"=== Test Set Statistics ===") |
| print(f"Total samples: {stats['total_samples']}") |
| print(f"Average up votes: {stats['avg_up_votes']:.2f}") |
|
|
| print("\nSplit distribution:") |
| for split, count in sorted(stats['split_distribution'].items()): |
| print(f" {split}: {count} files") |
|
|
| print("\nGender distribution:") |
| for gender, count in stats['gender_distribution'].most_common(): |
| if gender: |
| print(f" {gender}: {count} ({count/stats['total_samples']*100:.1f}%)") |
|
|
| print("\nAge distribution:") |
| for age, count in stats['age_distribution'].most_common(): |
| if age: |
| print(f" {age}: {count} ({count/stats['total_samples']*100:.1f}%)") |
|
|
| |
| if samples: |
| print(f"\nSample entry:") |
| sample = samples[0] |
| print(f" Split: {sample['split']}") |
| print(f" File: {sample['file_name']}") |
| print(f" Path: {sample['path']}") |
| print(f" Text: {sample['text'][:50]}...") |
| print(f" Gender: {sample.get('gender', 'N/A')}") |
| print(f" Age: {sample.get('age', 'N/A')}") |
|
|