|
import datasets |
|
import csv |
|
import os |
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {A great new dataset}, |
|
author={huggingface, Inc. |
|
}, |
|
year={2020} |
|
} |
|
""" |
|
|
|
|
|
_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( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
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, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir["train"], |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir["test"], |
|
"split": "test" |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
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 |
|
} |
|
|