import datasets import csv import os _CITATION = """\ @InProceedings{huggingface:dataset, title = {A great new dataset}, author={huggingface, Inc. }, year={2020} } """ # You can copy an official description _DESCRIPTION = """\ This new dataset is designed to solve this great NLP task and is crafted with a lot of care. """ _HOMEPAGE = "" _LICENSE = "" _URL = "https://huggingface.co/datasets/sebastiaan/test-cefr/resolve/main/" _URLS = { "train": _URL + "train_dataset.csv", "test": _URL + "test_dataset.csv", "val": _URL + "val_dataset.csv", } class CefrDataset(datasets.GeneratorBasedBuilder): VERSION = datasets.Version("1.1.0") def _info(self): features = datasets.Features( { "prompt": datasets.Value("string"), "label": datasets.Value("string") } ) return datasets.DatasetInfo( # This is the description that will appear on the datasets page. description=_DESCRIPTION, # 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, # specify them here. They'll be used if as_supervised=True in # builder.as_dataset. supervised_keys=None, # 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): """Returns SplitGenerators.""" my_urls = _URLS data_dir = dl_manager.download_and_extract(my_urls) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": data_dir["train"], "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": data_dir["test"], "split": "test" }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": data_dir["val"], "split": "val", }, ), ] def _generate_examples( self, filepath, split ): """ Yields examples as (key, example) tuples. """ with open(filepath, encoding="utf-8") as csv_file: csv_reader = csv.reader( csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True ) next(csv_reader, None) for id_, row in enumerate(csv_reader): (prompt, label) = row yield id_, { "prompt": prompt, "label": label }