Datasets:
shuyangcao
commited on
Commit
•
e16adeb
1
Parent(s):
ffb7021
First version
Browse files- .gitattributes +1 -0
- README.md +229 -0
- data/test.jsonl +3 -0
- data/train.jsonl +3 -0
- data/valid.jsonl +3 -0
- gov_report_qs.py +285 -0
.gitattributes
CHANGED
@@ -35,3 +35,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
35 |
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
36 |
*.ogg filter=lfs diff=lfs merge=lfs -text
|
37 |
*.wav filter=lfs diff=lfs merge=lfs -text
|
|
|
|
35 |
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
36 |
*.ogg filter=lfs diff=lfs merge=lfs -text
|
37 |
*.wav filter=lfs diff=lfs merge=lfs -text
|
38 |
+
*.jsonl filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
annotations_creators:
|
3 |
+
- expert-generated
|
4 |
+
language_creators:
|
5 |
+
- expert-generated
|
6 |
+
languages:
|
7 |
+
- en
|
8 |
+
licenses:
|
9 |
+
- cc-by-4.0
|
10 |
+
multilinguality:
|
11 |
+
- monolingual
|
12 |
+
size_categories:
|
13 |
+
- 10K<n<100K
|
14 |
+
source_datasets:
|
15 |
+
- launch/gov_report
|
16 |
+
task_categories:
|
17 |
+
- summarization
|
18 |
+
task_ids:
|
19 |
+
- summarization
|
20 |
+
pretty_name: GovReport-QS
|
21 |
+
---
|
22 |
+
|
23 |
+
|
24 |
+
# Dataset Card for GovReport-QS
|
25 |
+
|
26 |
+
## Table of Contents
|
27 |
+
- [Table of Contents](#table-of-contents)
|
28 |
+
- [Dataset Description](#dataset-description)
|
29 |
+
- [Dataset Summary](#dataset-summary)
|
30 |
+
- [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
|
31 |
+
- [Languages](#languages)
|
32 |
+
- [Dataset Structure](#dataset-structure)
|
33 |
+
- [Data Instances](#data-instances)
|
34 |
+
- [Data Fields](#data-fields)
|
35 |
+
- [Data Splits](#data-splits)
|
36 |
+
- [Dataset Creation](#dataset-creation)
|
37 |
+
- [Curation Rationale](#curation-rationale)
|
38 |
+
- [Source Data](#source-data)
|
39 |
+
- [Annotations](#annotations)
|
40 |
+
- [Personal and Sensitive Information](#personal-and-sensitive-information)
|
41 |
+
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
42 |
+
- [Social Impact of Dataset](#social-impact-of-dataset)
|
43 |
+
- [Discussion of Biases](#discussion-of-biases)
|
44 |
+
- [Other Known Limitations](#other-known-limitations)
|
45 |
+
- [Additional Information](#additional-information)
|
46 |
+
- [Dataset Curators](#dataset-curators)
|
47 |
+
- [Licensing Information](#licensing-information)
|
48 |
+
- [Citation Information](#citation-information)
|
49 |
+
- [Contributions](#contributions)
|
50 |
+
|
51 |
+
## Dataset Description
|
52 |
+
|
53 |
+
- **Homepage:** [https://gov-report-data.github.io](https://gov-report-data.github.io)
|
54 |
+
- **Repository:** [https://github.com/ShuyangCao/hibrids_summ](https://github.com/ShuyangCao/hibrids_summ)
|
55 |
+
- **Paper:** [https://aclanthology.org/2022.acl-long.58/](https://aclanthology.org/2022.acl-long.58/)
|
56 |
+
- **Leaderboard:** [Needs More Information]
|
57 |
+
- **Point of Contact:** [Needs More Information]
|
58 |
+
|
59 |
+
### Dataset Summary
|
60 |
+
|
61 |
+
Based on the GovReport dataset, GovReport-QS additionally includes annotated question-summary hierarchies for government reports. This hierarchy proactively highlights the document structure, to further promote content engagement and comprehension.
|
62 |
+
|
63 |
+
### Supported Tasks and Leaderboards
|
64 |
+
|
65 |
+
[More Information Needed]
|
66 |
+
|
67 |
+
### Languages
|
68 |
+
|
69 |
+
English
|
70 |
+
|
71 |
+
## Dataset Structure
|
72 |
+
|
73 |
+
Two configs are available:
|
74 |
+
- **paragraph** (default): paragraph-level annotated data
|
75 |
+
- **document**: aggregated paragraph-level annotated data for the same document
|
76 |
+
|
77 |
+
To use different configs, set the `name` argument of the `load_dataset` function.
|
78 |
+
|
79 |
+
### Data Instances
|
80 |
+
|
81 |
+
#### paragraph
|
82 |
+
|
83 |
+
An example looks as follows.
|
84 |
+
```
|
85 |
+
{
|
86 |
+
"doc_id": "GAO_123456",
|
87 |
+
"summary_paragraph_index": 2,
|
88 |
+
"document_sections": {
|
89 |
+
"title": ["test docment section 1 title", "test docment section 1.1 title"],
|
90 |
+
"paragraphs": ["test document\nsection 1 paragraphs", "test document\nsection 1.1 paragraphs"],
|
91 |
+
"depth": [1, 2]
|
92 |
+
},
|
93 |
+
"question_summary_pairs": {
|
94 |
+
"question": ["What is the test question 1?", "What is the test question 1.1?"],
|
95 |
+
"summary": ["This is the test answer 1.", "This is the test answer 1.1"],
|
96 |
+
"parent_pair_index": [-1, 0]
|
97 |
+
}
|
98 |
+
}
|
99 |
+
```
|
100 |
+
|
101 |
+
#### document
|
102 |
+
|
103 |
+
An example looks as follows.
|
104 |
+
```
|
105 |
+
{
|
106 |
+
"doc_id": "GAO_123456",
|
107 |
+
"document_sections": {
|
108 |
+
"title": ["test docment section 1 title", "test docment section 1.1 title"],
|
109 |
+
"paragraphs": ["test document\nsection 1 paragraphs", "test document\nsection 1.1 paragraphs"],
|
110 |
+
"depth": [1, 2],
|
111 |
+
"alignment": ["h0_title", "h0_full"]
|
112 |
+
},
|
113 |
+
"question_summary_pairs": {
|
114 |
+
"question": ["What is the test question 1?", "What is the test question 1.1?"],
|
115 |
+
"summary": ["This is the test answer 1.", "This is the test answer 1.1"],
|
116 |
+
"parent_pair_index": [-1, 0],
|
117 |
+
"summary_paragraph_index": [2, 2]
|
118 |
+
}
|
119 |
+
}
|
120 |
+
```
|
121 |
+
|
122 |
+
### Data Fields
|
123 |
+
|
124 |
+
#### paragraph
|
125 |
+
|
126 |
+
**Note that document_sections in this config are the sections aligned with the annotated summary paragraph.**
|
127 |
+
|
128 |
+
- `doc_id`: a `string` feature.
|
129 |
+
- `summary_paragraph_index`: a `int32` feature.
|
130 |
+
- `document_sections`: a dictionary feature containing lists of (each element corresponds to a section):
|
131 |
+
- `title`: a `string` feature.
|
132 |
+
- `paragraphs`: a of `string` feature, with `\n` separating different paragraphs.
|
133 |
+
- `depth`: a `int32` feature.
|
134 |
+
- `question_summary_pairs`: a dictionary feature containing lists of (each element corresponds to a question-summary pair):
|
135 |
+
- `question`: a `string` feature.
|
136 |
+
- `summary`: a `string` feature.
|
137 |
+
- `parent_pair_index`: a `int32` feature indicating which question-summary pair is the parent of the current pair. `-1` indicates that the current pair does not have parent.
|
138 |
+
|
139 |
+
#### document
|
140 |
+
|
141 |
+
**Note that document_sections in this config are the all sections in the document.**
|
142 |
+
|
143 |
+
- `id`: a `string` feature.
|
144 |
+
- `document_sections`: a dictionary feature containing lists of (each element corresponds to a section):
|
145 |
+
- `title`: a `string` feature.
|
146 |
+
- `paragraphs`: a of `string` feature, with `\n` separating different paragraphs.
|
147 |
+
- `depth`: a `int32` feature.
|
148 |
+
- `alignment`: a `string` feature. Whether the `full` section or the `title` of the section should be included when aligned with each annotated hierarchy. For example, `h0_full` indicates that the full section should be included for the hierarchy indexed `0`.
|
149 |
+
- `question_summary_pairs`: a dictionary feature containing lists of:
|
150 |
+
- `question`: a `string` feature.
|
151 |
+
- `summary`: a `string` feature.
|
152 |
+
- `parent_pair_index`: a `int32` feature indicating which question-summary pair is the parent of the current pair. `-1` indicates that the current pair does not have parent. Note that the indices start from `0` for pairs with the same `summary_paragraph_index`.
|
153 |
+
- `summary_paragraph_index`: a `int32` feature indicating which summary paragraph the question-summary pair is annotated for.
|
154 |
+
|
155 |
+
### Data Splits
|
156 |
+
|
157 |
+
#### paragraph
|
158 |
+
|
159 |
+
- train: 17519
|
160 |
+
- valid: 974
|
161 |
+
- test: 973
|
162 |
+
|
163 |
+
#### document
|
164 |
+
|
165 |
+
- train: 1371
|
166 |
+
- valid: 171
|
167 |
+
- test: 172
|
168 |
+
|
169 |
+
## Dataset Creation
|
170 |
+
|
171 |
+
### Curation Rationale
|
172 |
+
|
173 |
+
[More Information Needed]
|
174 |
+
|
175 |
+
### Source Data
|
176 |
+
|
177 |
+
#### Initial Data Collection and Normalization
|
178 |
+
|
179 |
+
[More Information Needed]
|
180 |
+
|
181 |
+
#### Who are the source language producers?
|
182 |
+
|
183 |
+
Editors of the Congressional Research Service and U.S. Government Accountability Office.
|
184 |
+
|
185 |
+
### Personal and Sensitive Information
|
186 |
+
|
187 |
+
None.
|
188 |
+
|
189 |
+
## Considerations for Using the Data
|
190 |
+
|
191 |
+
### Social Impact of Dataset
|
192 |
+
|
193 |
+
[More Information Needed]
|
194 |
+
|
195 |
+
### Discussion of Biases
|
196 |
+
|
197 |
+
[More Information Needed]
|
198 |
+
|
199 |
+
### Other Known Limitations
|
200 |
+
|
201 |
+
[More Information Needed]
|
202 |
+
|
203 |
+
## Additional Information
|
204 |
+
|
205 |
+
### Dataset Curators
|
206 |
+
|
207 |
+
[More Information Needed]
|
208 |
+
|
209 |
+
### Licensing Information
|
210 |
+
|
211 |
+
CC BY 4.0
|
212 |
+
|
213 |
+
### Citation Information
|
214 |
+
|
215 |
+
```
|
216 |
+
@inproceedings{cao-wang-2022-hibrids,
|
217 |
+
title = "{HIBRIDS}: Attention with Hierarchical Biases for Structure-aware Long Document Summarization",
|
218 |
+
author = "Cao, Shuyang and
|
219 |
+
Wang, Lu",
|
220 |
+
booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
|
221 |
+
month = may,
|
222 |
+
year = "2022",
|
223 |
+
address = "Dublin, Ireland",
|
224 |
+
publisher = "Association for Computational Linguistics",
|
225 |
+
url = "https://aclanthology.org/2022.acl-long.58",
|
226 |
+
pages = "786--807",
|
227 |
+
abstract = "Document structure is critical for efficient information consumption. However, it is challenging to encode it efficiently into the modern Transformer architecture. In this work, we present HIBRIDS, which injects Hierarchical Biases foR Incorporating Document Structure into attention score calculation. We further present a new task, hierarchical question-summary generation, for summarizing salient content in the source document into a hierarchy of questions and summaries, where each follow-up question inquires about the content of its parent question-summary pair. We also annotate a new dataset with 6,153 question-summary hierarchies labeled on government reports. Experiment results show that our model produces better question-summary hierarchies than comparisons on both hierarchy quality and content coverage, a finding also echoed by human judges. Additionally, our model improves the generation of long-form summaries from long government reports and Wikipedia articles, as measured by ROUGE scores.",
|
228 |
+
}
|
229 |
+
```
|
data/test.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6ae97dec4e32d519540ee140d8e3cdc22be0b139e58916e0ae0b171300b8cfcf
|
3 |
+
size 13637334
|
data/train.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eac7ee49967c109be5901433995818352b0d416b6db01a02583d5a6286e92c92
|
3 |
+
size 102144221
|
data/valid.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:caa05c1d7058ada8ab9d7432543609a77c8d8f78fe45f7ee2dcb79879e9b5871
|
3 |
+
size 13362516
|
gov_report_qs.py
ADDED
@@ -0,0 +1,285 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""GovReport: The Government Report Hierarchical Question-summary Generation Dataset."""
|
2 |
+
|
3 |
+
|
4 |
+
import json
|
5 |
+
|
6 |
+
import datasets
|
7 |
+
|
8 |
+
|
9 |
+
logger = datasets.logging.get_logger(__name__)
|
10 |
+
|
11 |
+
|
12 |
+
_CITATION = """\
|
13 |
+
@inproceedings{cao-wang-2022-hibrids,
|
14 |
+
title = "{HIBRIDS}: Attention with Hierarchical Biases for Structure-aware Long Document Summarization",
|
15 |
+
author = "Cao, Shuyang and
|
16 |
+
Wang, Lu",
|
17 |
+
booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
|
18 |
+
month = may,
|
19 |
+
year = "2022",
|
20 |
+
address = "Dublin, Ireland",
|
21 |
+
publisher = "Association for Computational Linguistics",
|
22 |
+
url = "https://aclanthology.org/2022.acl-long.58",
|
23 |
+
pages = "786--807",
|
24 |
+
abstract = "Document structure is critical for efficient information consumption. However, it is challenging to encode it efficiently into the modern Transformer architecture. In this work, we present HIBRIDS, which injects Hierarchical Biases foR Incorporating Document Structure into attention score calculation. We further present a new task, hierarchical question-summary generation, for summarizing salient content in the source document into a hierarchy of questions and summaries, where each follow-up question inquires about the content of its parent question-summary pair. We also annotate a new dataset with 6,153 question-summary hierarchies labeled on government reports. Experiment results show that our model produces better question-summary hierarchies than comparisons on both hierarchy quality and content coverage, a finding also echoed by human judges. Additionally, our model improves the generation of long-form summaries from long government reports and Wikipedia articles, as measured by ROUGE scores.",
|
25 |
+
}
|
26 |
+
"""
|
27 |
+
|
28 |
+
_DESCRIPTION = """\
|
29 |
+
GovReport-QS hierarchical question-summary generation dataset.
|
30 |
+
|
31 |
+
There are two configs:
|
32 |
+
- paragraph: paragraph-level annotated data
|
33 |
+
- document: aggregated paragraph-level annotated data for the same document
|
34 |
+
"""
|
35 |
+
|
36 |
+
_URL = "https://huggingface.co/datasets/shuyangcao/gov_report_qs/resolve/main/data/"
|
37 |
+
_URLS = {
|
38 |
+
"train": _URL + "train.jsonl",
|
39 |
+
"valid": _URL + "valid.jsonl",
|
40 |
+
"test": _URL + "test.jsonl",
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
def _recursive_load(section, keep_letter=False, depth=0, section_title_list=None, aligned_section_titles=None):
|
45 |
+
aligned_hierarchies = set()
|
46 |
+
alignment = set()
|
47 |
+
sections = []
|
48 |
+
if section["section_title"] != "Letter" or (section["section_title"] == "Letter" and keep_letter):
|
49 |
+
section_title = " ".join(section["section_title"].strip().split())
|
50 |
+
section_paragraphs = "\n".join([" ".join(paragraph.strip().split()) for paragraph in section["paragraphs"]])
|
51 |
+
if section_title:
|
52 |
+
section_title_list = section_title_list + (section_title,)
|
53 |
+
|
54 |
+
child_sections = []
|
55 |
+
for subsection in section["subsections"]:
|
56 |
+
child_section, child_aligned_hierarchies = _recursive_load(subsection, keep_letter, depth + 1, section_title_list, aligned_section_titles)
|
57 |
+
child_sections.extend(child_section)
|
58 |
+
aligned_hierarchies.update(child_aligned_hierarchies)
|
59 |
+
|
60 |
+
for hierarchy_id, aligned_section_title in enumerate(aligned_section_titles):
|
61 |
+
if section_title_list in aligned_section_title:
|
62 |
+
aligned_hierarchies.add(hierarchy_id)
|
63 |
+
alignment.add(f'h{hierarchy_id}_full')
|
64 |
+
|
65 |
+
for hierarchy_id in aligned_hierarchies:
|
66 |
+
if f'h{hierarchy_id}_full' not in alignment:
|
67 |
+
alignment.add(f'h{hierarchy_id}_title')
|
68 |
+
|
69 |
+
sections.append({
|
70 |
+
"title": section_title,
|
71 |
+
"paragraphs": section_paragraphs,
|
72 |
+
"depth": depth,
|
73 |
+
"alignment": " ".join(alignment),
|
74 |
+
})
|
75 |
+
sections.extend(child_sections)
|
76 |
+
|
77 |
+
else:
|
78 |
+
for subsection in section["subsections"]:
|
79 |
+
child_sections, child_aligned_hierarchies = _recursive_load(subsection, keep_letter, depth, section_title_list, aligned_section_titles)
|
80 |
+
sections.extend(child_sections)
|
81 |
+
aligned_hierarchies.update(child_aligned_hierarchies)
|
82 |
+
|
83 |
+
return sections, aligned_hierarchies
|
84 |
+
|
85 |
+
|
86 |
+
def _recursive_load_qs_pairs(qs_pair, current_id=0, parent_id=-1):
|
87 |
+
qs_pairs = []
|
88 |
+
qs_pairs.append({
|
89 |
+
"question": qs_pair["question"],
|
90 |
+
"summary": qs_pair["answer"],
|
91 |
+
"parent_pair_index": parent_id,
|
92 |
+
})
|
93 |
+
child_id = current_id + 1
|
94 |
+
for child_qs_pair in qs_pair["child_questions"]:
|
95 |
+
child_qs_pairs, current_child_id = _recursive_load_qs_pairs(child_qs_pair, child_id, current_id)
|
96 |
+
qs_pairs.extend(child_qs_pairs)
|
97 |
+
child_id = current_child_id
|
98 |
+
return qs_pairs, child_id
|
99 |
+
|
100 |
+
|
101 |
+
class GovReportQSConfig(datasets.BuilderConfig):
|
102 |
+
"""BuilderConfig for GovReport."""
|
103 |
+
|
104 |
+
def __init__(self, **kwargs):
|
105 |
+
"""BuilderConfig for GovReport.
|
106 |
+
Args:
|
107 |
+
**kwargs: keyword arguments forwarded to super.
|
108 |
+
"""
|
109 |
+
super(GovReportQSConfig, self).__init__(**kwargs)
|
110 |
+
|
111 |
+
|
112 |
+
class GovReportQS(datasets.GeneratorBasedBuilder):
|
113 |
+
VERSION = datasets.Version("1.0.0")
|
114 |
+
|
115 |
+
DEFAULT_CONFIG_NAME = "paragraph"
|
116 |
+
|
117 |
+
BUILDER_CONFIGS = [
|
118 |
+
GovReportQSConfig(
|
119 |
+
name="paragraph",
|
120 |
+
version=VERSION,
|
121 |
+
description="paragraph-level annotated data",
|
122 |
+
),
|
123 |
+
GovReportQSConfig(
|
124 |
+
name="document",
|
125 |
+
version=VERSION,
|
126 |
+
description="aggregated paragraph-level annotated data for the same document",
|
127 |
+
),
|
128 |
+
]
|
129 |
+
|
130 |
+
def _info(self):
|
131 |
+
if self.config.name == "paragraph":
|
132 |
+
features = datasets.Features(
|
133 |
+
{
|
134 |
+
"doc_id": datasets.Value("string"),
|
135 |
+
"summary_paragraph_index": datasets.Value("int32"),
|
136 |
+
"document_sections": datasets.features.Sequence(
|
137 |
+
{
|
138 |
+
"title": datasets.Value("string"),
|
139 |
+
"paragraphs": datasets.Value("string"),
|
140 |
+
"depth": datasets.Value("int32"),
|
141 |
+
}
|
142 |
+
),
|
143 |
+
"question_summary_pairs": datasets.features.Sequence(
|
144 |
+
{
|
145 |
+
"question": datasets.Value("string"),
|
146 |
+
"summary": datasets.Value("string"),
|
147 |
+
"parent_pair_index": datasets.Value("int32"),
|
148 |
+
}
|
149 |
+
),
|
150 |
+
}
|
151 |
+
)
|
152 |
+
elif self.config.name == "document":
|
153 |
+
features = datasets.Features(
|
154 |
+
{
|
155 |
+
"doc_id": datasets.Value("string"),
|
156 |
+
"document_sections": datasets.features.Sequence(
|
157 |
+
{
|
158 |
+
"title": datasets.Value("string"),
|
159 |
+
"paragraphs": datasets.Value("string"),
|
160 |
+
"depth": datasets.Value("int32"),
|
161 |
+
"alignment": datasets.Value("string")
|
162 |
+
}
|
163 |
+
),
|
164 |
+
"question_summary_pairs": datasets.features.Sequence(
|
165 |
+
{
|
166 |
+
"question": datasets.Value("string"),
|
167 |
+
"summary": datasets.Value("string"),
|
168 |
+
"parent_pair_index": datasets.Value("int32"),
|
169 |
+
"summary_paragraph_index": datasets.Value("int32"),
|
170 |
+
}
|
171 |
+
),
|
172 |
+
}
|
173 |
+
)
|
174 |
+
else:
|
175 |
+
raise ValueError("Unsupported config name {}".format(self.config.name))
|
176 |
+
|
177 |
+
return datasets.DatasetInfo(
|
178 |
+
description=_DESCRIPTION,
|
179 |
+
features=features,
|
180 |
+
supervised_keys=None,
|
181 |
+
homepage="",
|
182 |
+
citation=_CITATION,
|
183 |
+
)
|
184 |
+
|
185 |
+
def _split_generators(self, dl_manager):
|
186 |
+
downloaded_files = dl_manager.download_and_extract(_URLS)
|
187 |
+
|
188 |
+
return [
|
189 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
190 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
|
191 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
192 |
+
]
|
193 |
+
|
194 |
+
def _generate_examples(self, filepath):
|
195 |
+
"""This function returns the examples in the raw (text) form."""
|
196 |
+
logger.info(f"generating examples from = {filepath}")
|
197 |
+
|
198 |
+
with open(filepath) as f:
|
199 |
+
key = 0
|
200 |
+
for line in f:
|
201 |
+
line = line.strip()
|
202 |
+
if not line:
|
203 |
+
continue
|
204 |
+
data = json.loads(line)
|
205 |
+
|
206 |
+
doc_id = data["id"]
|
207 |
+
|
208 |
+
annotated_hierarchies = data["annotated_hierarchies"]
|
209 |
+
aligned_section_titles = [set([tuple([" ".join(title.strip().split()) for title in section]) for section in hierarchy["aligned_sections"]]) for hierarchy in annotated_hierarchies]
|
210 |
+
|
211 |
+
if doc_id.startswith("GAO"):
|
212 |
+
document_sections = []
|
213 |
+
for lv1_section in data["report"]:
|
214 |
+
document_sections.extend(_recursive_load(lv1_section, keep_letter=False, depth=1, section_title_list=tuple(), aligned_section_titles=aligned_section_titles)[0])
|
215 |
+
elif doc_id.startswith("CRS"):
|
216 |
+
document_sections = _recursive_load(data["reports"], keep_letter=True, depth=0, section_title_list=tuple(), aligned_section_titles=aligned_section_titles)[0]
|
217 |
+
else:
|
218 |
+
raise ValueError("Invalid document id {}".format(doc_id))
|
219 |
+
|
220 |
+
annotated_qs_pairs = []
|
221 |
+
for hierarchy_id, annotated_hierarchy in enumerate(annotated_hierarchies):
|
222 |
+
summary_paragraph_index = annotated_hierarchy["paragraph_index"]
|
223 |
+
|
224 |
+
qs_pairs = []
|
225 |
+
current_id = 0
|
226 |
+
for lv1_qs_pair in annotated_hierarchy["questions"]:
|
227 |
+
child_qs_pairs, current_id = _recursive_load_qs_pairs(lv1_qs_pair, current_id=current_id, parent_id=-1)
|
228 |
+
qs_pairs.extend(child_qs_pairs)
|
229 |
+
|
230 |
+
annotated_qs_pairs.append({
|
231 |
+
"hierarchy_id": hierarchy_id,
|
232 |
+
"summary_paragraph_index": summary_paragraph_index,
|
233 |
+
"question_summary_pairs": qs_pairs,
|
234 |
+
})
|
235 |
+
|
236 |
+
if self.config.name == "paragraph":
|
237 |
+
for annotated_qs_pair in annotated_qs_pairs:
|
238 |
+
_id = f"{doc_id}_{annotated_qs_pair['summary_paragraph_index']}_{key}"
|
239 |
+
|
240 |
+
aligned_sections = []
|
241 |
+
for section in document_sections:
|
242 |
+
if f"h{annotated_qs_pair['hierarchy_id']}_full" in section["alignment"]: # both title and paragraphs
|
243 |
+
aligned_sections.append({
|
244 |
+
"title": section["title"],
|
245 |
+
"paragraphs": section["paragraphs"],
|
246 |
+
"depth": section["depth"],
|
247 |
+
})
|
248 |
+
elif f"f{annotated_qs_pair['hierarchy_id']}_title" in section["alignment"]: # only title
|
249 |
+
aligned_sections.append({
|
250 |
+
"title": section["title"],
|
251 |
+
"paragraphs": "",
|
252 |
+
"depth": section["depth"],
|
253 |
+
})
|
254 |
+
|
255 |
+
if aligned_sections:
|
256 |
+
yield _id, {
|
257 |
+
"doc_id": doc_id,
|
258 |
+
"summary_paragraph_index": annotated_qs_pair["summary_paragraph_index"],
|
259 |
+
"document_sections": aligned_sections,
|
260 |
+
"question_summary_pairs": annotated_qs_pair["question_summary_pairs"],
|
261 |
+
}
|
262 |
+
else:
|
263 |
+
print(f"{doc_id}_{key} has no aligned sections")
|
264 |
+
key += 1
|
265 |
+
elif self.config.name == "document":
|
266 |
+
_id = f"{doc_id}"
|
267 |
+
|
268 |
+
question_summary_pairs = []
|
269 |
+
for annotated_qs_pair in annotated_qs_pairs:
|
270 |
+
summary_paragraph_index = annotated_qs_pair["summary_paragraph_index"]
|
271 |
+
for qs_pair in annotated_qs_pair["question_summary_pairs"]:
|
272 |
+
question_summary_pairs.append({
|
273 |
+
"question": qs_pair["question"],
|
274 |
+
"summary": qs_pair["summary"],
|
275 |
+
"parent_pair_index": qs_pair["parent_pair_index"],
|
276 |
+
"summary_paragraph_index": summary_paragraph_index,
|
277 |
+
})
|
278 |
+
|
279 |
+
yield _id, {
|
280 |
+
"doc_id": doc_id,
|
281 |
+
"document_sections": document_sections,
|
282 |
+
"question_summary_pairs": question_summary_pairs,
|
283 |
+
}
|
284 |
+
else:
|
285 |
+
raise ValueError("Unsupported config name {}".format(self.config.name))
|