| | import json |
| | import os |
| | import datasets |
| | from datasets.tasks import TextClassification |
| |
|
| | _DESCRIPTION = """ |
| | GovReport dataset for summarization. |
| | From paper: Efficient Attentions for Long Document Summarization" by L. Huang et al. |
| | See: https://arxiv.org/pdf/2104.02112.pdf |
| | See: https://github.com/luyang-huang96/LongDocSum |
| | """ |
| | _CITATION = """\ |
| | @misc{huang2021efficient, |
| | title={Efficient Attentions for Long Document Summarization}, |
| | author={Luyang Huang and Shuyang Cao and Nikolaus Parulian and Heng Ji and Lu Wang}, |
| | year={2021}, |
| | eprint={2104.02112}, |
| | archivePrefix={arXiv}, |
| | primaryClass={cs.CL} |
| | } |
| | } |
| | """ |
| | _ABSTRACT = "summary" |
| | _ARTICLE = "report" |
| |
|
| | class GovReportSummarizationConfig(datasets.BuilderConfig): |
| | """BuilderConfig for GovReportSummarization.""" |
| |
|
| | def __init__(self, **kwargs): |
| | """BuilderConfig for GovReportSummarization. |
| | Args: |
| | **kwargs: keyword arguments forwarded to super. |
| | """ |
| | super(GovReportSummarizationConfig, self).__init__(**kwargs) |
| |
|
| |
|
| | class GovReportSummarizationDataset(datasets.GeneratorBasedBuilder): |
| | """GovReportSummarization Dataset.""" |
| | |
| | _TRAIN_FILE = "train.zip" |
| | _VAL_FILE = "valid.zip" |
| | _TEST_FILE = "test.zip" |
| |
|
| | BUILDER_CONFIGS = [ |
| | GovReportSummarizationConfig( |
| | name="document", |
| | version=datasets.Version("1.0.0"), |
| | description="GovReport dataset for summarization, document", |
| | ), |
| | ] |
| |
|
| | DEFAULT_CONFIG_NAME = "document" |
| |
|
| | def _info(self): |
| | |
| | return datasets.DatasetInfo( |
| | description=_DESCRIPTION, |
| | features=datasets.Features( |
| | { |
| | _ARTICLE: datasets.Value("string"), |
| | _ABSTRACT: datasets.Value("string"), |
| | |
| | } |
| | ), |
| | supervised_keys=None, |
| | homepage="https://github.com/luyang-huang96/LongDocSum", |
| | citation=_CITATION, |
| | ) |
| |
|
| | def _split_generators(self, dl_manager): |
| |
|
| | train_path = os.path.join(dl_manager.download_and_extract(self._TRAIN_FILE), "train.txt") |
| | val_path = os.path.join(dl_manager.download_and_extract(self._VAL_FILE), "valid.txt") |
| | test_path = os.path.join(dl_manager.download_and_extract(self._TEST_FILE), "test.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 GovReportSummarization examples.""" |
| | with open(filepath, encoding="utf-8") as f: |
| | for id_, row in enumerate(f): |
| | data = json.loads(row) |
| | report = data["report"] |
| | summary = data["summary"] |
| |
|
| | yield id_, {"report": report, "summary": summary} |
| |
|