File size: 12,692 Bytes
d35cbd8 f66af21 d35cbd8 c4cc7cc d35cbd8 f66af21 d35cbd8 f66af21 d35cbd8 f66af21 d35cbd8 5f52b01 d35cbd8 47c0146 d35cbd8 47c0146 d35cbd8 47c0146 d35cbd8 47c0146 d35cbd8 1947019 d35cbd8 39ba7aa d35cbd8 4832d46 d35cbd8 4832d46 d35cbd8 4832d46 d35cbd8 f66af21 9707291 d35cbd8 4832d46 d35cbd8 4832d46 d35cbd8 4832d46 d35cbd8 4832d46 d35cbd8 4832d46 d35cbd8 4d2c440 |
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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
"""Multi Legal Pile"""
import json
import datasets
from huggingface_hub.file_download import hf_hub_url
try:
import lzma as xz
except ImportError:
import pylzma as xz
datasets.logging.set_verbosity_info()
logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = """
"""
_CITATION = """
"""
_URL = "https://huggingface.co/datasets/joelito/Multi_Legal_Pile"
# Specific Data
_DATA_NAME = {
"bg": {
"legislation": ["bulgaria_marcell"],
},
"cs": {
"caselaw": ["czechia_constitutional_court", "czechia_supreme_administrative_court", "czechia_supreme_court"],
},
"da": {
"caselaw": ["denmark_ddsc"],
"legislation": ["denmark_ddsc"],
},
"de": {
"caselaw": ["germany_openlegaldata", "switzerland_entscheidsuche"],
"legislation": ["germany_openlegaldata", "switzerland_lexfind"],
},
"en": {
"legislation": ["switzerland_lexfind", "uk_uk_lex"],
},
"fr": {
"caselaw": ["belgium_jurportal", "france_cass", "luxembourg_judoc", "switzerland_entscheidsuche"],
"legislation": ["belgium_ejustice", "switzerland_lexfind"],
},
"hu": {
"legislation": ["hungary_marcell"],
},
"it": {
"caselaw": ["switzerland_entscheidsuche"],
"legislation": ["switzerland_lexfind"],
},
"nl": {
"legislation": ["belgium_ejustice"],
},
"pl": {
"legislation": ["poland_marcell"],
},
"pt": {
"caselaw": ["brazil_rulingbr"],
},
"ro": {
"legislation": ["romania_marcell"],
},
"sk": {
"legislation": ["slovakia_marcell"],
},
"sl": {
"legislation": ["slovenia_marcell"],
},
}
_PILE_OF_LAW_NAMES = {
"caselaw": {
"courtlistener_opinions": {
"train": [
"train.courtlisteneropinions.0",
"train.courtlisteneropinions.1",
"train.courtlisteneropinions.2",
"train.courtlisteneropinions.3",
"train.courtlisteneropinions.4",
"train.courtlisteneropinions.5",
"train.courtlisteneropinions.6",
"train.courtlisteneropinions.7",
"train.courtlisteneropinions.8",
"train.courtlisteneropinions.9",
],
"validation": [
"validation.courtlisteneropinions.0",
"validation.courtlisteneropinions.1",
"validation.courtlisteneropinions.2",
"validation.courtlisteneropinions.3"
]
},
"courtlistener_docket_entry_documents": {
"train": [
"train.courtlistenerdocketentries.0",
"train.courtlistenerdocketentries.1",
"train.courtlistenerdocketentries.2",
"train.courtlistenerdocketentries.3"
],
"validation": [
"validation.courtlistenerdocketentries.0",
"validation.courtlistenerdocketentries.1"
]
},
"scotus_filings": {
"train": ["train.scotus_docket_entries"],
"validation": ["validation.scotus_docket_entries"]
},
"echr": {
"train": ["train.echr"],
"validation": ["validation.echr"]
},
"canadian_decisions": {
"train": ["train.canadian_decisions"],
"validation": ["validation.canadian_decisions"]
},
},
"contracts": {
"atticus_contracts": {
"train": [
"train.atticus_contracts.0",
"train.atticus_contracts.1",
"train.atticus_contracts.2",
"train.atticus_contracts.3",
"train.atticus_contracts.4"
],
"validation": [
"validation.atticus_contracts.0",
"validation.atticus_contracts.1"
]
},
"edgar": {
"train": ["train.edgar"],
"validation": ["validation.edgar"]
},
"cfpb_creditcard_contracts": {
"train": ["train.cfpb_cc"],
"validation": ["validation.cfpb_cc"]
},
},
"legislation": {
"uscode": {
"train": ["train.uscode"],
"validation": ["validation.uscode"]
},
"state_codes": {
"train": ["train.state_code"],
"validation": ["validation.state_code"]
},
"us_bills": {
"train": ["train.us_bills"],
"validation": ["validation.us_bills"]
},
"federal_register": {
"train": ["train.federal_register"],
"validation": ["validation.federal_register"]
},
"cfr": {
"train": ["train.cfr"],
"validation": ["validation.cfr"]
},
"constitutions": {
"train": ["train.constitutions"],
"validation": ["validation.constitutions"]
},
},
"other": { # analyses
"oig": {
"train": ["train.oig"],
"validation": ["validation.oig"]
},
"olc_memos": {
"train": ["train.olcmemos"],
"validation": ["validation.olcmemos"]
},
},
}
_LANGUAGES = ["bg", "cs", "da", "de", "el", "en", "es", "et", "fi", "fr", "ga", "hr",
"hu", "it", "lt", "lv", "mt", "nl", "pl", "pt", "ro", "sk", "sl", "sv"]
_TYPES = ["caselaw", "contracts", "legislation", "other"]
_JURISDICTONS = ["Austria", "Belgium", "Bulgaria", "Croatia", "Czechia", "Denmark", "Estonia", "Finland",
"France", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg",
"Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Sweden",
"EU", "Switzerland", "UK", "US", "Canada", "N/A"]
class MultiLegalPileConfig(datasets.BuilderConfig):
"""BuilderConfig for MultiLegalPile."""
def __init__(self, name: str, repo_data_only=False, **kwargs):
"""BuilderConfig for MultiLegalPile.
Args:
name: combination of language and type with _
language: One of bg,cs,da,de,el,en,es,et,fi,fr,ga,hr,hu,it,lt,lv,mt,nl,pl,pt,ro,sk,sl,sv or all
type: One of caselaw,contracts,legislation,other or all
**kwargs: keyword arguments forwarded to super.
"""
super(MultiLegalPileConfig, self).__init__(**kwargs)
self.name = name
self.language = name.split("_")[0]
self.type = name.split("_")[1]
self.repo_data_only = repo_data_only
class MultiLegalPile(datasets.GeneratorBasedBuilder):
"""MultiLegalPile: A Corpus Covering Large-Scale Multilingual Legal Data"""
BUILDER_CONFIG_CLASS = MultiLegalPileConfig
BUILDER_CONFIGS = [MultiLegalPileConfig(f"{language}_{type}")
for type in _TYPES + ["all"]
for language in _LANGUAGES + ["all"]]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"language": datasets.Value("string"), # one of _LANGUAGES
"type": datasets.Value("string"), # one of _TYPES
"jurisdiction": datasets.Value("string"), # one of _JURISDICTONS
"text": datasets.Value("string"),
}
),
supervised_keys=None,
homepage=_URL,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
def download_url(dataset, file_name):
url = hf_hub_url(repo_id=dataset, filename=f"data/{file_name}.jsonl.xz", repo_type="dataset")
return dl_manager.download(url)
data_infos = []
languages = _LANGUAGES if self.config.language == "all" else [self.config.language]
types = _TYPES if self.config.type == "all" else [self.config.type]
for language in languages:
for type in types:
info = {"language": language, "type": type}
# add native MultiLegalPile data
if language in _DATA_NAME and type in _DATA_NAME[language]: # if we actually have something there
for data_name in _DATA_NAME[language][type]:
info["jurisdiction"] = data_name.split("_")[0].capitalize()
info["filepath"] = download_url("joelito/Multi_Legal_Pile", f"{language}/{type}/{data_name}")
data_infos.append(info.copy())
if not self.config.repo_data_only:
# add eurlex_resources data
info["jurisdiction"] = "EU"
if type == 'caselaw':
info["filepath"] = download_url("joelito/eurlex_resources", f"{language}/caselaw")
data_infos.append(info.copy())
elif type == 'legislation':
for resource_type in ["decision", "directive", "regulation", "recommendation", "proposal"]:
info["filepath"] = download_url("joelito/eurlex_resources", f"{language}/{resource_type}")
data_infos.append(info.copy())
elif type == 'contracts':
# international agreements
info["filepath"] = download_url("joelito/eurlex_resources", f"{language}/intagr")
data_infos.append(info.copy())
# add mc4_legal data
if type == 'other':
info["jurisdiction"] = "N/A"
if language in ["de", "en", "es"]: # here we need to chunk because the files are too large
for idx in [0, 1]:
info["filepath"] = download_url("joelito/mc4_legal", f"{language}_{idx}")
data_infos.append(info.copy())
elif language in ["hr"]:
pass # nothing there for Croatian
else:
info["filepath"] = download_url("joelito/mc4_legal", f"{language}")
data_infos.append(info.copy())
# add pile-of-law data
if language == 'en':
info["jurisdiction"] = "US"
for name, train_val_files in _PILE_OF_LAW_NAMES[type].items():
if name == 'canadian_decisions':
info["jurisdiction"] = "Canada"
elif name in ['echr']:
info["jurisdiction"] = "EU"
elif name in ['constitutions']:
info["jurisdiction"] = "N/A"
for split in ["train", "validation"]:
for file_name in train_val_files[split]:
info["filepath"] = download_url("pile-of-law/pile-of-law", file_name)
data_infos.append(info.copy())
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"data_infos": data_infos})]
def _generate_examples(self, data_infos):
"""This function returns the examples in the raw (text) form by iterating on all the files."""
id_ = 0
for data_info in data_infos:
logger.info("Generating examples from = %s", data_info["filepath"])
try:
with xz.open(open(data_info["filepath"], "rb"), "rt", encoding="utf-8") as f:
for line in f:
if line:
example = json.loads(line)
if example is not None and isinstance(example, dict):
yield id_, {
# uses the default values for language, type and jurisdiction if it is not set
"language": example.get("language", data_info["language"]),
"type": example.get("type", data_info["type"]),
"jurisdiction": example.get("jurisdiction", data_info["jurisdiction"]),
"text": example.get("text", ""),
}
id_ += 1
except Exception:
logger.exception("Error while processing file %s", data_info["filepath"])
|