File size: 1,476 Bytes
1294ff9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json
import random
import datasets

_HOMEPAGE = (
    f"https://www.modelscope.cn/datasets/MuGeminorum/{os.path.basename(__file__)[:-3]}"
)

_URL = f"{_HOMEPAGE}/resolve/master/data/dataset.jsonl"


class hoyoMusic(datasets.GeneratorBasedBuilder):
    def _info(self):
        return datasets.DatasetInfo(
            features=datasets.Features(
                {
                    "prompt": datasets.Value("string"),
                    "data": datasets.Value("string"),
                    "label": datasets.Value("string"),
                }
            ),
            supervised_keys=("data", "label"),
            homepage=_HOMEPAGE,
            license="CC-BY-NC-ND",
            version="0.0.1",
        )

    def _split_generators(self, dl_manager):
        dataset = []
        data = dl_manager.download(_URL)
        with open(data, "r", encoding="utf-8") as file:
            for line in file:
                dataset.append(json.loads(line))

        random.shuffle(dataset)
        data_count = len(dataset)
        p90 = int(data_count * 0.9)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN, gen_kwargs={"files": dataset[:p90]}
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST, gen_kwargs={"files": dataset[p90:]}
            ),
        ]

    def _generate_examples(self, files):
        for i, path in enumerate(files):
            yield i, path