File size: 10,765 Bytes
efb73aa 8e0586b efb73aa 8e0586b efb73aa 8e0586b efb73aa 8e0586b efb73aa 8e0586b efb73aa 8e0586b |
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
import json
import os
from typing import Any, Dict, List, Tuple, Union
import datasets
logger = datasets.logging.get_logger(__name__)
def _load_jsonl(filename):
with open(filename, "r") as fp:
jsonl_content = fp.read()
result = [json.loads(jline) for jline in jsonl_content.splitlines()]
return result
def _load_json(filepath):
with open(filepath, "r") as fp:
res = json.load(fp)
return res
_CITATION = """
@article{Shen2022MultiLexSum,
author = {Zejiang Shen and
Kyle Lo and
Lauren Yu and
Nathan Dahlberg and
Margo Schlanger and
Doug Downey},
title = {Multi-LexSum: Real-World Summaries of Civil Rights Lawsuits at Multiple Granularities},
journal = {CoRR},
volume = {abs/2206.10883},
year = {2022},
url = {https://doi.org/10.48550/arXiv.2206.10883},
doi = {10.48550/arXiv.2206.10883}
}
""" # TODO
_DESCRIPTION = """
Multi-LexSum is a multi-doc summarization dataset for civil rights litigation lawsuits with summaries of three granularities.
""" # TODO: Update with full abstract
_HOMEPAGE = "https://multilexsum.github.io"
# _BASE_URL = "https://ai2-s2-research.s3.us-west-2.amazonaws.com/multilexsum/releases"
_BASE_URL = "https://huggingface.co/datasets/allenai/multi_lexsum/resolve/main/releases"
_FILES = {
"train": "train.json",
"dev": "dev.json",
"test": "test.json",
"sources": "sources.json",
}
class MultiLexsumConfig(datasets.BuilderConfig):
"""BuilderConfig for LexSum."""
def __init__(self, **kwargs):
"""BuilderConfig for LexSum.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(MultiLexsumConfig, self).__init__(**kwargs)
class MultiLexsum(datasets.GeneratorBasedBuilder):
"""MultiLexSum Dataset: a multi-doc summarization dataset for
civil rights litigation lawsuits with summaries of three granularities.
"""
BUILDER_CONFIGS = [
MultiLexsumConfig(
name="v20220616",
version=datasets.Version("1.0.0", "Public v1.0 release."),
description="The v1.0 Multi-LexSum dataset",
),
MultiLexsumConfig(
name="v20230518",
version=datasets.Version("1.1.0", "Public v1.1 release."),
description="It adds additional metadata for documents and cases",
),
]
def _info(self):
if self.config.name == "v20220616":
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"sources": datasets.Sequence(datasets.Value("string")),
"summary/long": datasets.Value("string"),
"summary/short": datasets.Value("string"),
"summary/tiny": datasets.Value("string"),
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
)
elif self.config.name == "v20230518":
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"sources": datasets.Sequence(datasets.Value("string")),
"sources_metadata": datasets.Sequence(
{
"doc_id": datasets.Value("string"),
"doc_type": datasets.Value("string"),
"doc_title": datasets.Value("string"),
"parser": datasets.Value("string"),
"is_ocr": datasets.Value("bool"),
"url": datasets.Value("string"),
}
),
"summary/long": datasets.Value("string"),
"summary/short": datasets.Value("string"),
"summary/tiny": datasets.Value("string"),
"case_metadata": datasets.Features(
{
# fmt: off
"case_name": datasets.Value("string"),
"case_type": datasets.Value("string"),
"filing_date": datasets.Value("string"),
"filing_year": datasets.Value("string"),
"case_ongoing": datasets.Value("string"),
"case_ongoing_record_time": datasets.Value("string"),
"closing_year": datasets.Value("string"),
"order_start_year": datasets.Value("string"),
"order_end_year": datasets.Value("string"),
"defendant_payment": datasets.Value("string"),
"class_action_sought": datasets.Value("string"),
"class_action_granted": datasets.Value("string"),
"attorney_orgs": [datasets.Value("string")],
"prevailing_party": datasets.Value("string"),
"plaintiff_types": [datasets.Value("string")],
"plaintiff_description": datasets.Value("string"),
"constitutional_clauses": [datasets.Value("string")],
"causes_of_action": [datasets.Value("string")],
"summary_authors": [datasets.Value("string")],
"case_url": datasets.Value("string"),
# fmt: on
}
),
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
base_url = _BASE_URL if self.config.data_dir is None else self.config.data_dir
downloaded_files = dl_manager.download_and_extract(
{
name: f"{base_url}/{self.config.name}/{filename}"
for name, filename in _FILES.items()
}
)
# Given sources is a large file, we read it first
sources = _load_json(downloaded_files["sources"])
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"subset_file": downloaded_files["train"],
"sources": sources,
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"subset_file": downloaded_files["dev"],
"sources": sources,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"subset_file": downloaded_files["test"],
"sources": sources,
},
),
]
def _generate_examples(self, subset_file: str, sources: Dict[str, Dict]):
"""This function returns the examples in the raw (text) form."""
logger.info(f"generating examples from = {subset_file}")
if self.config.name == "v20220616":
subset_cases = _load_jsonl(subset_file)
for case_data in subset_cases:
case_sources = [
sources[source_id]["doc_text"]
for source_id in case_data["case_documents"]
]
yield case_data["case_id"], {
"id": case_data["case_id"],
"sources": case_sources,
"summary/long": case_data["summary/long"],
"summary/short": case_data["summary/short"],
"summary/tiny": case_data["summary/tiny"],
}
elif self.config.name == "v20230518":
subset_cases = _load_jsonl(subset_file)
for idx, case_data in enumerate(subset_cases):
case_sources = [
sources[source_id]["doc_text"]
for source_id in case_data["case_documents"]
]
case_source_metadata = [
{
key: val
for key, val in sources[source_id].items()
if key != "doc_text"
}
for source_id in case_data["case_documents"]
]
case_metadata = {
"case_name": case_data["case_name"],
"case_type": case_data["case_type"],
"filing_date": case_data["filing_date"],
"filing_year": case_data["filing_year"],
"case_ongoing": case_data["case_ongoing"],
"case_ongoing_record_time": case_data["case_ongoing_record_time"],
"closing_year": case_data["closing_year"],
"order_start_year": case_data["order_start_year"],
"order_end_year": case_data["order_end_year"],
"defendant_payment": case_data["defendant_payment"],
"class_action_sought": case_data["class_action_sought"],
"class_action_granted": case_data["class_action_granted"],
"attorney_orgs": case_data["attorney_org"],
"prevailing_party": case_data["prevailing_party"],
"plaintiff_types": case_data["plaintiff_types"],
"plaintiff_description": case_data["plaintiff_description"],
"constitutional_clauses": case_data["constitutional_clauses"],
"causes_of_action": case_data["causes_of_action"],
"summary_authors": case_data["summary_authors"],
"case_url": case_data["case_url"],
}
yield case_data["case_id"], {
"id": case_data["case_id"],
"sources": case_sources,
"sources_metadata": case_source_metadata,
"summary/long": case_data["summary/long"],
"summary/short": case_data["summary/short"],
"summary/tiny": case_data["summary/tiny"],
"case_metadata": case_metadata,
}
|