Datasets:
adding data builder script
Browse files
usb.py
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Acknowledgement: dataset builder script adapted from https://huggingface.co/datasets/glue/blob/main/glue.py
|
2 |
+
|
3 |
+
import datasets
|
4 |
+
import pdb
|
5 |
+
import jsonlines
|
6 |
+
|
7 |
+
CITATION_BLOB = '''
|
8 |
+
@article{krishna2023usb,
|
9 |
+
title={USB: A Unified Summarization Benchmark Across Tasks and Domains},
|
10 |
+
author={Krishna, Kundan and Gupta, Prakhar and Ramprasad, Sanjana and Wallace, Byron C and Bigham, Jeffrey P and Lipton, Zachary C},
|
11 |
+
booktitle={Findings of the Association for Computational Linguistics: EMNLP 2023},
|
12 |
+
year={2023}
|
13 |
+
}
|
14 |
+
'''
|
15 |
+
|
16 |
+
DESCRIPTION_BLOB = '''
|
17 |
+
The USB benchmark consists of labeled datasets for a collection of 8 tasks dealing with text summarization,
|
18 |
+
particularly focusing on factuality and controllability of summary generation.
|
19 |
+
Paper can be found here : https://arxiv.org/abs/2305.14296
|
20 |
+
'''
|
21 |
+
|
22 |
+
|
23 |
+
class USBConfig(datasets.BuilderConfig):
|
24 |
+
def __init__(
|
25 |
+
self,
|
26 |
+
text_features,
|
27 |
+
label_column,
|
28 |
+
citation=CITATION_BLOB,
|
29 |
+
data_url="processed_data.tar.gz",
|
30 |
+
label_classes=None,
|
31 |
+
process_label=lambda x: x,
|
32 |
+
**kwargs,
|
33 |
+
):
|
34 |
+
super(USBConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
35 |
+
self.text_features = text_features
|
36 |
+
self.label_column = label_column
|
37 |
+
|
38 |
+
self.citation = citation
|
39 |
+
self.label_classes = label_classes
|
40 |
+
self.process_label = process_label
|
41 |
+
self.url = "https://github.com/kukrishna/usb"
|
42 |
+
|
43 |
+
self.data_url=data_url
|
44 |
+
|
45 |
+
|
46 |
+
class USB(datasets.GeneratorBasedBuilder):
|
47 |
+
"""The Unified Summarization Benchmark."""
|
48 |
+
|
49 |
+
BUILDER_CONFIGS = [
|
50 |
+
USBConfig(
|
51 |
+
name="topicbased_summarization",
|
52 |
+
description="Generate a short summary of the given article covering the given topic",
|
53 |
+
text_features={"summ_idx": "int", "input_lines": "listsent", "topic_name": "sent", "output_lines":"listsent"},
|
54 |
+
label_column="output_lines",
|
55 |
+
),
|
56 |
+
USBConfig(
|
57 |
+
name="fixing_factuality",
|
58 |
+
description="Given a summary sentence (claim) and presented evidence from the article, edit the summary to remove unsupported or contradicting facts",
|
59 |
+
text_features={"summ_idx": "int", "input_lines": "listsent", "initial_summary": "sent", "fixed_summary":"sent"},
|
60 |
+
label_column="fixed_summary",
|
61 |
+
),
|
62 |
+
USBConfig(
|
63 |
+
name="unsupported_span_prediction",
|
64 |
+
description="Given a summary sentence (claim) and presented evidence from the article, mark the parts of the summary which are not supported by the evidence by surrounding them with [] and [/] tags.",
|
65 |
+
text_features={"summ_idx": "int", "input_lines": "listsent", "summary": "sent", "annotated_summary":"sent"},
|
66 |
+
label_column="annotated_summary",
|
67 |
+
),
|
68 |
+
USBConfig(
|
69 |
+
name="evidence_extraction",
|
70 |
+
description="Given an article and its summary, for each summary sentence, produce a minimal list of sentences from the article which provide sufficient evidence for all facts in the summary sentence.",
|
71 |
+
text_features={"input_lines": "listsent", "summary_lines": "listsent", "evidence_labels":"listlistint"},
|
72 |
+
label_column="evidence_labels",
|
73 |
+
),
|
74 |
+
USBConfig(
|
75 |
+
name="multisentence_compression",
|
76 |
+
description="Given a list of sentences from an article, generate a single sentence summary of the presented cluster of sentences.",
|
77 |
+
text_features={"summ_idx": "int", "input_lines": "listsent", "output_lines": "listsent"},
|
78 |
+
label_column="output_lines",
|
79 |
+
),
|
80 |
+
USBConfig(
|
81 |
+
name="extractive_summarization",
|
82 |
+
description="Given an article, generate an extractive summary by producing a subset o the article's sentences",
|
83 |
+
text_features={"input_lines": "listsent", "labels": "listint"},
|
84 |
+
label_column="labels",
|
85 |
+
),
|
86 |
+
USBConfig(
|
87 |
+
name="abstractive_summarization",
|
88 |
+
description="Given an article, generate its abstractive summary",
|
89 |
+
text_features={"input_lines": "listsent", "output_lines": "listsent"},
|
90 |
+
label_column="output_lines",
|
91 |
+
),
|
92 |
+
USBConfig(
|
93 |
+
name="factuality_classification",
|
94 |
+
description="Given a summary sentence (claim) and presented evidence from the article, predict whether all facts of the claim are supported by and in agreement with the presented evidence, or not.",
|
95 |
+
text_features={"summ_idx": "int", "input_lines": "listsent", "summary_sent": "sent", "label":"int"},
|
96 |
+
label_column="label",
|
97 |
+
),
|
98 |
+
]
|
99 |
+
|
100 |
+
def _split_generators(self, dl_manager):
|
101 |
+
|
102 |
+
data_root = dl_manager.download_and_extract(self.config.data_url)
|
103 |
+
|
104 |
+
return [
|
105 |
+
datasets.SplitGenerator(
|
106 |
+
name=datasets.Split.TRAIN,
|
107 |
+
gen_kwargs={
|
108 |
+
"data_file": f"{data_root}/{self.config.name}/train.jsonl",
|
109 |
+
"split": "train",
|
110 |
+
},
|
111 |
+
),
|
112 |
+
datasets.SplitGenerator(
|
113 |
+
name=datasets.Split.VALIDATION,
|
114 |
+
gen_kwargs={
|
115 |
+
"data_file": f"{data_root}/{self.config.name}/validation.jsonl",
|
116 |
+
"split": "validation",
|
117 |
+
},
|
118 |
+
),
|
119 |
+
datasets.SplitGenerator(
|
120 |
+
name=datasets.Split.TEST,
|
121 |
+
gen_kwargs={
|
122 |
+
"data_file": f"{data_root}/{self.config.name}/test.jsonl",
|
123 |
+
"split": "test",
|
124 |
+
},
|
125 |
+
),
|
126 |
+
]
|
127 |
+
|
128 |
+
def _generate_examples(self, data_file, split):
|
129 |
+
with jsonlines.open(data_file) as f:
|
130 |
+
for ex_idx,example in enumerate(f):
|
131 |
+
example["id"] = example["id"]+":"+str(ex_idx)
|
132 |
+
example["domain"] = example["id"].split("/")[0]
|
133 |
+
yield example["id"], example
|
134 |
+
|
135 |
+
def _info(self):
|
136 |
+
features = {}
|
137 |
+
features["id"] = datasets.Value("string")
|
138 |
+
features["domain"] = datasets.Value("string")
|
139 |
+
|
140 |
+
for (text_feature,dtype) in self.config.text_features.items():
|
141 |
+
hf_dtype = None
|
142 |
+
if dtype=="int":
|
143 |
+
hf_dtype = datasets.Value("int32")
|
144 |
+
elif dtype=="listint":
|
145 |
+
hf_dtype = datasets.Sequence(datasets.Value("int32"))
|
146 |
+
elif dtype=="listlistint":
|
147 |
+
hf_dtype = datasets.Sequence(datasets.Sequence(datasets.Value("int32")))
|
148 |
+
elif dtype=="sent":
|
149 |
+
hf_dtype = datasets.Value("string")
|
150 |
+
elif dtype=="listsent":
|
151 |
+
hf_dtype = datasets.Sequence(datasets.Value("string"))
|
152 |
+
else:
|
153 |
+
raise NotImplementedError
|
154 |
+
|
155 |
+
features[text_feature] = hf_dtype
|
156 |
+
|
157 |
+
return datasets.DatasetInfo(
|
158 |
+
description=DESCRIPTION_BLOB,
|
159 |
+
features=datasets.Features(features),
|
160 |
+
homepage=self.config.url,
|
161 |
+
citation=self.config.citation,
|
162 |
+
)
|