File size: 5,283 Bytes
49c80ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c90474f
49c80ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec0eca8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49c80ad
 
ec0eca8
49c80ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12ab0f8
 
 
49c80ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec0eca8
49c80ad
ec0eca8
49c80ad
ec0eca8
 
49c80ad
 
 
 
 
 
 
 
 
c90474f
ec0eca8
 
 
 
 
c90474f
49c80ad
ec0eca8
49c80ad
ec0eca8
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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):
        # 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 = 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}