| import os |
| import json |
| import datasets |
|
|
|
|
| |
| |
| _DESCRIPTION = """20Q""" |
|
|
| |
| _HOMEPAGE = "" |
|
|
| |
| _LICENSE = "" |
|
|
|
|
|
|
| class NewDataset(datasets.GeneratorBasedBuilder): |
| """TODO: Short description of my dataset.""" |
|
|
| VERSION = datasets.Version("1.0.0") |
|
|
| def _info(self): |
| features = datasets.Features( |
| { |
| "subject": datasets.Value("string"), |
| "question": datasets.Value("string"), |
| "label": datasets.Value("bool"), |
| "label_fine_grained": datasets.Value("string") |
| } |
| ) |
|
|
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| homepage=_HOMEPAGE, |
| license=_LICENSE, |
| citation="_CITATION", |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| data_dir = dl_manager.download_and_extract(["data/train.jsonl", "data/test.jsonl"]) |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={ |
| "filepath": data_dir[0], |
| "split": "train", |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs={ |
| "filepath": data_dir[1], |
| "split": "test" |
| }, |
| ), |
| ] |
|
|
| def _generate_examples(self, filepath, split): |
| with open(filepath, encoding="utf-8") as f: |
| for key, row in enumerate(f): |
| data = json.loads(row) |
| yield key, { |
| "subject": data["subject"], |
| "question": data["question"], |
| "label": data["label"], |
| "label_fine_grained": data["label_fine_grained"] |
| } |
|
|