|
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", |
|
), |
|
MediaSumSummarizationConfig( |
|
name="newline_prepended", |
|
version=datasets.Version("1.0.0"), |
|
description="MediaSum dataset for summarization, concat sections", |
|
), |
|
MediaSumSummarizationConfig( |
|
name="roberta_prepended", |
|
version=datasets.Version("1.0.0"), |
|
description="MediaSum dataset for summarization, document", |
|
), |
|
MediaSumSummarizationConfig( |
|
name="bert_prepended", |
|
version=datasets.Version("1.0.0"), |
|
description="MediaSum dataset for summarization, document", |
|
), |
|
MediaSumSummarizationConfig( |
|
name="list_prepended", |
|
version=datasets.Version("1.0.0"), |
|
description="MediaSum dataset for summarization, document", |
|
), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "roberta_prepended" |
|
|
|
def _info(self): |
|
|
|
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"), |
|
|
|
} |
|
), |
|
supervised_keys=None, |
|
homepage="https://github.com/zcgzcgzcg1/MediaSum", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
train_path = os.path.join(dl_manager.download_and_extract(self._TRAIN_FILE), "train_data.txt") |
|
val_path = os.path.join(dl_manager.download_and_extract(self._VAL_FILE), "val_data.txt") |
|
test_path = os.path.join(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 "newline" in self.config.name: |
|
join_ = "\n" |
|
elif "roberta" in self.config.name: |
|
join_ = "</s>" |
|
elif "bert" in self.config.name: |
|
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], |
|
""" |
|
|
|
documents = data["utt"] |
|
|
|
if "_prepended" in self.config.name: |
|
names = data["speaker"] |
|
documents = [name + ": " + document for name, document in zip(names, documents)] |
|
|
|
if self.config.name != "list": |
|
documents = join_.join(documents) |
|
summary = data["summary"] |
|
yield id_, {"document": documents, "summary": summary} |
|
|