Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
json
Languages:
English
Size:
10K - 100K
ArXiv:
License:
| from datasets import DatasetDict, load_dataset | |
| import json | |
| import datasets | |
| class MyDatasetConfig(datasets.BuilderConfig): | |
| def __init__(self, category=None, **kwargs): | |
| super().__init__(**kwargs) | |
| self.category = category | |
| class MyDataset(datasets.GeneratorBasedBuilder): | |
| BUILDER_CONFIG_CLASS = MyDatasetConfig | |
| BUILDER_CONFIGS = [ | |
| MyDatasetConfig( | |
| name="alpaca_gpt4", | |
| category="alpaca_gpt4", | |
| version=datasets.Version("1.0.0"), | |
| ), | |
| MyDatasetConfig( | |
| name="magpie", | |
| category="magpie", | |
| version=datasets.Version("1.0.0"), | |
| ), | |
| ] | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| features=datasets.Features({ | |
| "id": datasets.Value("string"), | |
| "conversations": datasets.Sequence({ | |
| "from": datasets.Value("string"), | |
| "value": datasets.Value("string"), | |
| }) | |
| }) | |
| ) | |
| def _split_generators(self, dl_manager): | |
| category = self.config.category | |
| base = f"./{category}" | |
| return [ | |
| datasets.SplitGenerator( | |
| name=f"{category}_tshirt_k_50", | |
| gen_kwargs={"filepath": f"{base}/tshirt_k_50.json"}, | |
| ), | |
| datasets.SplitGenerator( | |
| name=f"{category}_tshirt_k_75", | |
| gen_kwargs={"filepath": f"{base}/tshirt_k_75.json"}, | |
| ) | |
| ] | |
| def _generate_examples(self, filepath): | |
| with open(filepath, "r") as f: | |
| data = json.load(f) | |
| for row in data: | |
| yield row["id"], row | |