import json import datasets class SkillDataset(datasets.GeneratorBasedBuilder): VERSION = datasets.Version("0.1.0") def _info(self): return datasets.DatasetInfo( description="A dataset of skills and their descriptions", features=datasets.Features( { "input": datasets.Value("string"), "target": datasets.Value("string"), } ), ) def _split_generators(self, dl_manager): mappings = json.load(open("mappings.json", "r")) training_data = mappings[:int(0.95 * len(mappings))] testing_data = mappings[int(0.95 * len(mappings)) :] return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data": training_data } ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data": testing_data } ), ] def _generate_examples(self, data): for i, mapping in enumerate(data): yield i, { "input": mapping["input"], "target": mapping["target"], }