|
import csv |
|
import datasets |
|
|
|
_CITATION = """""" |
|
_DESCRIPTION = """""" |
|
_LICENSE = "CC-BY-SA-4.0" |
|
|
|
_DATA_URLS = { |
|
"train": "https://huggingface.co/datasets/raki-1203/ai_hub_summarization/resolve/main/train.tsv", |
|
"dev": "https://huggingface.co/datasets/raki-1203/ai_hub_summarization/resolve/main/valid.tsv", |
|
} |
|
|
|
_VERSION = "0.0.0" |
|
|
|
|
|
class AiHubSummarizationConfig(datasets.BuilderConfig): |
|
def __init__(self, data_url, **kwargs): |
|
super().__init__(version=datasets.Version(_VERSION), **kwargs) |
|
self.data_url = data_url |
|
|
|
|
|
class AiHubSummarization(datasets.GeneratorBasedBuilder): |
|
DEFAULT_CONFIG_NAME = "ai_hub_summarization" |
|
BUILDER_CONFIGS = [ |
|
AiHubSummarizationConfig( |
|
name="ai_hub_summarization", |
|
data_url=_DATA_URLS, |
|
description=_DESCRIPTION, |
|
) |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"passage": datasets.Value("string"), |
|
"abstract_summary": datasets.Value("string"), |
|
} |
|
), |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
supervised_keys=None, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
""" Returns SplitGenerators. """ |
|
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["dev"], |
|
"split": "valid", |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, data_file: str, split: str): |
|
""" Yields examples. """ |
|
with open(data_file, newline='', encoding="UTF-8") as csvfile: |
|
reader = csv.reader(csvfile, delimiter='\t') |
|
feature_names = next(reader) |
|
idx = 0 |
|
for row in reader: |
|
if idx == 0: |
|
continue |
|
features = { |
|
"passage": row[0], |
|
"abstract_summary": row[1], |
|
} |
|
yield idx, features |
|
idx += 1 |
|
|