clairebarale commited on
Commit
7be07aa
·
1 Parent(s): 1c9e8fc

Delete AsyLex.py

Browse files
Files changed (1) hide show
  1. AsyLex.py +0 -345
AsyLex.py DELETED
@@ -1,345 +0,0 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- """AsyLex: A Dataset for Legal Language Processing of Refugee Claims"""
16
-
17
-
18
- import csv
19
- import json
20
- import os
21
-
22
- import datasets
23
-
24
-
25
- # TODO: Add BibTeX citation
26
- # Find for instance the citation on arxiv or on the dataset repo/website
27
- _CITATION = """\
28
- @inproceedings{barale-etal-2023-automated,
29
- title = "Automated Refugee Case Analysis: A {NLP} Pipeline for Supporting Legal Practitioners",
30
- author = "Barale, Claire and
31
- Rovatsos, Michael and
32
- Bhuta, Nehal",
33
- booktitle = "Findings of the Association for Computational Linguistics: ACL 2023",
34
- month = jul,
35
- year = "2023",
36
- address = "Toronto, Canada",
37
- publisher = "Association for Computational Linguistics",
38
- url = "https://aclanthology.org/2023.findings-acl.187",
39
- doi = "10.18653/v1/2023.findings-acl.187",
40
- pages = "2992--3005",
41
- }
42
- """
43
-
44
- # TODO: Add description of the dataset here
45
- # You can copy an official description
46
- _DESCRIPTION = """\
47
- The dataset introduces 59,112 documents of refugee status determination in Canada from 1996 to 2022, providing researchers and practitioners with essential material for training and evaluating NLP models for legal research and case review.
48
-
49
- AsyLex contains labeled data suited for two NLP tasks: (1) Entity extraction and (2) Legal Judgment Prediction.
50
- """
51
-
52
- _LICENSE = "cc-by-nc-sa-4.0"
53
-
54
- # TODO: Add link to the official dataset URLs here
55
- # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
56
- # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
57
- _URLS = {
58
- "raw_documents": "https://huggingface.co/datasets/clairebarale/AsyLex/raw/main/cases_anonymized_txt_raw.tar.gz",
59
- "raw_sentences": "https://huggingface.co/datasets/clairebarale/AsyLex/raw/main/all_sentences_anonymized.tar.xz",
60
- "all_legal_entities": "https://huggingface.co/datasets/clairebarale/AsyLex/raw/main/main_and_case_cover_all_entities_inferred.csv",
61
- "casecover_legal_entities": "https://huggingface.co/datasets/clairebarale/AsyLex/blob/main/case_cover/case_cover_anonymised_extracted_entities.csv",
62
- "casecover_entities_outcome": "https://huggingface.co/datasets/clairebarale/AsyLex/blob/main/case_cover/case_cover_entities_and_decision_outcome.csv",
63
- "determination_sentences": "https://huggingface.co/datasets/clairebarale/AsyLex/blob/main/determination_label_extracted_sentences.csv",
64
- "outcome_classification": "https://huggingface.co/datasets/clairebarale/AsyLex/tree/main/outcome_train_test/"
65
- }
66
-
67
-
68
-
69
- class Asylex(datasets.GeneratorBasedBuilder):
70
- """AsyLex: A Dataset for Legal Language Processing of Refugee Claims"""
71
-
72
- VERSION = datasets.Version("1.1.0")
73
-
74
- # If you need to make complex sub-parts in the datasets with configurable options
75
- # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
76
- # BUILDER_CONFIG_CLASS = MyBuilderConfig
77
-
78
- # You will be able to load one or the other configurations in the following list with
79
- # data = datasets.load_dataset('my_dataset', 'raw_documents')
80
- # data = datasets.load_dataset('my_dataset', 'raw_sentences')
81
- BUILDER_CONFIGS = [
82
- datasets.BuilderConfig(name="raw_documents", version=VERSION, description="contains the raw text from all documents, by case, with the corresponding case identifier"),
83
- datasets.BuilderConfig(name="raw_sentences", version=VERSION, description="contains the raw text from all retrieved documents, split by sentences, with the corresponding case identifier"),
84
- datasets.BuilderConfig(name="all_legal_entities", version=VERSION, description="contains the structured dataset, all extracted entities (one column per entity type), with the corresponding case identifier"),
85
- datasets.BuilderConfig(name="casecover_legal_entities", version=VERSION, description="contains the structured dataset derived from the case covers only (one column per entity type), with the corresponding case identifier"),
86
- datasets.BuilderConfig(name="casecover_entities_outcome", version=VERSION, description="contains the structured dataset derived from the case covers only (one column per entity type), with the corresponding case identifier, with the addition of the decision outcome of the case"),
87
- datasets.BuilderConfig(name="determination_sentences", version=VERSION, description="contains all sentences that have been extracted with the Entity Type determination. All sentences included here should therefore directly state the outcome of the decision, with the correspinding case identifier"),
88
- datasets.BuilderConfig(name="outcome_classification", version=VERSION, description="folder containing a train and test set for the task of outcome classificiation. Each set includes the case identifier and the decision outcome (0,1,2). The test set only contains gold-standard manually labeled data."),
89
-
90
- ]
91
-
92
- DEFAULT_CONFIG_NAME = "raw_sentences"
93
-
94
- def _info(self):
95
- # This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
96
- if self.config.name == "raw_documents":
97
- features = datasets.Features(
98
- {
99
- "case_files": datasets.Value("file"),
100
- }
101
- )
102
- elif self.config.name == "raw_sentences":
103
- features = datasets.Features(
104
- {
105
- "decisionID": datasets.Value("int64"),
106
- "Text": datasets.Value("string"),
107
- }
108
- )
109
- elif self.config.name == "all_legal_entities":
110
- features = datasets.Features(
111
- {
112
- "decisionID": datasets.Value("int64"),
113
- "Text": datasets.Value("string"),
114
- "GPE": datasets.Value("string"),
115
- "DATE": datasets.Value("string"),
116
- "NORP": datasets.Value("string"),
117
- "ORG": datasets.Value("string"),
118
- "LAW": datasets.Value("string"),
119
- "CLAIMANT_EVENTS": datasets.Value("string"),
120
- "CREDIBILITY": datasets.Value("string"),
121
- "DETERMINATION": datasets.Value("string"),
122
- "CLAIMANT_INFO": datasets.Value("string"),
123
- "PROCEDURE": datasets.Value("string"),
124
- "DOC_EVIDENCE": datasets.Value("string"),
125
- "EXPLANATION": datasets.Value("string"),
126
- "LEGAL_GROUND": datasets.Value("string"),
127
- "LAW_CASE": datasets.Value("string"),
128
- "LAW_REPORT": datasets.Value("string"),
129
- "decision_outcome": datasets.ClassLabel(
130
- names=['Rejected', 'Granted', 'Uncertain']
131
- ),
132
- "extracted_dates": datasets.Value("string"),
133
- "LOC_HEARING": datasets.Value("string"),
134
- "TRIBUNAL": datasets.Value("string"),
135
- "PUBLIC_PRIVATE_HEARING": datasets.Value("string"),
136
- "INCHAMBER_VIRTUAL_HEARING": datasets.Value("string"),
137
- "JUDGE": datasets.Value("string"),
138
- "text_case_cover": datasets.Value("string"),
139
- "DATE_DECISION": datasets.Value("string"),
140
- }
141
- )
142
-
143
- elif self.config.name == "casecover_legal_entities":
144
- features = datasets.Features(
145
- {
146
- "decision_ID": datasets.Value("int64"),
147
- "extracted_dates": datasets.Value("string"),
148
- "extracted_gpe": datasets.Value("string"),
149
- "extracted_org": datasets.Value("string"),
150
- "public_private_hearing": datasets.Value("string"),
151
- "in_chamber_virtual": datasets.Value("string"),
152
- "judge_name": datasets.Value("string"),
153
- "date_decision": datasets.Value("string"),
154
- "text_case_cover": datasets.Value("string"),
155
- }
156
- )
157
- elif self.config.name == "casecover_entities_outcome":
158
- features = datasets.Features(
159
- {
160
- "decision_ID": datasets.Value("int64"),
161
- "extracted_dates": datasets.Value("string"),
162
- "LOC_HEARING": datasets.Value("string"),
163
- "TRIBUNAL": datasets.Value("string"),
164
- "PUBLIC_PRIVATE_HEARING": datasets.Value("string"),
165
- "INCHAMBER_VIRTUAL_HEARING": datasets.Value("string"),
166
- "JUDGE": datasets.Value("string"),
167
- "text_case_cover": datasets.Value("string"),
168
- "DATE_DECISION": datasets.Value("string"),
169
- "decision_outcome": datasets.ClassLabel(
170
- names=['Rejected', 'Granted', 'Uncertain']),
171
- }
172
- )
173
- elif self.config.name == "determination_sentences":
174
- features = datasets.Features(
175
- {
176
- "decisionID": datasets.Value("int64"),
177
- "extracted_sentences_determination": datasets.Value("string"),
178
- }
179
- )
180
- elif self.config.name == "outcome_classification":
181
- features = datasets.Features(
182
- {
183
- "decisionID": datasets.Value("float64"),
184
- "decision_outcome": datasets.ClassLabel(
185
- names=['Rejected', 'Granted', 'Uncertain']),
186
- }
187
- )
188
-
189
- data_files = {
190
- "train": "outcome_train_test/train_dataset_silver.csv",
191
- "test": "outcome_train_test/test_dataset_gold.csv",
192
- }
193
- return datasets.DatasetInfo(
194
- # This is the description that will appear on the datasets page.
195
- description="The dataset introduces 59,112 documents of refugee status determination in Canada from 1996 to 2022, providing researchers and practitioners with essential material for training and evaluating NLP models for legal research and case review. AsyLex contains labeled data suited for two NLP tasks: (1) Entity extraction and (2) Legal Judgment Prediction.",
196
- # This defines the different columns of the dataset and their types
197
- features=features,
198
- # License for the dataset if available
199
- license=_LICENSE,
200
- # Citation for the dataset
201
- citation=_CITATION,
202
- )
203
-
204
- def _split_generators(self, dl_manager):
205
- # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
206
- # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
207
-
208
- # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
209
- # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
210
- # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
211
- urls_to_download = _URLS[self.config.name]
212
- downloaded_files = dl_manager.download_and_extract(urls_to_download)
213
-
214
- if self.config.name == "outcome_classification":
215
- data_dir = dl_manager.download_and_extract(_URLS["outcome_classification"])
216
- return [
217
- datasets.SplitGenerator(
218
- name=datasets.Split.TRAIN,
219
- gen_kwargs={
220
- "filepath": os.path.join(data_dir, "train_dataset_silver.csv"),
221
- "split": "train",
222
- },
223
- ),
224
- datasets.SplitGenerator(
225
- name=datasets.Split.TEST,
226
- # These kwargs will be passed to _generate_examples
227
- gen_kwargs={
228
- "filepath": os.path.join(data_dir, "test_dataset_gold.csv"),
229
- "split": "test"
230
- },
231
- ),
232
- ]
233
- else:
234
- return [
235
- datasets.SplitGenerator(
236
- name=datasets.Split.TRAIN,
237
- gen_kwargs={
238
- "filepath": downloaded_files,
239
- "split": "train",
240
- },
241
- )
242
- ]
243
-
244
- # key value examples
245
- def generate_examples(self, file_path, split):
246
-
247
- if self.config.name == "raw_documents":
248
- for idx, filename in enumerate(os.listdir(file_path)):
249
- if filename.endswith(".txt"):
250
- with open(os.path.join(file_path, filename), "r", encoding="utf-8") as f:
251
- # Read the content of the text file
252
- text_content = f.read()
253
- yield idx, {"case_files": text_content}
254
-
255
- elif self.config.name == "raw_sentences":
256
- with open(file_path, "r", encoding="utf-8") as f:
257
- for idx, line in f:
258
- parts = line.strip().split(";")
259
- if len(parts) == 2:
260
- decisionID, Text = parts
261
- yield idx, {"decisionID": int(decisionID), "Text": Text}
262
-
263
- elif self.config.name == "all_legal_entities":
264
- with open(file_path, "r", encoding="utf-8") as f:
265
- reader = csv.DictReader(f, delimiter=";")
266
- for idx, row in enumerate(reader):
267
- yield idx, {
268
- "decisionID": int(row["decisionID"]),
269
- "Text": row["Text"],
270
- "GPE": row["GPE"],
271
- "DATE": row["DATE"],
272
- "NORP": row["NORP"],
273
- "ORG": row["ORG"],
274
- "LAW": row["LAW"],
275
- "CLAIMANT_EVENTS": row["CLAIMANT_EVENTS"],
276
- "CREDIBILITY": row["CREDIBILITY"],
277
- "DETERMINATION": row["DETERMINATION"],
278
- "CLAIMANT_INFO": row["CLAIMANT_INFO"],
279
- "PROCEDURE": row["PROCEDURE"],
280
- "DOC_EVIDENCE": row["DOC_EVIDENCE"],
281
- "EXPLANATION": row["EXPLANATION"],
282
- "LEGAL_GROUND": row["LEGAL_GROUND"],
283
- "LAW_CASE": row["LAW_CASE"],
284
- "LAW_REPORT": row["LAW_REPORT"],
285
- "decision_outcome": row["decision_outcome"],
286
- "extracted_dates": row["extracted_dates"],
287
- "LOC_HEARING": row["LOC_HEARING"],
288
- "TRIBUNAL": row["TRIBUNAL"],
289
- "PUBLIC_PRIVATE_HEARING": row["PUBLIC_PRIVATE_HEARING"],
290
- "INCHAMBER_VIRTUAL_HEARING": row["INCHAMBER_VIRTUAL_HEARING"],
291
- "JUDGE": row["JUDGE"],
292
- "text_case_cover": row["text_case_cover"],
293
- "DATE_DECISION": row["DATE_DECISION"],
294
- }
295
-
296
- elif self.config.name == "casecover_legal_entities":
297
- with open(file_path, "r", encoding="utf-8") as f:
298
- reader = csv.DictReader(f, delimiter=",")
299
- for idx, row in enumerate(reader):
300
- yield idx, {
301
- "decision_ID": int(row["decision_ID"]),
302
- "extracted_dates": row["extracted_dates"],
303
- "extracted_gpe": row["extracted_gpe"],
304
- "extracted_org": row["extracted_org"],
305
- "public_private_hearing": row["public_private_hearing"],
306
- "in_chamber_virtual": row["in_chamber_virtual"],
307
- "judge_name": row["judge_name"],
308
- "date_decision": row["date_decision"],
309
- "text_case_cover": row["text_case_cover"],
310
- }
311
-
312
- elif self.config.name == "casecover_entities_outcome":
313
- with open(file_path, "r", encoding="utf-8") as f:
314
- reader = csv.DictReader(f, delimiter=";")
315
- for idx, row in enumerate(reader):
316
- yield idx, {
317
- "decision_ID": int(row["decision_ID"]),
318
- "extracted_dates": row["extracted_dates"],
319
- "LOC_HEARING": row["LOC_HEARING"],
320
- "TRIBUNAL": row["TRIBUNAL"],
321
- "PUBLIC_PRIVATE_HEARING": row["PUBLIC_PRIVATE_HEARING"],
322
- "INCHAMBER_VIRTUAL_HEARING": row["INCHAMBER_VIRTUAL_HEARING"],
323
- "JUDGE": row["JUDGE"],
324
- "text_case_cover": row["text_case_cover"],
325
- "DATE_DECISION": row["DATE_DECISION"],
326
- "decision_outcome": row["decision_outcome"],
327
- }
328
-
329
- elif self.config.name == "determination_sentences":
330
- with open(file_path, "r", encoding="utf-8") as f:
331
- for idx, line in f:
332
- parts = line.strip().split(";")
333
- if len(parts) == 2:
334
- decisionID, extracted_sentences_determination = parts
335
- yield idx, {"decisionID": int(decisionID), "extracted_sentences_determination": extracted_sentences_determination}
336
-
337
- elif self.config.name == "outcome_classification":
338
- with open(file_path, "r", encoding="utf-8") as f:
339
- reader = csv.DictReader(f, delimiter=";")
340
- for idx, row in enumerate(reader):
341
- yield idx, {
342
- "decisionID": float(row["decisionID"]),
343
- "decision_outcome": row["decision_outcome"],
344
- }
345
-