from __future__ import absolute_import, division, print_function import datasets _URLs = { "train": "train.tsv", "valid": "valid.tsv", "test": "test.tsv", } class RottenTomato(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( description="MR Dataset", features=datasets.Features( { "text": datasets.Value("string"), "label": datasets.features.ClassLabel(names=['kill', 'arrest', 'fail to act', 'force']), } ), supervised_keys=None, license="", homepage="", citation="", ) def _split_generators(self, dl_manager): downloaded_files = dl_manager.download_and_extract(_URLs) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "filepath": downloaded_files["train"], } ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "filepath": downloaded_files["valid"], } ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "filepath": downloaded_files["test"], } ), ] def _generate_examples(self, filepath): with open(filepath, "r", encoding='ISO-8859-1') as f: for idx, line in enumerate(f): text, label = line.split("\t") text = " ".join(text.split()[:1000]) yield idx, {"text": text.strip(), "label": label.strip()}