|
|
|
|
|
|
|
|
from datasets import Dataset, Audio |
|
|
import json |
|
|
|
|
|
|
|
|
def test_hf_metadata_format(): |
|
|
"""Test the HF-compatible metadata format with file_name column""" |
|
|
|
|
|
|
|
|
records = [] |
|
|
try: |
|
|
with open("data/metadata.jsonl", "r", encoding="utf-8") as f: |
|
|
for line in f: |
|
|
records.append(json.loads(line)) |
|
|
except FileNotFoundError: |
|
|
print("Error: data/metadata.jsonl not found") |
|
|
return |
|
|
|
|
|
print(f"Loaded {len(records)} records from metadata.jsonl") |
|
|
|
|
|
|
|
|
dataset = Dataset.from_list(records) |
|
|
|
|
|
|
|
|
dataset = dataset.cast_column("file_name", Audio(decode=False)) |
|
|
|
|
|
print(f"\nDataset info:") |
|
|
print(f"- Number of samples: {len(dataset)}") |
|
|
print(f"- Features: {dataset.features}") |
|
|
|
|
|
|
|
|
print(f"\nFirst 3 examples:") |
|
|
for i, example in enumerate(dataset.select(range(3))): |
|
|
print(f"\n{i+1}. Word: {example['word']}") |
|
|
print(f" IPA: {example['ipa']}") |
|
|
audio = example['file_name'] |
|
|
if audio: |
|
|
print(f" Audio path: {audio.get('path', 'N/A')}") |
|
|
print(f" Audio loaded successfully") |
|
|
|
|
|
return dataset |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
print("Testing HF metadata format with file_name column...") |
|
|
print("=" * 60) |
|
|
|
|
|
dataset = test_hf_metadata_format() |
|
|
|
|
|
if dataset: |
|
|
print(f"\n✓ Dataset successfully loaded with {len(dataset)} examples") |
|
|
print("✓ Metadata columns (word, ipa) are preserved") |
|
|
print("✓ Audio files are linked via file_name column") |
|
|
print("✓ Compatible with HF Dataset Viewer format") |
|
|
else: |
|
|
print("✗ Failed to load dataset") |