joelniklaus
commited on
Commit
·
979bb7a
1
Parent(s):
3810cf6
Create Multi_Legal_Pile_Commercial
Browse files- Multi_Legal_Pile_Commercial +434 -0
Multi_Legal_Pile_Commercial
ADDED
@@ -0,0 +1,434 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Multi Legal Pile"""
|
2 |
+
|
3 |
+
import json
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
from huggingface_hub.file_download import hf_hub_url
|
7 |
+
|
8 |
+
try:
|
9 |
+
import lzma as xz
|
10 |
+
except ImportError:
|
11 |
+
import pylzma as xz
|
12 |
+
|
13 |
+
datasets.logging.set_verbosity_info()
|
14 |
+
logger = datasets.logging.get_logger(__name__)
|
15 |
+
|
16 |
+
_DESCRIPTION = """
|
17 |
+
Multi Legal Pile is a dataset of legal documents in the 24 EU languages.
|
18 |
+
"""
|
19 |
+
|
20 |
+
_CITATION = """
|
21 |
+
"""
|
22 |
+
|
23 |
+
_URL = "https://huggingface.co/datasets/joelito/Multi_Legal_Pile_Commercial"
|
24 |
+
|
25 |
+
VERSION = datasets.Version("1.0.0", "")
|
26 |
+
|
27 |
+
# IMPORTANT: Types should not have underscores in this dataset
|
28 |
+
CASELAW = "caselaw"
|
29 |
+
LEGISLATION = "legislation"
|
30 |
+
CONTRACTS = "contracts"
|
31 |
+
OTHER = "other"
|
32 |
+
LEGAL_MC4 = "legal-mc4"
|
33 |
+
|
34 |
+
# Native MultiLegalPile
|
35 |
+
_DATA_NAME = {
|
36 |
+
"bg": {
|
37 |
+
LEGISLATION: ["bulgaria_marcell"],
|
38 |
+
},
|
39 |
+
"da": {
|
40 |
+
CASELAW: ["denmark_ddsc"],
|
41 |
+
LEGISLATION: ["denmark_ddsc"],
|
42 |
+
},
|
43 |
+
"de": {
|
44 |
+
CASELAW: ["germany_openlegaldata", "switzerland_entscheidsuche"],
|
45 |
+
LEGISLATION: ["germany_openlegaldata", "switzerland_lexfind"],
|
46 |
+
},
|
47 |
+
"en": {
|
48 |
+
LEGISLATION: ["switzerland_lexfind", "uk_uk_lex"],
|
49 |
+
},
|
50 |
+
"fr": {
|
51 |
+
CASELAW: ["belgium_jurportal", "france_cass", "luxembourg_judoc", "switzerland_entscheidsuche"],
|
52 |
+
LEGISLATION: ["belgium_ejustice", "switzerland_lexfind"],
|
53 |
+
},
|
54 |
+
"hu": {
|
55 |
+
LEGISLATION: ["hungary_marcell"],
|
56 |
+
},
|
57 |
+
"it": {
|
58 |
+
CASELAW: ["switzerland_entscheidsuche"],
|
59 |
+
LEGISLATION: ["switzerland_lexfind"],
|
60 |
+
},
|
61 |
+
"nl": {
|
62 |
+
LEGISLATION: ["belgium_ejustice"],
|
63 |
+
},
|
64 |
+
"pl": {
|
65 |
+
LEGISLATION: ["poland_marcell"],
|
66 |
+
},
|
67 |
+
"pt": {
|
68 |
+
CASELAW: ["brazil_rulingbr", "brazil_cjpg_0", "brazil_cjpg_1", "brazil_cjpg_2", "brazil_cjpg_3", "brazil_cjpg_4"],
|
69 |
+
},
|
70 |
+
"ro": {
|
71 |
+
LEGISLATION: ["romania_marcell"],
|
72 |
+
},
|
73 |
+
"sk": {
|
74 |
+
LEGISLATION: ["slovakia_marcell"],
|
75 |
+
},
|
76 |
+
"sl": {
|
77 |
+
LEGISLATION: ["slovenia_marcell"],
|
78 |
+
},
|
79 |
+
}
|
80 |
+
|
81 |
+
|
82 |
+
# PileOfLaw
|
83 |
+
_PILE_OF_LAW_NAMES = {
|
84 |
+
CASELAW: {
|
85 |
+
"courtlistener_docket_entry_documents": {
|
86 |
+
"train": [
|
87 |
+
"train.courtlistenerdocketentries.0",
|
88 |
+
"train.courtlistenerdocketentries.1",
|
89 |
+
"train.courtlistenerdocketentries.2",
|
90 |
+
"train.courtlistenerdocketentries.3"
|
91 |
+
],
|
92 |
+
"validation": [
|
93 |
+
"validation.courtlistenerdocketentries.0",
|
94 |
+
"validation.courtlistenerdocketentries.1"
|
95 |
+
]
|
96 |
+
},
|
97 |
+
"courtlistener_opinions": {
|
98 |
+
"train": [
|
99 |
+
"train.courtlisteneropinions.0",
|
100 |
+
"train.courtlisteneropinions.1",
|
101 |
+
"train.courtlisteneropinions.2",
|
102 |
+
"train.courtlisteneropinions.3",
|
103 |
+
"train.courtlisteneropinions.4",
|
104 |
+
"train.courtlisteneropinions.5",
|
105 |
+
"train.courtlisteneropinions.6",
|
106 |
+
"train.courtlisteneropinions.7",
|
107 |
+
"train.courtlisteneropinions.8",
|
108 |
+
"train.courtlisteneropinions.9",
|
109 |
+
"train.courtlisteneropinions.10",
|
110 |
+
"train.courtlisteneropinions.11",
|
111 |
+
"train.courtlisteneropinions.12",
|
112 |
+
"train.courtlisteneropinions.13",
|
113 |
+
"train.courtlisteneropinions.14",
|
114 |
+
"train.courtlisteneropinions.15"
|
115 |
+
|
116 |
+
],
|
117 |
+
"validation": [
|
118 |
+
"validation.courtlisteneropinions.0",
|
119 |
+
"validation.courtlisteneropinions.1",
|
120 |
+
"validation.courtlisteneropinions.2",
|
121 |
+
"validation.courtlisteneropinions.3",
|
122 |
+
"validation.courtlisteneropinions.4",
|
123 |
+
"validation.courtlisteneropinions.5"
|
124 |
+
]
|
125 |
+
},
|
126 |
+
"bva_opinions": {
|
127 |
+
"train": ["train.bva"],
|
128 |
+
"validation": ["validation.bva"]
|
129 |
+
},
|
130 |
+
"nlrb_decisions": {
|
131 |
+
"train": ["train.nlrb_decisions"],
|
132 |
+
"validation": ["validation.nlrb_decisions"]
|
133 |
+
},
|
134 |
+
"scotus_oral_arguments": {
|
135 |
+
"train": ["train.scotus_oral"],
|
136 |
+
"validation": ["validation.scotus_oral"]
|
137 |
+
},
|
138 |
+
"scotus_filings": {
|
139 |
+
"train": ["train.scotus_docket_entries"],
|
140 |
+
"validation": ["validation.scotus_docket_entries"]
|
141 |
+
},
|
142 |
+
"ftc_advisory_opinions": {
|
143 |
+
"train": ["train.ftc_advisory_opinions"],
|
144 |
+
"validation": ["validation.ftc_advisory_opinions"]
|
145 |
+
},
|
146 |
+
"eoir": {
|
147 |
+
"train": ["train.eoir"],
|
148 |
+
"validation": ["validation.eoir"]
|
149 |
+
},
|
150 |
+
"dol_ecab": {
|
151 |
+
"train": ["train.dol_ecab"],
|
152 |
+
"validation": ["validation.dol_ecab"]
|
153 |
+
},
|
154 |
+
"hhs_alj_opinions": {
|
155 |
+
"train": ["train.hhs_alj"],
|
156 |
+
"validation": ["validation.hhs_alj"]
|
157 |
+
},
|
158 |
+
"sec_administrative_proceedings": {
|
159 |
+
"train": ["train.sec"],
|
160 |
+
"validation": ["validation.sec"]
|
161 |
+
},
|
162 |
+
},
|
163 |
+
LEGISLATION: {
|
164 |
+
"federal_register": {
|
165 |
+
"train": ["train.federal_register"],
|
166 |
+
"validation": ["validation.federal_register"]
|
167 |
+
},
|
168 |
+
"us_bills": {
|
169 |
+
"train": ["train.us_bills"],
|
170 |
+
"validation": ["validation.us_bills"]
|
171 |
+
},
|
172 |
+
"cfr": {
|
173 |
+
"train": ["train.cfr"],
|
174 |
+
"validation": ["validation.cfr"]
|
175 |
+
},
|
176 |
+
"state_codes": {
|
177 |
+
"train": ["train.state_code"],
|
178 |
+
"validation": ["validation.state_code"]
|
179 |
+
},
|
180 |
+
"uscode": {
|
181 |
+
"train": ["train.uscode"],
|
182 |
+
"validation": ["validation.uscode"]
|
183 |
+
},
|
184 |
+
"founding_docs": {
|
185 |
+
"train": ["train.founding_docs"],
|
186 |
+
"validation": ["validation.founding_docs"]
|
187 |
+
},
|
188 |
+
"eurlex": {
|
189 |
+
"train": ["train.eurlex"],
|
190 |
+
"validation": ["validation.eurlex"]
|
191 |
+
},
|
192 |
+
"fre": {
|
193 |
+
"train": ["train.fre"],
|
194 |
+
"validation": ["validation.fre"]
|
195 |
+
},
|
196 |
+
"frcp": {
|
197 |
+
"train": ["train.frcp"],
|
198 |
+
"validation": ["validation.frcp"]
|
199 |
+
},
|
200 |
+
},
|
201 |
+
CONTRACTS: {
|
202 |
+
"atticus_contracts": {
|
203 |
+
"train": [
|
204 |
+
"train.atticus_contracts.0",
|
205 |
+
"train.atticus_contracts.1",
|
206 |
+
"train.atticus_contracts.2",
|
207 |
+
"train.atticus_contracts.3",
|
208 |
+
"train.atticus_contracts.4"
|
209 |
+
],
|
210 |
+
"validation": [
|
211 |
+
"validation.atticus_contracts.0",
|
212 |
+
"validation.atticus_contracts.1"
|
213 |
+
]
|
214 |
+
},
|
215 |
+
"resource_contracts": {
|
216 |
+
"train": ["train.resource_contracts"],
|
217 |
+
"validation": ["validation.resource_contracts"]
|
218 |
+
},
|
219 |
+
},
|
220 |
+
OTHER: {
|
221 |
+
"congressional_hearings": {
|
222 |
+
"train": ["train.congressional_hearings"],
|
223 |
+
"validation": ["validation.congressional_hearings"]
|
224 |
+
},
|
225 |
+
"oig": {
|
226 |
+
"train": ["train.oig"],
|
227 |
+
"validation": ["validation.oig"]
|
228 |
+
},
|
229 |
+
"olc_memos": {
|
230 |
+
"train": ["train.olc_memos"],
|
231 |
+
"validation": ["validation.olc_memos"]
|
232 |
+
},
|
233 |
+
"un_debates": {
|
234 |
+
"train": ["train.undebates"],
|
235 |
+
"validation": ["validation.undebates"]
|
236 |
+
},
|
237 |
+
"uspto_office_actions": {
|
238 |
+
"train": ["train.uspto_oab"],
|
239 |
+
"validation": ["validation.uspto_oab"]
|
240 |
+
},
|
241 |
+
"ed_policy_guidance": {
|
242 |
+
"train": ["train.ed_policy_guidance"],
|
243 |
+
"validation": ["validation.ed_policy_guidance"]
|
244 |
+
},
|
245 |
+
"acus_reports": {
|
246 |
+
"train": ["train.acus_reports"],
|
247 |
+
"validation": ["validation.acus_reports"]
|
248 |
+
},
|
249 |
+
"fmshrc_bluebooks": {
|
250 |
+
"train": ["train.fmshrc"],
|
251 |
+
"validation": ["validation.fmshrc"]
|
252 |
+
},
|
253 |
+
"medicaid_policy_guidance": {
|
254 |
+
"train": ["train.medicaid_policy_guidance"],
|
255 |
+
"validation": ["validation.medicaid_policy_guidance"]
|
256 |
+
},
|
257 |
+
"irs_legal_advice_memos": {
|
258 |
+
"train": ["train.irs_legal_advice_memos"],
|
259 |
+
"validation": ["validation.irs_legal_advice_memos"]
|
260 |
+
},
|
261 |
+
"doj_guidance_documents": {
|
262 |
+
"train": ["train.doj_guidance"],
|
263 |
+
"validation": ["validation.doj_guidance"]
|
264 |
+
}
|
265 |
+
},
|
266 |
+
LEGAL_MC4: {}
|
267 |
+
}
|
268 |
+
|
269 |
+
_LEGAL_MC4_SHARDS = {
|
270 |
+
"bg": 0,
|
271 |
+
"cs": 2,
|
272 |
+
"da": 0,
|
273 |
+
"de": 8,
|
274 |
+
"el": 0,
|
275 |
+
"en": 1,
|
276 |
+
"es": 9,
|
277 |
+
"et": 0,
|
278 |
+
"fi": 0,
|
279 |
+
"fr": 2,
|
280 |
+
"ga": 0,
|
281 |
+
# "hr", # hr is not present in mc4
|
282 |
+
"hu": 0,
|
283 |
+
"it": 3,
|
284 |
+
"lt": 0,
|
285 |
+
"lv": 0,
|
286 |
+
"mt": 0,
|
287 |
+
"nl": 0,
|
288 |
+
"pl": 2,
|
289 |
+
"pt": 1,
|
290 |
+
"ro": 0,
|
291 |
+
"sk": 0,
|
292 |
+
"sl": 0,
|
293 |
+
"sv": 0,
|
294 |
+
}
|
295 |
+
|
296 |
+
_LANGUAGES = ["bg", "cs", "da", "de", "el", "en", "es", "et", "fi", "fr", "ga", "hr",
|
297 |
+
"hu", "it", "lt", "lv", "mt", "nl", "pl", "pt", "ro", "sk", "sl", "sv"]
|
298 |
+
|
299 |
+
_TYPES = [CASELAW, CONTRACTS, LEGISLATION, OTHER, LEGAL_MC4]
|
300 |
+
|
301 |
+
_JURISDICTIONS = ["Austria", "Belgium", "Brazil", "Bulgaria", "Croatia", "Czechia", "Denmark", "Estonia", "Finland",
|
302 |
+
"France", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg",
|
303 |
+
"Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Sweden",
|
304 |
+
"EU", "Switzerland", "UK", "US", "Canada", "N/A"]
|
305 |
+
|
306 |
+
|
307 |
+
class MultiLegalPileConfig(datasets.BuilderConfig):
|
308 |
+
"""BuilderConfig for MultiLegalPile."""
|
309 |
+
|
310 |
+
def __init__(self, name: str, repo_data_only=False, **kwargs):
|
311 |
+
"""BuilderConfig for MultiLegalPile.
|
312 |
+
Args:
|
313 |
+
name: combination of language and type with _
|
314 |
+
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
|
315 |
+
type: One of caselaw,contracts,legislation,other,legal-mc4 or all
|
316 |
+
**kwargs: keyword arguments forwarded to super.
|
317 |
+
"""
|
318 |
+
super(MultiLegalPileConfig, self).__init__(**kwargs)
|
319 |
+
self.name = name
|
320 |
+
self.language = name.split("_")[0]
|
321 |
+
self.type = name.split("_")[1]
|
322 |
+
self.repo_data_only = repo_data_only
|
323 |
+
|
324 |
+
|
325 |
+
class MultiLegalPile(datasets.GeneratorBasedBuilder):
|
326 |
+
"""MultiLegalPile: A Corpus Covering Large-Scale Multilingual Legal Data"""
|
327 |
+
BUILDER_CONFIG_CLASS = MultiLegalPileConfig
|
328 |
+
|
329 |
+
BUILDER_CONFIGS = [MultiLegalPileConfig(f"{language}_{type}",
|
330 |
+
version=VERSION,
|
331 |
+
description=f"MultiLegalPile for language {language} and type {type}")
|
332 |
+
for type in _TYPES + ["all"]
|
333 |
+
for language in _LANGUAGES + ["all"]]
|
334 |
+
|
335 |
+
def _info(self):
|
336 |
+
return datasets.DatasetInfo(
|
337 |
+
description=_DESCRIPTION,
|
338 |
+
features=datasets.Features(
|
339 |
+
{
|
340 |
+
"language": datasets.Value("string"), # one of _LANGUAGES
|
341 |
+
"type": datasets.Value("string"), # one of _TYPES
|
342 |
+
"jurisdiction": datasets.Value("string"), # one of _JURISDICTIONS
|
343 |
+
"text": datasets.Value("string"),
|
344 |
+
}
|
345 |
+
),
|
346 |
+
supervised_keys=None,
|
347 |
+
homepage=_URL,
|
348 |
+
citation=_CITATION,
|
349 |
+
)
|
350 |
+
|
351 |
+
def _split_generators(self, dl_manager):
|
352 |
+
def download_url(dataset, file_name):
|
353 |
+
url = hf_hub_url(repo_id=dataset, filename=f"data/{file_name}.jsonl.xz", repo_type="dataset")
|
354 |
+
return dl_manager.download(url)
|
355 |
+
|
356 |
+
data_infos = []
|
357 |
+
languages = _LANGUAGES if self.config.language == "all" else [self.config.language]
|
358 |
+
types = _TYPES if self.config.type == "all" else [self.config.type]
|
359 |
+
|
360 |
+
for language in languages:
|
361 |
+
for type in types:
|
362 |
+
info = {"language": language, "type": type}
|
363 |
+
# add native MultiLegalPile data
|
364 |
+
if language in _DATA_NAME and type in _DATA_NAME[language]: # if we actually have something there
|
365 |
+
for data_name in _DATA_NAME[language][type]:
|
366 |
+
info["jurisdiction"] = data_name.split("_")[0].capitalize()
|
367 |
+
info["filepath"] = download_url("joelito/Multi_Legal_Pile", f"{language}/{type}/{data_name}")
|
368 |
+
data_infos.append(info.copy())
|
369 |
+
|
370 |
+
if not self.config.repo_data_only:
|
371 |
+
# add eurlex_resources data
|
372 |
+
info["jurisdiction"] = "EU"
|
373 |
+
if type == 'caselaw':
|
374 |
+
info["filepath"] = download_url("joelito/eurlex_resources", f"{language}/caselaw")
|
375 |
+
data_infos.append(info.copy())
|
376 |
+
elif type == 'legislation':
|
377 |
+
for resource_type in ["decision", "directive", "regulation", "recommendation", "proposal"]:
|
378 |
+
info["filepath"] = download_url("joelito/eurlex_resources", f"{language}/{resource_type}")
|
379 |
+
data_infos.append(info.copy())
|
380 |
+
elif type == 'contracts':
|
381 |
+
# international agreements
|
382 |
+
info["filepath"] = download_url("joelito/eurlex_resources", f"{language}/intagr")
|
383 |
+
data_infos.append(info.copy())
|
384 |
+
|
385 |
+
# add legal-mc4 data
|
386 |
+
if type == LEGAL_MC4:
|
387 |
+
info["jurisdiction"] = "N/A"
|
388 |
+
if language == "hr":
|
389 |
+
pass
|
390 |
+
else:
|
391 |
+
for split in ["train", "validation"]:
|
392 |
+
shards = range(_LEGAL_MC4_SHARDS[language] + 1) if split == "train" else [0]
|
393 |
+
for shard in shards:
|
394 |
+
info["filepath"] = download_url("joelito/legal-mc4", f"{language}.{split}.{shard}")
|
395 |
+
data_infos.append(info.copy())
|
396 |
+
|
397 |
+
# add pile-of-law data
|
398 |
+
if language == 'en':
|
399 |
+
info["jurisdiction"] = "US"
|
400 |
+
for name, train_val_files in _PILE_OF_LAW_NAMES[type].items():
|
401 |
+
if name == 'canadian_decisions':
|
402 |
+
info["jurisdiction"] = "Canada"
|
403 |
+
elif name in ['echr', 'eurlex', 'euro_parl']:
|
404 |
+
info["jurisdiction"] = "EU"
|
405 |
+
elif name in ['constitutions', 'icj-pcij', 'r_legaladvice', 'un_debates', 'tos']:
|
406 |
+
info["jurisdiction"] = "N/A"
|
407 |
+
for split in ["train", "validation"]:
|
408 |
+
for file_name in train_val_files[split]:
|
409 |
+
info["filepath"] = download_url("pile-of-law/pile-of-law", file_name)
|
410 |
+
data_infos.append(info.copy())
|
411 |
+
|
412 |
+
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"data_infos": data_infos})]
|
413 |
+
|
414 |
+
def _generate_examples(self, data_infos):
|
415 |
+
"""This function returns the examples in the raw (text) form by iterating on all the files."""
|
416 |
+
id_ = 0
|
417 |
+
for data_info in data_infos:
|
418 |
+
logger.info("Generating examples from = %s", data_info["filepath"])
|
419 |
+
try:
|
420 |
+
with xz.open(open(data_info["filepath"], "rb"), "rt", encoding="utf-8") as f:
|
421 |
+
for line in f:
|
422 |
+
if line:
|
423 |
+
example = json.loads(line)
|
424 |
+
if example is not None and isinstance(example, dict):
|
425 |
+
yield id_, {
|
426 |
+
# uses the default values for language, type and jurisdiction if it is not set
|
427 |
+
"language": example.get("language", data_info["language"]),
|
428 |
+
"type": example.get("type", data_info["type"]),
|
429 |
+
"jurisdiction": example.get("jurisdiction", data_info["jurisdiction"]),
|
430 |
+
"text": example.get("text", ""),
|
431 |
+
}
|
432 |
+
id_ += 1
|
433 |
+
except Exception:
|
434 |
+
logger.exception("Error while processing file %s", data_info["filepath"])
|