Datasets:
rcds
/

Nina Baumgartner commited on
Commit
ae62622
1 Parent(s): 30c6cda

Created loading script, added data directory and moved datasets to datadirectory

Browse files
README.md CHANGED
@@ -74,7 +74,9 @@ When the dataset is used in a multilingual setting selecting the the 'all_langua
74
 
75
  ```python
76
  from datasets import load_dataset
77
- dataset = load_dataset('occlusion_swiss_judgment_prediction', 'all_languages')```
 
 
78
 
79
 
80
  For occlusion:
 
74
 
75
  ```python
76
  from datasets import load_dataset
77
+ dataset = load_dataset('occlusion_swiss_judgment_prediction', 'all_languages')
78
+
79
+ ```
80
 
81
 
82
  For occlusion:
test_occ_1.jsonl.xz → data/test_occ_1.jsonl.xz RENAMED
File without changes
test_occ_2.jsonl.xz → data/test_occ_2.jsonl.xz RENAMED
File without changes
test_occ_3.jsonl.xz → data/test_occ_3.jsonl.xz RENAMED
File without changes
test_occ_4.jsonl.xz → data/test_occ_4.jsonl.xz RENAMED
File without changes
occlusion_swiss_judgment_prediction.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """Dataset for the Occlusion task."""
15
+
16
+ import json
17
+ import lzma
18
+ import os
19
+
20
+ import datasets
21
+
22
+ try:
23
+ import lzma as xz
24
+ except ImportError:
25
+ import pylzma as xz
26
+
27
+ # TODO: Add final BibTeX citation
28
+ # Find for instance the citation on arxiv or on the dataset repo/website
29
+ _CITATION = """\
30
+ @misc{baumgartner_nina_occlusion_2022,
31
+ title = {From Occlusion to Transparancy – An Occlusion-Based Explainability Approach for Legal Judgment Prediction in Switzerland},
32
+ shorttitle = {From Occlusion to Transparancy},
33
+ abstract = {Natural Language Processing ({NLP}) models have been used for more and more complex tasks such as Legal Judgment Prediction ({LJP}). A {LJP} model predicts the outcome of a legal case by utilizing its facts. This increasing deployment of Artificial Intelligence ({AI}) in high-stakes domains such as law and the involvement of sensitive data has increased the need for understanding such systems. We propose a multilingual occlusion-based explainability approach for {LJP} in Switzerland and conduct a study on the bias using Lower Court Insertion ({LCI}). We evaluate our results using different explainability metrics introduced in this thesis and by comparing them to high-quality Legal Expert Annotations using Inter Annotator Agreement. Our findings show that the model has a varying understanding of the semantic meaning and context of the facts section, and struggles to distinguish between legally relevant and irrelevant sentences. We also found that the insertion of a different lower court can have an effect on the prediction, but observed no distinct effects based on legal areas, cantons, or regions. However, we did identify a language disparity with Italian performing worse than the other languages due to representation inequality in the training data, which could lead to potential biases in the prediction in multilingual regions of Switzerland. Our results highlight the challenges and limitations of using {NLP} in the judicial field and the importance of addressing concerns about fairness, transparency, and potential bias in the development and use of {NLP} systems. The use of explainable artificial intelligence ({XAI}) techniques, such as occlusion and {LCI}, can help provide insight into the decision-making processes of {NLP} systems and identify areas for improvement. Finally, we identify areas for future research and development in this field in order to address the remaining limitations and challenges.},
34
+ author = {{Baumgartner, Nina}},
35
+ year = {2022},
36
+ langid = {english}
37
+ }
38
+ """
39
+
40
+ # You can copy an official description
41
+ _DESCRIPTION = """\
42
+ This dataset contains an implementation of occlusion for the SwissJudgmentPrediction task.
43
+ """
44
+ _LICENSE = "cc-by-sa-4.0"
45
+
46
+ _URLS = {
47
+ "full": "https://huggingface.co/datasets/rcds/occlusion_swiss_judgment_prediction"
48
+ }
49
+
50
+
51
+ class OcclusionSwissJudgmentPrediction(datasets.GeneratorBasedBuilder):
52
+ """This dataset contains court decision for the occlusion task"""
53
+
54
+ VERSION = datasets.Version("1.1.0")
55
+
56
+ BUILDER_CONFIGS = [
57
+ datasets.BuilderConfig(name="full", description="This part covers the whole dataset"),
58
+ ]
59
+
60
+ DEFAULT_CONFIG_NAME = "full" # It's not mandatory to have a default configuration. Just use one if it make sense.
61
+
62
+ def _info(self):
63
+ if self.config.name == "full": # This is the name of the configuration selected in BUILDER_CONFIGS above
64
+ features = datasets.Features(
65
+ {
66
+ "id": datasets.Value("int32"),
67
+ "year": datasets.Value("int32"),
68
+ "label": datasets.Value("string"),
69
+ "language": datasets.Value("string"),
70
+ "region": datasets.Value("string"),
71
+ "canton": datasets.Value("string"),
72
+ "legal_area": datasets.Value("string"),
73
+ "explainability_label": datasets.Value("string"),
74
+ "occluded_text": datasets.Value("string"),
75
+ "text": datasets.Value("string")
76
+
77
+ }
78
+ )
79
+ return datasets.DatasetInfo(
80
+ # This is the description that will appear on the datasets page.
81
+ description=_DESCRIPTION,
82
+ # This defines the different columns of the dataset and their types
83
+ features=features, # Here we define them above because they are different between the two configurations
84
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
85
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
86
+ # supervised_keys=("sentence", "label"),
87
+ # License for the dataset if available
88
+ license=_LICENSE,
89
+ # Citation for the dataset
90
+ citation=_CITATION,
91
+ )
92
+
93
+ def _split_generators(self, dl_manager):
94
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
95
+
96
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
97
+ # 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.
98
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
99
+ urls = _URLS[self.config.name]
100
+ filepath_test_1 = dl_manager.download(os.path.join(urls, "test_occ_1.jsonl.xz"))
101
+ filepath_test_2 = dl_manager.download(os.path.join(urls, "test_occ_1.jsonl.xz"))
102
+ filepath_test_3 = dl_manager.download(os.path.join(urls, "test_occ_1.jsonl.xz"))
103
+ filepath_test_4 = dl_manager.download(os.path.join(urls, "test_occ_1.jsonl.xz"))
104
+
105
+ return [
106
+ datasets.SplitGenerator(
107
+ name=datasets.Split.TEST_1,
108
+ # These kwargs will be passed to _generate_examples
109
+ gen_kwargs={
110
+ "filepath": filepath_test_1,
111
+ "split": "test_1"
112
+ },
113
+ ),
114
+ datasets.SplitGenerator(
115
+ name=datasets.Split.TEST_2,
116
+ # These kwargs will be passed to _generate_examples
117
+ gen_kwargs={
118
+ "filepath": filepath_test_2,
119
+ "split": "test_2"
120
+ },
121
+ ),
122
+ datasets.SplitGenerator(
123
+ name=datasets.Split.TEST_3,
124
+ # These kwargs will be passed to _generate_examples
125
+ gen_kwargs={
126
+ "filepath": filepath_test_3,
127
+ "split": "test_3"
128
+ },
129
+ ),
130
+ datasets.SplitGenerator(
131
+ name=datasets.Split.TEST_4,
132
+ # These kwargs will be passed to _generate_examples
133
+ gen_kwargs={
134
+ "filepath": filepath_test_4,
135
+ "split": "test_4"
136
+ },
137
+ )
138
+ ]
139
+
140
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
141
+
142
+ def _generate_examples(self, filepath, split):
143
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
144
+ line_counter = 0
145
+ try:
146
+ with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
147
+ for id, line in enumerate(f):
148
+ line_counter += 1
149
+ if line:
150
+ data = json.loads(line)
151
+ if self.config.name == "full":
152
+ yield id, {
153
+ "id": data["id"],
154
+ "year": data["year"],
155
+ "label": data["label"],
156
+ "language": data["language"],
157
+ "region": data["region"],
158
+ "canton": data["canton"],
159
+ "legal_area": data["legal_area"],
160
+ "explainability_label": data["explainability_label"],
161
+ "occluded_text": data["occluded_text"],
162
+ "text": data["text"]
163
+
164
+ }
165
+ except lzma.LZMAError as e:
166
+ print(split, e)
167
+ if line_counter == 0:
168
+ raise e