File size: 3,219 Bytes
f4422b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7f9639
 
f4422b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4fcd499
f4422b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dad9468
 
 
f4422b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5312831
f4422b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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):
        # Should return a datasets.DatasetInfo object
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    _ARTICLE: datasets.Value("string"),
                    _ABSTRACT: datasets.Value("string"),
                    #"id": 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}