File size: 1,205 Bytes
802cbd9
 
 
 
 
e8284a7
 
 
802cbd9
 
 
e8284a7
802cbd9
 
 
 
 
 
 
 
 
 
 
 
e8284a7
802cbd9
 
 
 
e8284a7
802cbd9
e8284a7
802cbd9
e8284a7
 
 
 
802cbd9
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

import json
import datasets

class DsuDataset(datasets.GeneratorBasedBuilder):
    """Discrete Speech Units dataset"""
    
    VERSION = datasets.Version("1.0.0")
    
    def _info(self):
        return datasets.DatasetInfo(
            description="Discrete Speech Units Dataset",
            features=datasets.Features({
                "id": datasets.Value("string"),
                "tokens": datasets.Sequence(datasets.Value("int32")),
                "text": datasets.Value("string"),
                "augmentation": datasets.Value("string")
            })
        )

    def _split_generators(self, dl_manager):
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"filepath": "data/train.json"},
            )
        ]

    def _generate_examples(self, filepath):
        with open(filepath, encoding="utf-8") as f:
            data = json.load(f)
            for i, item in enumerate(data):
                yield i, {
                    "id": item["id"],
                    "tokens": item["tokens"],
                    "text": item["text"],
                    "augmentation": item["augmentation"],
                }