| import datasets | |
| class AwesomeStuff(datasets.GeneratorBasedBuilder): | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig(name="first", description="This part of my dataset covers a first domain"), | |
| datasets.BuilderConfig(name="second", description="This part of my dataset covers a second domain"), | |
| ] | |
| def _info(self): | |
| features = datasets.Features( | |
| { | |
| "number": datasets.Value("int16"), | |
| "string": datasets.Value("string"), | |
| } | |
| ) | |
| return datasets.DatasetInfo( | |
| # This is the description that will appear on the datasets page. | |
| description="_DESC", | |
| # This defines the different columns of the dataset and their types | |
| features=features, # Here we define them above because they are different between the two configurations | |
| # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and | |
| # specify them. They'll be used if as_supervised=True in builder.as_dataset. | |
| # supervised_keys=("sentence", "label"), | |
| # Homepage of the dataset for documentation | |
| homepage="_HOMEPAGE", | |
| # License for the dataset if available | |
| license="_LICENSE", | |
| # Citation for the dataset | |
| citation="_CITATION", | |
| ) | |
| def _split_generators(self, dl_manager): | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| # These kwargs will be passed to _generate_examples | |
| gen_kwargs={ | |
| "split": "train", | |
| }, | |
| ), | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TEST, | |
| # These kwargs will be passed to _generate_examples | |
| gen_kwargs={ | |
| "split": "test" | |
| }, | |
| ), | |
| ] | |
| def _generate_examples(self, split): | |
| if self.config.name == "first": | |
| n_max = 10000 if split == "train" else 100 | |
| else: | |
| n_max = 7000 if split == "train" else 200 | |
| for i in range(n_max): | |
| yield i, { | |
| "number": i, | |
| "string": f"{self.config.name}_{split}", | |
| } | |