hoyoMusic / hoyoMusic.py
admin
rename org name
7309911
raw
history blame
1.47 kB
import os
import json
import random
import datasets
_HOMEPAGE = f"https://www.modelscope.cn/datasets/Genius-Society/{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