| import csv | |
| import datasets | |
| from datasets.download.download_manager import DownloadManager | |
| _CITATION = """""" | |
| _DESCRIPTION = "hugging face dataset 공유해보기 연습" | |
| _LICENSE = "CC-BY-SA-4.0" | |
| _URL = "https://github.com/KyungHyunLim/hf_dataset_test" | |
| _DATA_URLS = { | |
| "train": "https://huggingface.co/datasets/KHLim/boost_camp/resolve/main/train.csv", | |
| "valid": "https://huggingface.co/datasets/KHLim/boost_camp/resolve/main/dev.csv" | |
| } | |
| _VERSION = "0.0.0" | |
| class MyDataConfig(datasets.BuilderConfig): | |
| def __init__(self, data_url, **kwargs): | |
| super().__init__(version=datasets.Version(_VERSION), **kwargs) | |
| self.data_url = data_url | |
| class MYData(datasets.GeneratorBasedBuilder): | |
| DEFAULT_CONFIG_NAME = "mydata" | |
| BUILDER_CONFIGS = [ | |
| MyDataConfig( | |
| name="mydata", | |
| data_url=_DATA_URLS, | |
| description=_DESCRIPTION | |
| ) | |
| ] | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=datasets.Features( | |
| { | |
| "id": datasets.Value("string"), | |
| "source": datasets.Value("string"), | |
| "sentence_1": datasets.Value("string"), | |
| "sentence_2": datasets.Value("string"), | |
| "label": datasets.Value("float"), | |
| "binary-label": datasets.Value("float") | |
| } | |
| ), | |
| homepage=_URL, | |
| license=_LICENSE, | |
| citation=_CITATION, | |
| supervised_keys=None, | |
| ) | |
| def _split_generators(self, dl_manager: DownloadManager): | |
| data_file = dl_manager.download_and_extract(self.config.data_url) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| gen_kwargs={ | |
| "data_file": data_file['train'], | |
| "split": "train" | |
| }, | |
| ), | |
| datasets.SplitGenerator( | |
| name=datasets.Split.VALIDATION, | |
| gen_kwargs={ | |
| "data_file": data_file['valid'], | |
| "split": "valid" | |
| } | |
| ) | |
| ] | |
| def _generate_examples(self, data_file:str, split:str): | |
| with open(data_file, newline='', encoding='utf-8') as f: | |
| reader = csv.reader(f, delimiter=',') | |
| features_names = next(reader) | |
| idx = 0 | |
| for row in reader: | |
| features = { | |
| "id": row[0], | |
| "source": row[1], | |
| "sentence_1": row[2], | |
| "sentence_2": row[3], | |
| "label": row[4], | |
| "binary-label": row[5] | |
| } | |
| yield idx, features | |
| idx += 1 |