ighina commited on
Commit
95410e8
1 Parent(s): c09f9db

Upload sumipcc_dataset.py

Browse files
Files changed (1) hide show
  1. sumipcc_dataset.py +289 -0
sumipcc_dataset.py ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """Sum-IPCC: Climate Change Report Summarization with Large Language Models"""
17
+
18
+ import os
19
+ import datasets
20
+ import yaml
21
+ import textwrap
22
+
23
+
24
+ _CITATION = """
25
+ @misc{IPCC,
26
+ title={Climate Change Report Summarization with Large Language Models},
27
+ author={Leonardo Catalano, Tommaso Colella and Iacopo Ghinassi},
28
+ year={2024},
29
+ eprint={},
30
+ archivePrefix={},
31
+ primaryClass={}
32
+ }
33
+ """
34
+
35
+ _DESCRIPTION = """\
36
+ A dataset for summarization for policy makers of IPCC synthesis reports for climate change.
37
+ """
38
+
39
+ _HOMEPAGE = ""
40
+
41
+ _LICENSE = ""
42
+
43
+ _SumIPCCsum_BASE_KWARGS = dict(
44
+ citation=_CITATION,
45
+ url=_HOMEPAGE,
46
+ )
47
+
48
+
49
+ class SumIPCCConfig(datasets.BuilderConfig):
50
+ """BuilderConfig for Climabench."""
51
+
52
+ def __init__(
53
+ self,
54
+ data_dir,
55
+ citation,
56
+ url,
57
+ **kwargs,
58
+ ):
59
+ """BuilderConfig for Climabench.
60
+ Args:
61
+ data_dir: `string`, the path to the folder containing the tsv files in the
62
+ downloaded zip
63
+ """
64
+ super(SumIPCCConfig, self).__init__(
65
+ version=datasets.Version("1.0.0", ""), **kwargs
66
+ )
67
+ self.data_dir = data_dir
68
+ self.citation = citation
69
+ self.url = url
70
+
71
+
72
+ class SumIPCC(datasets.GeneratorBasedBuilder):
73
+ """SumIPCC dataset."""
74
+
75
+ BUILDER_CONFIGS = [
76
+ SumIPCCConfig(
77
+ name="AR6",
78
+ description=textwrap.dedent(
79
+ """
80
+ This Synthesis Report (SYR) of the IPCC Sixth Assessment Report (AR6)
81
+ summarises the state of knowledge of climate change, its widespread
82
+ impacts and risks, and climate change mitigation and adaptation, based
83
+ on the peer-reviewed scientific, technical and socio-economic literature
84
+ since the publication of the IPCC’s Fifth Assessment Report (AR5) in
85
+ 2014.
86
+ The assessment is undertaken within the context of the evolving
87
+ international landscape, in particular, developments in the UN
88
+ Framework Convention on Climate Change (UNFCCC) process,
89
+ including the outcomes of the Kyoto Protocol and the adoption of the
90
+ Paris Agreement. It reflects the increasing diversity of those involved in
91
+ climate action.
92
+ This report integrates the main findings of the AR6 Working Group
93
+ reports58 and the three AR6 Special Reports 59
94
+ . It recognizes the
95
+ interdependence of climate, ecosystems and biodiversity, and human
96
+ societies; the value of diverse forms of knowledge; and the close
97
+ linkages between climate change adaptation, mitigation, ecosystem
98
+ health, human well-being and sustainable development. Building on
99
+ multiple analytical frameworks, including those from the physical and
100
+ social sciences, this report identifies opportunities for transformative
101
+ action which are effective, feasible, just and equitable using concepts
102
+ of systems transitions and resilient development pathways 60
103
+ . Different
104
+ regional classification schemes 61 are used for physical, social and
105
+ economic aspects, reflecting the underlying literature.
106
+ After this introduction, Section 2, ‘Current Status and Trends’, opens
107
+ with the assessment of observational evidence for our changing
108
+ climate, historical and current drivers of human-induced climate
109
+ change, and its impacts. It assesses the current implementation of
110
+ adaptation and mitigation response options. Section 3, ‘Long-Term
111
+ Climate and Development Futures’, provides a long-term assessment of
112
+ climate change to 2100 and beyond in a broad range of socio-economic
113
+ futures. It considers long-term characteristics, impacts, risks and costs
114
+ in adaptation and mitigation pathways in the context of sustainable
115
+ development. Section 4, ‘Near- Term Responses in a Changing Climate’,
116
+ assesses opportunities for scaling up effective action in the period up
117
+ to 2040, in the context of climate pledges, and commitments, and the
118
+ pursuit of sustainable development.
119
+ Based on scientific understanding, key findings can be formulated as
120
+ statements of fact or associated with an assessed level of confidence
121
+ using the IPCC calibrated language62
122
+ . The scientific findings are
123
+ drawn from the underlying reports and arise from their Summary for
124
+ Policymakers (hereafter SPM), Technical Summary (hereafter TS), and
125
+ underlying chapters and are indicated by {} brackets. Figure 1.1 shows
126
+ the Synthesis Report Figures Key, a guide to visual icons that are used
127
+ across multiple figures within this report.
128
+ """
129
+ ),
130
+ data_dir="all_data/AR6",
131
+ citation=textwrap.dedent(
132
+ """\
133
+ @misc{IPCCAR6,
134
+ title = {AR6 Synthesis Report Climate Change 2023},
135
+ author = {IPCC},
136
+ year={2024}
137
+ url = {https://www.ipcc.ch/report/ar6/syr/downloads/report/IPCC_AR6_SYR_LongerReport.pdf},
138
+ }
139
+ }"""
140
+ ),
141
+ url="https://www.ipcc.ch/report/ar6/syr/",
142
+ ),
143
+ SumIPCCConfig(
144
+ name="AR5",
145
+ description=textwrap.dedent(
146
+ """
147
+ The Synthesis Report (SYR), constituting the final product of the Fifth
148
+ Assessment Report (AR5) of the Intergovernmental Panel on Climate
149
+ Change (IPCC), is published under the title Climate Change 2014. This
150
+ report distils, synthesizes and integrates the key findings of the three
151
+ Working Group contributions – The Physical Science Basis, Impacts,
152
+ Adaptation, and Vulnerability and Mitigation of Climate Change – to
153
+ the AR5 in a concise document for the benefit of decision makers in
154
+ the government, the private sector as well as the public at large. The
155
+ SYR also draws on the findings of the two Special Reports brought out
156
+ in 2011 dealing with Renewable Energy Sources and Climate Change
157
+ Mitigation, and Managing the Risks of Extreme Events and Disasters to
158
+ Advance Climate Change Adaptation. The SYR, therefore, is a compre-
159
+ hensive up-to-date compilation of assessments dealing with climate
160
+ change, based on the most recent scientific, technical and socio-economic
161
+ literature in the field.
162
+ """
163
+ ),
164
+ data_dir="all_data/AR5",
165
+ citation=textwrap.dedent(
166
+ """\
167
+ @misc{IPCCAR5,
168
+ title = {AR5 Synthesis Report: Climate Change 2014},
169
+ author = {IPCC},
170
+ year={2014}
171
+ url = {https://www.ipcc.ch/site/assets/uploads/2018/02/SYR_AR5_FINAL_full.pdf},
172
+ }
173
+ }"""
174
+ ),
175
+ url="https://www.ipcc.ch/report/ar5/syr/",
176
+ ),
177
+ SumIPCCConfig(
178
+ name="ALL",
179
+ description=textwrap.dedent(
180
+ """
181
+ The concatenation of AR5 and AR6 synthesis reports from IPCC
182
+ """
183
+ ),
184
+ data_dir="all_data",
185
+ citation=textwrap.dedent(
186
+ """\
187
+ @misc{IPCC,
188
+ title = {IPCC Homepage},
189
+ author = {IPCC},
190
+ year={2024}
191
+ url = {https://www.ipcc.ch/},
192
+ }
193
+ }"""
194
+ ),
195
+ url="https://www.ipcc.ch/"
196
+ )
197
+ ]
198
+
199
+ def _info(self):
200
+ features = datasets.Features(
201
+ {
202
+ "full_paragraphs": datasets.Sequence(datasets.Value("string")),
203
+ "summary": datasets.Value("string"),
204
+ "summary_topic": datasets.Value("string"),
205
+ "paragraph_topic": datasets.Value("string"),
206
+ "section_topic": datasets.Value("string"),
207
+ "source": datasets.Value("string"),
208
+ "paragraph_ids": datasets.Sequence(datasets.Value("string")),
209
+ "paragraph_titles": datasets.Sequence(datasets.Value("string")),
210
+ "ID": datasets.Value("string")
211
+ }
212
+ )
213
+
214
+ return datasets.DatasetInfo(
215
+ description=_DESCRIPTION,
216
+ features=datasets.Features(features),
217
+ homepage=self.config.url,
218
+ citation=self.config.citation + "\n" + _CITATION,
219
+ )
220
+
221
+ def _split_generators(self, dl_manager):
222
+ data_dir = self.config.data_dir
223
+
224
+ if self.config.name == "ALL":
225
+ files = []
226
+ for root, directs, _ in os.walk(data_dir):
227
+ for direct in directs:
228
+ file_name = [file for file in os.listdir(os.path.join(root, direct)) if file.endswith("yaml")]
229
+ assert len(file_name) == 1, "Too many yaml files in directory"
230
+ file_name = file_name[0]
231
+ files.append(os.path.join(root, direct, file_name))
232
+ else:
233
+ files = []
234
+ for root, _, fls in os.walk(data_dir):
235
+ file_name = [file for file in fls if file.endswith("yaml")]
236
+ assert len(file_name) == 1, "Too many yaml files in directory"
237
+ file_name = file_name[0]
238
+ files.append(os.path.join(root, file_name))
239
+
240
+ return [
241
+ datasets.SplitGenerator(
242
+ name=datasets.Split.TEST,
243
+ gen_kwargs={
244
+ "data_files": files,
245
+ "split": "test",
246
+ },
247
+ ),
248
+ ]
249
+
250
+ def _generate_examples(self, data_files, split):
251
+ #idx = iter(range(10000))
252
+ idx = -1
253
+ for data_file in data_files:
254
+ with open(data_file, encoding='utf-8') as f:
255
+ doc = yaml.safe_load(f)
256
+ for identifier in doc["summaries"]:
257
+ idx += 1
258
+ yield from self._process_example(doc, identifier, data_file, idx)
259
+
260
+ def _process_example(self, doc,
261
+ identifier,
262
+ source,
263
+ idx):
264
+
265
+ summary = doc["summaries"][identifier]
266
+ full_para = doc["full_paragraphs"][identifier]
267
+
268
+ para_topic = doc["paragraph_topics"][identifier]
269
+ sect_topic = doc["section_topics"][identifier]
270
+ summary_topic = doc["summary_topics"][identifier]
271
+
272
+ para_id = doc["pointers"][identifier]
273
+ para_title = doc["titles"][identifier]
274
+
275
+ yield idx, {"full_paragraphs": full_para,
276
+ "summary": summary,
277
+ "paragraph_topic": para_topic,
278
+ "section_topic": sect_topic,
279
+ "summary_topic": summary_topic,
280
+ "source": source,
281
+ "paragraph_ids": para_id,
282
+ "paragraph_titles": para_title,
283
+ "ID": identifier}
284
+
285
+ # do this in some postprocess function after generating yaml
286
+ # def _clean(self, text):
287
+ # text = re.sub("\n", " ", text)
288
+ # text = re.sub("'", "", text)
289
+ # return text.strip()