import json import os import datasets from datasets.tasks import TextClassification _CITATION = None _DESCRIPTION = """ MediaSum dataset for summarization. From paper: "MediaSum: A Large-scale Media Interview Dataset for Dialogue Summarization" by C. Zhu et al." """ _CITATION = """\ @article{zhu2021mediasum, title={MediaSum: A Large-scale Media Interview Dataset for Dialogue Summarization}, author={Zhu, Chenguang and Liu, Yang and Mei, Jie and Zeng, Michael}, journal={arXiv preprint arXiv:2103.06410}, year={2021} } """ _ABSTRACT = "summary" _ARTICLE = "document" class MediaSumSummarizationConfig(datasets.BuilderConfig): """BuilderConfig for MediaSumSummarization.""" def __init__(self, **kwargs): """BuilderConfig for MediaSumSummarization. Args: **kwargs: keyword arguments forwarded to super. """ super(MediaSumSummarizationConfig, self).__init__(**kwargs) class MediaSumSummarizationDataset(datasets.GeneratorBasedBuilder): """MediaSumSummarization Dataset.""" _TRAIN_FILE = "train_data.zip" _VAL_FILE = "val_data.zip" _TEST_FILE = "test_data.zip" BUILDER_CONFIGS = [ MediaSumSummarizationConfig( name="newline", version=datasets.Version("1.0.0"), description="MediaSum dataset for summarization, concat sections", ), MediaSumSummarizationConfig( name="roberta", version=datasets.Version("1.0.0"), description="MediaSum dataset for summarization, document", ), MediaSumSummarizationConfig( name="bert", version=datasets.Version("1.0.0"), description="MediaSum dataset for summarization, document", ), MediaSumSummarizationConfig( name="list", version=datasets.Version("1.0.0"), description="MediaSum dataset for summarization, document", ), ] DEFAULT_CONFIG_NAME = "roberta" def _info(self): # Should return a datasets.DatasetInfo object return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { _ARTICLE: datasets.Sequence(datasets.Value("string")) if self.config.name == "list" else datasets.Value("string"), _ABSTRACT: datasets.Value("string"), #"id": datasets.Value("string"), } ), supervised_keys=None, homepage="https://github.com/zcgzcgzcg1/MediaSum", citation=_CITATION, ) def _split_generators(self, dl_manager): train_path = dl_manager.download_and_extract(self._TRAIN_FILE) + "/train_data.txt" val_path = dl_manager.download_and_extract(self._VAL_FILE) + "/val_data.txt" test_path = dl_manager.download_and_extract(self._TEST_FILE) + "/test_data.txt" return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path} ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={"filepath": val_path} ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={"filepath": test_path} ), ] def _generate_examples(self, filepath): """Generate MediaSumSummarization examples.""" if self.config.name == "newline": join_ = "\n" elif self.config.name == "roberta": join_ = "" elif self.config.name == "bert": join_ = "[SEP]" with open(filepath, encoding="utf-8") as f: for id_, row in enumerate(f): data = json.loads(row) """ 'summary': str, 'document': List[str], """ document = data["utt"] if self.config.name != "list": document = join_.join(document) summary = data["summary"] yield id_, {"document": document, "summary": summary}