"""WRENCH classification dataset.""" import json import datasets class WrenchConfig(datasets.BuilderConfig): """BuilderConfig for WRENCH.""" def __init__( self, dataset_path, **kwargs, ): super(WrenchConfig, self).__init__( version=datasets.Version("1.0.0", ""), **kwargs ) self.dataset_path = dataset_path class Wrench(datasets.GeneratorBasedBuilder): """WRENCH classification dataset.""" BUILDER_DICT = [ { "name": "imdb", "dataset_path": "./imdb", }, { "name": "yelp", "dataset_path": "./yelp", }, { "name": "youtube", "dataset_path": "./youtube", }, { "name": "sms", "dataset_path": "./sms", }, { "name": "trec", "dataset_path": "./trec", }, { "name": "cdr", "dataset_path": "./cdr", }, { "name": "semeval", "dataset_path": "./semeval", }, { "name": "Bioresponse", "dataset_path": "./Bioresponse", }, { "name": "wikigold", "dataset_path": "./wikigold", }, { "name": "PhishingWebsites", "dataset_path": "./PhishingWebsites", }, { "name": "bank-marketing", "dataset_path": "./bank-marketing", }, { "name": "spambase", "dataset_path": "./spambase", }, { "name": "mit-movie", "dataset_path": "./mit-movie", }, { "name": "basketball", "dataset_path": "./basketball", }, { "name": "agnews", "dataset_path": "./agnews", }, { "name": "commercial", "dataset_path": "./commercial", }, { "name": "spouse", "dataset_path": "./spouse", }, { "name": "mit-restaurant", "dataset_path": "./mit-restaurant", }, { "name": "conll", "dataset_path": "./conll", }, { "name": "chemprot", "dataset_path": "./chemprot", }, { "name": "ncbi-diseas", "dataset_path": "./ncbi-diseas", }, { "name": "bc5cdr", "dataset_path": "./bc5cdr", }, { "name": "mushroom", "dataset_path": "./mushroom", }, { "name": "laptopreview", "dataset_path": "./laptopreview", }, { "name": "census", "dataset_path": "./census", }, { "name": "tennis", "dataset_path": "./tennis", }, ] BUILDER_CONFIGS = [ WrenchConfig(name=i["name"], dataset_path=i["dataset_path"]) for i in BUILDER_DICT ] def _info(self): return datasets.DatasetInfo( features=datasets.Features( { "text": datasets.Value("string"), "label": datasets.Value("int8"), "weak_labels": datasets.Sequence(datasets.Value("int8")), } ) ) def _split_generators(self, dl_manager): dataset_path = self.config.dataset_path train_path = dl_manager.download_and_extract(f"{dataset_path}/train.json") valid_path = dl_manager.download_and_extract(f"{dataset_path}/valid.json") test_path = dl_manager.download_and_extract(f"{dataset_path}/test.json") return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path} ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={"filepath": valid_path} ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={"filepath": test_path} ), ] def _generate_examples(self, filepath): """Generate Custom examples.""" print(f"\n\n\n{filepath}\n\n\n\n\n\n\n") with open(filepath, encoding="utf-8") as f: json_data = json.load(f) print("\n\n", json_data, "\n\n") list_of_dicts = [dict(key=key, **value) for key, value in json_data.items()] print("\n\n", list_of_dicts, "\n\n") for idx in list_of_dicts: data = json_data[idx] text = data["data"]["text"] weak_labels = data["weak_labels"] label = data["label"] yield int(idx), { "text": text, "label": label, "weak_labels": weak_labels, }