Datasets:
rcds
/

Modalities:
Text
ArXiv:
Libraries:
Datasets
License:
vr18 commited on
Commit
b5dad54
·
1 Parent(s): f091098

Upload loading script and debug data

Browse files
data/areas/huggingface/test.jsonl.xz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc29bc921155edcfd7b1ba9e330a5f7c1f8ee5617fdd74afc71bf2eac04e4fc6
3
+ size 10259328
data/areas/huggingface/train.jsonl.xz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ecf68115fa37605bbd8a8265d5ad6c4f0dfccd34a4217bd096c4b5c7d8c79381
3
+ size 9393812
data/areas/huggingface/validation.jsonl.xz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:adf8b8458ffd6c01dbaa57c41a8f62b14ad0ccc187703ecc406f9fa1f44d8cb7
3
+ size 3031564
data/sub_areas/huggingface/test.jsonl.xz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99cba03319658dacb33f80ff1ce157f2ddb5e923dc75527e31356dfab8c7f7f9
3
+ size 5413996
data/sub_areas/huggingface/train.jsonl.xz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be146bc76f82994920a6f84b3ad7555504ca96aba957e5e29fce933548811349
3
+ size 5419304
data/sub_areas/huggingface/validation.jsonl.xz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7fed6d7425e9574e07d13c68ae5071c19e857ad78ff8a2e2531688e86c6dc9ee
3
+ size 1829180
law_area_prediction.py ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import json
3
+ import lzma
4
+ import os
5
+
6
+ import datasets
7
+ try:
8
+ import lzma as xz
9
+ except ImportError:
10
+ import pylzma as xz
11
+
12
+
13
+ # TODO: Add BibTeX citation
14
+ # Find for instance the citation on arxiv or on the dataset repo/website
15
+ _CITATION = """\
16
+ @InProceedings{huggingface:dataset,
17
+ title = {A great new dataset},
18
+ author={huggingface, Inc.
19
+ },
20
+ year={2020}
21
+ }
22
+ """
23
+
24
+ # You can copy an official description
25
+ _DESCRIPTION = """\
26
+ This dataset contains court decision for law area prediction task.
27
+ """
28
+
29
+ # TODO: Add a link to an official homepage for the dataset here
30
+ _HOMEPAGE = ""
31
+
32
+ # TODO: Add the licence for the dataset here if you can find it
33
+ _LICENSE = ""
34
+
35
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
36
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
37
+ _URLS = {
38
+ "main": "https://huggingface.co/datasets/rcds/law_area_prediction/resolve/main/data/areas/huggingface",
39
+ "sub": "https://huggingface.co/datasets/rcds/law_area_prediction/resolve/main/data/sub_areas/huggingface"
40
+ }
41
+
42
+ def get_url(config_name):
43
+ if config_name == "main":
44
+ return _URLS["main"]
45
+ if config_name == "public sub" or config_name == "civil sub" or config_name == "criminal sub":
46
+ return _URLS["sub"]
47
+
48
+
49
+ class CourtViewGeneration(datasets.GeneratorBasedBuilder):
50
+ """This dataset contains court decision for law area prediction task."""
51
+
52
+ VERSION = datasets.Version("1.1.0")
53
+
54
+ # This is an example of a dataset with multiple configurations.
55
+ # If you don't want/need to define several sub-sets in your dataset,
56
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
57
+
58
+ # If you need to make complex sub-parts in the datasets with configurable options
59
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
60
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
61
+
62
+ # You will be able to load one or the other configurations in the following list with
63
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
64
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
65
+ BUILDER_CONFIGS = [
66
+ datasets.BuilderConfig(name="main", version=VERSION, description="This part of my dataset covers the whole dataset"),
67
+ datasets.BuilderConfig(name="public sub", version=VERSION, description="This dataset is for predicting the sub law areas of the public law"),
68
+ datasets.BuilderConfig(name="civil sub", version=VERSION, description="This dataset is for predicting the sub law areas of the civil law"),
69
+ datasets.BuilderConfig(name="criminal sub", version=VERSION, description="This dataset is for predicting the sub law areas of the criminal law"),
70
+ ]
71
+
72
+ DEFAULT_CONFIG_NAME = "main" # It's not mandatory to have a default configuration. Just use one if it make sense.
73
+
74
+ def _info(self):
75
+ if self.config.name == "main": # This is the name of the configuration selected in BUILDER_CONFIGS above
76
+ features = datasets.Features(
77
+ {
78
+ "decision_id": datasets.Value("string"),
79
+ "facts": datasets.Value("string"),
80
+ "considerations": datasets.Value("string"),
81
+ "label": datasets.Value("string"),
82
+ "law_sub_area": datasets.Value("string"),
83
+ "language": datasets.Value("string"),
84
+ "year": datasets.Value("int32"),
85
+ "court": datasets.Value("string"),
86
+ "chamber": datasets.Value("string"),
87
+ "canton": datasets.Value("string"),
88
+ "region": datasets.Value("string")
89
+
90
+ # These are the features of your dataset like images, labels ...
91
+ }
92
+ )
93
+ if self.config.name != "main": # for law sub area prediction
94
+ features = datasets.Features(
95
+ {
96
+ "decision_id": datasets.Value("string"),
97
+ "facts": datasets.Value("string"),
98
+ "considerations": datasets.Value("string"),
99
+ "law_area": datasets.Value("string"),
100
+ "label": datasets.Value("string"),
101
+ "language": datasets.Value("string"),
102
+ "year": datasets.Value("int32"),
103
+ "court": datasets.Value("string"),
104
+ "chamber": datasets.Value("string"),
105
+ "canton": datasets.Value("string"),
106
+ "region": datasets.Value("string")
107
+ }
108
+ )
109
+ return datasets.DatasetInfo(
110
+ # This is the description that will appear on the datasets page.
111
+ description=_DESCRIPTION,
112
+ # This defines the different columns of the dataset and their types
113
+ features=features, # Here we define them above because they are different between the two configurations
114
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
115
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
116
+ # supervised_keys=("sentence", "label"),
117
+ # Homepage of the dataset for documentation
118
+ # homepage=_HOMEPAGE,
119
+ # License for the dataset if available
120
+ # license=_LICENSE,
121
+ # Citation for the dataset
122
+ # citation=_CITATION,
123
+ )
124
+
125
+ def _split_generators(self, dl_manager):
126
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
127
+
128
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
129
+ # 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.
130
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
131
+ urls = get_url(self.config.name)
132
+ filepath_train = dl_manager.download(os.path.join(urls, "train.jsonl.xz"))
133
+ filepath_validation = dl_manager.download(os.path.join(urls, "validation.jsonl.xz"))
134
+ filepath_test = dl_manager.download(os.path.join(urls, "test.jsonl.xz"))
135
+
136
+ return [
137
+ datasets.SplitGenerator(
138
+ name=datasets.Split.TRAIN,
139
+ # These kwargs will be passed to _generate_examples
140
+ gen_kwargs={
141
+ "filepath": filepath_train,
142
+ "split": "train",
143
+ },
144
+ ),
145
+ datasets.SplitGenerator(
146
+ name=datasets.Split.VALIDATION,
147
+ # These kwargs will be passed to _generate_examples
148
+ gen_kwargs={
149
+ "filepath": filepath_validation,
150
+ "split": "validation",
151
+ },
152
+ ),
153
+ datasets.SplitGenerator(
154
+ name=datasets.Split.TEST,
155
+ # These kwargs will be passed to _generate_examples
156
+ gen_kwargs={
157
+ "filepath": filepath_test,
158
+ "split": "test"
159
+ },
160
+ )
161
+ ]
162
+
163
+ def belongs_to_law_area(self, law_sub_area):
164
+ area_map = {
165
+ "public sub": ['Tax', 'Urban Planning and Environmental', 'Expropriation', 'Public Administration', 'Other Fiscal'],
166
+ "civil sub": ['Rental and Lease', 'Employment Contract', 'Bankruptcy', 'Family', 'Competition and Antitrust', 'Intellectual Property'],
167
+ 'criminal sub': ['Substantive Criminal', 'Criminal Procedure']
168
+ }
169
+ if law_sub_area in area_map[self.config.name]:
170
+ return True
171
+ # raise Error if law_sub_area not found in any area
172
+ for area in area_map:
173
+ if law_sub_area in area_map[area]:
174
+ return False
175
+ raise ValueError("law_sub_area not found in any area")
176
+
177
+
178
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
179
+ def _generate_examples(self, filepath, split):
180
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
181
+ line_counter = 0
182
+ try:
183
+ with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
184
+ for id, line in enumerate(f):
185
+ line_counter += 1
186
+ if line:
187
+ data = json.loads(line)
188
+ if self.config.name == "main":
189
+ yield id, {
190
+ "decision_id": data["decision_id"],
191
+ "facts": data["facts"],
192
+ "considerations": data["considerations"],
193
+ "label": data["label"],
194
+ "law_sub_area": data["law_sub_area"],
195
+ "language": data["language"],
196
+ "year": data["year"],
197
+ "court": data["court"],
198
+ "chamber": data["chamber"],
199
+ "canton": data["canton"],
200
+ "region": data["region"]
201
+ }
202
+ if self.config.name == "public sub" or self.config.name == "civil sub" or self.config.name == "criminal sub":
203
+ if self.belongs_to_law_area(data["law_sub_area"]):
204
+ yield id, {
205
+ "decision_id": data["decision_id"],
206
+ "facts": data["facts"],
207
+ "considerations": data["considerations"],
208
+ "law_area": data["law_area"],
209
+ "label": data["label"],
210
+ "language": data["language"],
211
+ "year": data["year"],
212
+ "court": data["court"],
213
+ "chamber": data["chamber"],
214
+ "canton": data["canton"],
215
+ "region": data["region"]
216
+ }
217
+ except lzma.LZMAError as e:
218
+ print(split, e)
219
+ if line_counter == 0:
220
+ raise e