File size: 2,963 Bytes
e8a558c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3

import json
import os
from pathlib import Path
from datasets import Dataset, Audio


def test_final_structure():
    """Test the final dataset structure for HF compatibility"""

    print("Testing final dataset structure...")
    print("=" * 50)

    # Check for required files
    files_to_check = [
        "metadata.jsonl",
        "audio/xin_chao.mp3",
        "audio/cam_on.mp3",
        "audio/viet_nam.mp3"
    ]

    print("1. Checking file structure:")
    for file_path in files_to_check:
        if os.path.exists(file_path):
            print(f"   ✓ {file_path}")
        else:
            print(f"   ✗ {file_path} - MISSING")
            return False

    # Load and validate metadata
    print("\n2. Loading metadata.jsonl:")
    try:
        records = []
        with open("metadata.jsonl", "r", encoding="utf-8") as f:
            for line_num, line in enumerate(f, 1):
                try:
                    record = json.loads(line)
                    records.append(record)
                except json.JSONDecodeError as e:
                    print(f"   ✗ Line {line_num}: Invalid JSON - {e}")
                    return False

        print(f"   ✓ Loaded {len(records)} records")

        # Validate required fields
        required_fields = ["file_name", "word", "ipa"]
        for i, record in enumerate(records[:3], 1):
            missing_fields = [field for field in required_fields if field not in record]
            if missing_fields:
                print(f"   ✗ Record {i} missing fields: {missing_fields}")
                return False

        print(f"   ✓ All records have required fields: {required_fields}")

    except Exception as e:
        print(f"   ✗ Error loading metadata: {e}")
        return False

    # Test with datasets library
    print("\n3. Testing with datasets library:")
    try:
        dataset = Dataset.from_list(records)
        dataset = dataset.cast_column("file_name", Audio(decode=False))

        print(f"   ✓ Dataset created successfully")
        print(f"   ✓ Features: {dataset.features}")
        print(f"   ✓ Number of examples: {len(dataset)}")

        # Test first example
        first_example = dataset[0]
        print(f"   ✓ First example loaded: {first_example['word']} ({first_example['ipa']})")

    except Exception as e:
        print(f"   ✗ Error with datasets library: {e}")
        return False

    print("\n4. Summary:")
    print("   ✓ Files in root directory")
    print("   ✓ metadata.jsonl with file_name column")
    print("   ✓ Audio files in audio/ subdirectory")
    print("   ✓ Compatible with datasets library")
    print("   ✓ Ready for Hugging Face Dataset Viewer")

    return True


if __name__ == "__main__":
    success = test_final_structure()

    if success:
        print("\n🎉 Dataset structure is correct and ready for upload!")
    else:
        print("\n❌ Dataset structure needs fixes")