# nc_pat.py: the HF datasets "loading script" for the NC_PAT dataset (defines configurations/tasks, columns, etc.) import os import json import datasets from datasets import Split, SplitGenerator no_extra = { "source": datasets.Value("string"), "target": datasets.Value("string"), } samp_class = { "source": datasets.Value("string"), "target": datasets.Value("string"), "class": datasets.Value("string"), } count_class = { "source": datasets.Value("string"), "target": datasets.Value("string"), "count": datasets.Value("string"), "class": datasets.Value("string"), } dir_only = { "source": datasets.Value("string"), "target": datasets.Value("string"), "direction": datasets.Value("string"), } configs = [ {"name": "car_cdr_cons", "desc": "small phrase translation tasks that require only: CAR, CDR, or CAR+CDR+CONS operations", "features": samp_class}, {"name": "car_cdr_cons_tuc", "desc": "same task as car_cdr_cons, but requires mapping lowercase fillers to their uppercase tokens", "features": samp_class}, {"name": "car_cdr_rcons", "desc": "same task as car_cdr_cons, but the CONS samples have their left/right children swapped", "features": samp_class}, {"name": "car_cdr_rcons_tuc", "desc": "same task as car_cdr_rcons, but requires mapping lowercase fillers to their uppercase tokens", "features": samp_class}, {"name": "car_cdr_seq", "desc": "each samples requires 1-4 combinations of CAR and CDR, as identified by the root filler token", "features": count_class}, {"name": "car_cdr_seq_40k", "desc": "same task as car_cdr_seq, but train samples increased from 10K to 40K", "features": count_class}, {"name": "car_cdr_seq_tuc", "desc": "same task as car_cdr_seq, but requires mapping lowercase fillers to their uppercase tokens", "features": count_class}, {"name": "car_cdr_seq_40k_tuc", "desc": "same task as car_cdr_seq_tuc, but train samples increased from 10K to 40K", "features": count_class}, {"name": "car_cdr_seq_path", "desc": "similiar to car_cdr_seq, but each needed operation in represented as a node in the left child of the root", "features": count_class}, {"name": "car_cdr_seq_path_40k", "desc": "same task as car_cdr_seq_path, but train samples increased from 10K to 40K", "features": count_class}, {"name": "car_cdr_seq_path_40k_tuc", "desc": "same task as car_cdr_seq_path_40k, but requires mapping lowercase fillers to their uppercase tokens", "features": count_class}, {"name": "car_cdr_seq_path_tuc", "desc": "same task as car_cdr_seq_path, but requires mapping lowercase fillers to their uppercase tokens", "features": count_class}, {"name": "active_active_stb", "desc": "active sentence translation, from sentence to parenthesized tree form, both directions", "features": dir_only}, {"name": "active_active_stb_40k", "desc": "same task as active_active_stb, but train samples increased from 10K to 40K", "features": dir_only}, {"name": "active_logical_ttb", "desc": "active to logical tree translation, in both directions", "features": dir_only}, {"name": "active_logical_ttb_40k", "desc": "same task as active_logical_ttb, but train samples increased from 10K to 40K", "features": dir_only}, {"name": "active_passive_ssb", "desc": "active to passive sentence translation, in both directions", "features": dir_only}, {"name": "active_passive_ssb_40k", "desc": "same task as active_passive_ssb, but train samples increased from 10K to 40K", "features": dir_only}, {"name": "active_passive_ttb", "desc": "active to passive tree translation, in both directions", "features": dir_only}, {"name": "active_passive_ttb_40k", "desc": "same task as active_passive_ttb, but train samples increased from 10K to 40K", "features": dir_only}, {"name": "actpass_logical_tt", "desc": "mixture of active to logical and passive to logical tree translations, single direction", "features": no_extra}, {"name": "actpass_logical_tt_40k", "desc": "same task as actpass_logical_tt, but train samples increased from 10K to 40K", "features": no_extra}, {"name": "passive_logical_ttb", "desc": "passive to logical tree translation, in both directions", "features": dir_only}, {"name": "passive_logical_ttb_40k", "desc": "same task as passive_logical_ttb, but train samples increased from 10K to 40K", "features": dir_only}, {"name": "passive_passive_stb", "desc": "passive sentence translation, from sentence to parenthesized tree form, both directions", "features": dir_only}, {"name": "passive_passive_stb_40k", "desc": "same task as passive_passive_stb, but train samples increased from 10K to 40K", "features": dir_only}, ] class NcPatConfig(datasets.BuilderConfig): """BuilderConfig for NC_PAT dataset.""" def __init__(self, features=None, **kwargs): # Version history: # 0.0.17: Initial version released to HF datasets super().__init__(version=datasets.Version("0.0.17"), **kwargs) self.features = features self.label_classes = None self.data_url = "./{}.zip".format(kwargs["name"]) self.citation = None self.homepage = None def _info(self): return datasets.DatasetInfo( description=self.description, features=self.features, # No default supervised_keys (as we have to pass both question # and context as input). supervised_keys=None, homepage=self.homepage, citation=self.citation, ) class NcPat(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [NcPatConfig(name=c["name"], description=c["desc"], features=c["features"]) for c in configs] VERSION = datasets.Version("0.0.17") def _info(self): return datasets.DatasetInfo( description="The dataset consists of diagnostic/warm-up tasks and core tasks within this dataset." + "The core tasks represent the translation of English sentences between the active, passive, and logical forms.", supervised_keys=None, homepage=None, citation=None, ) def _split_generators(self, dl_manager: datasets.DownloadManager): url = self.config.data_url dl_dir = dl_manager.download_and_extract(url) task = self.config_id splits = [ SplitGenerator(name=Split.TRAIN, gen_kwargs={"data_file": os.path.join(dl_dir, "train.jsonl")}), SplitGenerator(name=Split.VALIDATION, gen_kwargs={"data_file": os.path.join(dl_dir, "dev.jsonl")}), SplitGenerator(name=Split.TEST, gen_kwargs={"data_file": os.path.join(dl_dir, "test.jsonl")}), ] if not task.startswith("car_cdr_cons") and not task.startswith("car_cdr_rcons"): splits += [ SplitGenerator(name="ood_new", gen_kwargs={"data_file": os.path.join(dl_dir, "ood_new_adj.jsonl")}), SplitGenerator(name="ood_long", gen_kwargs={"data_file": os.path.join(dl_dir, "ood_long_adj.jsonl")}), ] return splits def _generate_examples(self, data_file): with open(data_file, encoding="utf-8") as f: for i, line in enumerate(f): key = str(i) row = json.loads(line) yield key, row if __name__ == "__main__": # short test builder = NcPat.BUILDER_CONFIGS[0] print("name: {}, desc: {}".format(builder.name, builder.description))