ccdv commited on
Commit
49c80ad
1 Parent(s): 4769348
Files changed (1) hide show
  1. mediasum.py +124 -0
mediasum.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ import datasets
5
+ from datasets.tasks import TextClassification
6
+
7
+ _CITATION = None
8
+
9
+
10
+ _DESCRIPTION = """
11
+ MediaSum dataset for summarization.
12
+ From paper: "MediaSum: A Large-scale Media Interview Dataset for Dialogue Summarization" by C. Zhu et al."
13
+
14
+ """
15
+ _CITATION = """\
16
+ @article{zhu2021mediasum,
17
+ title={MediaSum: A Large-scale Media Interview Dataset for Dialogue Summarization},
18
+ author={Zhu, Chenguang and Liu, Yang and Mei, Jie and Zeng, Michael},
19
+ journal={arXiv preprint arXiv:2103.06410},
20
+ year={2021}
21
+ }
22
+ """
23
+ _ABSTRACT = "summary"
24
+ _ARTICLE = "utt"
25
+
26
+ class MediaSumSummarizationConfig(datasets.BuilderConfig):
27
+ """BuilderConfig for MediaSumSummarization."""
28
+
29
+ def __init__(self, **kwargs):
30
+ """BuilderConfig for MediaSumSummarization.
31
+ Args:
32
+ **kwargs: keyword arguments forwarded to super.
33
+ """
34
+ super(MediaSumSummarizationConfig, self).__init__(**kwargs)
35
+
36
+
37
+ class MediaSumSummarizationDataset(datasets.GeneratorBasedBuilder):
38
+ """MediaSumSummarization Dataset."""
39
+
40
+ _TRAIN_FILE = "train_data.zip"
41
+ _VAL_FILE = "val_data.zip"
42
+ _TEST_FILE = "test_data.zip"
43
+
44
+ BUILDER_CONFIGS = [
45
+ MediaSumSummarizationConfig(
46
+ name="newline",
47
+ version=datasets.Version("1.0.0"),
48
+ description="MediaSum dataset for summarization, concat sections",
49
+ ),
50
+ MediaSumSummarizationConfig(
51
+ name="roberta",
52
+ version=datasets.Version("1.0.0"),
53
+ description="MediaSum dataset for summarization, document",
54
+ ),
55
+ MediaSumSummarizationConfig(
56
+ name="bert",
57
+ version=datasets.Version("1.0.0"),
58
+ description="MediaSum dataset for summarization, document",
59
+ ),
60
+ MediaSumSummarizationConfig(
61
+ name="list",
62
+ version=datasets.Version("1.0.0"),
63
+ description="MediaSum dataset for summarization, document",
64
+ ),
65
+ ]
66
+
67
+ DEFAULT_CONFIG_NAME = "roberta"
68
+
69
+ def _info(self):
70
+ # Should return a datasets.DatasetInfo object
71
+ return datasets.DatasetInfo(
72
+ description=_DESCRIPTION,
73
+ features=datasets.Features(
74
+ {
75
+ _ARTICLE: datasets.Sequence(datasets.Value("string")) if self.config.name == "list" else datasets.Value("string"),
76
+ _ABSTRACT: datasets.Value("string"),
77
+ #"id": datasets.Value("string"),
78
+ }
79
+ ),
80
+ supervised_keys=None,
81
+ homepage="https://github.com/zcgzcgzcg1/MediaSum",
82
+ citation=_CITATION,
83
+ )
84
+
85
+ def _split_generators(self, dl_manager):
86
+
87
+ train_path = dl_manager.download_and_extract(self._TRAIN_FILE) + "/train_data.txt"
88
+ val_path = dl_manager.download_and_extract(self._VAL_FILE) + "/val_data.txt"
89
+ test_path = dl_manager.download_and_extract(self._TEST_FILE) + "/test_data.txt"
90
+
91
+ return [
92
+ datasets.SplitGenerator(
93
+ name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}
94
+ ),
95
+ datasets.SplitGenerator(
96
+ name=datasets.Split.VALIDATION, gen_kwargs={"filepath": val_path}
97
+ ),
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}
100
+ ),
101
+ ]
102
+
103
+ def _generate_examples(self, filepath):
104
+ """Generate MediaSumSummarization examples."""
105
+ if self.config.name == "newline":
106
+ join_ = "\n"
107
+ elif self.config.name == "roberta":
108
+ join_ = "</s>"
109
+ elif self.config.name == "bert":
110
+ join_ = "[SEP]"
111
+
112
+ with open(filepath, encoding="utf-8") as f:
113
+ for id_, row in enumerate(f):
114
+ data = json.loads(row)
115
+
116
+ """
117
+ 'summary': str,
118
+ 'document': List[str],
119
+ """
120
+ document = data["utt"]
121
+ if self.config.name != "list":
122
+ document = join_.join(document)
123
+ summary = data["summary"]
124
+ yield id_, {"document": document, "summary": summary}