Datasets:
rcds
/

Multilinguality:
multilingual
Size Categories:
10K<n<100K
Language Creators:
found
Annotations Creators:
found
Source Datasets:
original
ArXiv:
License:
File size: 7,122 Bytes
f11bf17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4aafe38
 
 
 
 
 
 
 
 
 
f11bf17
 
 
 
 
c990c74
f11bf17
 
 
 
c990c74
 
 
 
 
 
 
f11bf17
c990c74
f11bf17
 
c990c74
f11bf17
c990c74
f11bf17
 
 
 
 
 
c990c74
f11bf17
 
 
c990c74
f11bf17
 
 
 
 
 
 
 
 
c990c74
f11bf17
 
 
 
 
c990c74
f11bf17
 
 
 
 
c990c74
 
 
f11bf17
c990c74
 
 
 
 
 
 
f11bf17
 
 
 
 
 
 
 
 
 
 
 
 
c990c74
f11bf17
 
 
 
 
 
 
 
 
 
 
 
 
 
c990c74
f11bf17
 
c990c74
 
f11bf17
 
 
 
 
 
c990c74
f11bf17
 
c990c74
f11bf17
c990c74
f11bf17
 
c990c74
f11bf17
c990c74
f11bf17
 
 
c990c74
f11bf17
c990c74
f11bf17
 
 
c990c74
 
 
 
 
 
 
 
 
 
 
 
 
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
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Swiss-Court-Predict: A Multilingual Legal Judgment Prediction Benchmark"""

import json

import datasets


logger = datasets.logging.get_logger(__name__)

_CITATION = """\
@InProceedings{niklaus-etal-2021-swiss,
  author = {Niklaus, Joel
                and Chalkidis, Ilias
                and Stürmer, Matthias},
  title = {Swiss-Court-Predict: A Multilingual Legal Judgment Prediction Benchmark},
  booktitle = {Proceedings of the 2021 Natural Legal Language Processing Workshop},
  year = {2021},
  location = {Punta Cana, Dominican Republic},
}
@misc{niklaus2022empirical,
    title={An Empirical Study on Cross-X Transfer for Legal Judgment Prediction},
    author={Joel Niklaus and Matthias Stürmer and Ilias Chalkidis},
    year={2022},
    eprint={2209.12325},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}
"""

_DESCRIPTION = """
Swiss-Judgment-Prediction is a multilingual, diachronic dataset of 85K Swiss Federal Supreme Court (FSCS) cases annotated with the respective binarized judgment outcome (approval/dismissal), posing a challenging text classification task. We also provide additional metadata, i.e., the publication year, the legal area and the canton of origin per case, to promote robustness and fairness studies on the critical area of legal NLP.
"""

_ORIGINAL_LANGUAGES = [
    "de",
    "fr",
    "it",
]
_MT_LANGUAGES = [
    "mt_de",
    "mt_fr",
    "mt_it",
    "mt_en",
]
_LANGUAGES = _ORIGINAL_LANGUAGES + _MT_LANGUAGES

_URL = "https://zenodo.org/record/7109926/files/"
_URLS = {
    "train": _URL + "train.jsonl",
    "train_mt": _URL + "train_mt.jsonl",
    "val": _URL + "val.jsonl",
    "test": _URL + "test.jsonl",
}


class SwissJudgmentPredictionConfig(datasets.BuilderConfig):
    """BuilderConfig for SwissJudgmentPrediction."""

    def __init__(self, language: str, **kwargs):
        """BuilderConfig for SwissJudgmentPrediction.

        Args:
        language: One of de, fr, it, or all, or all+mt
          **kwargs: keyword arguments forwarded to super.
        """
        super(SwissJudgmentPredictionConfig, self).__init__(**kwargs)
        self.language = language


class SwissJudgmentPrediction(datasets.GeneratorBasedBuilder):
    """SwissJudgmentPrediction: A Multilingual Legal Judgment PredictionBenchmark"""

    VERSION = datasets.Version("2.0.0", "")
    BUILDER_CONFIG_CLASS = SwissJudgmentPredictionConfig
    BUILDER_CONFIGS = [
        SwissJudgmentPredictionConfig(
            name=lang,
            language=lang,
            version=datasets.Version("2.0.0", ""),
            description=f"Plain text import of SwissJudgmentPrediction for the {lang} language",
        )
        for lang in _LANGUAGES
    ] + [
        SwissJudgmentPredictionConfig(
            name="all",
            language="all",
            version=datasets.Version("2.0.0", ""),
            description="Plain text import of SwissJudgmentPrediction for all languages",
        ),
        SwissJudgmentPredictionConfig(
            name="all+mt",
            language="all+mt",
            version=datasets.Version("2.0.0", ""),
            description="Plain text import of SwissJudgmentPrediction for all languages with machine translation",
        ),
    ]

    def _info(self):
        features = datasets.Features(
            {
                "id": datasets.Value("int32"),
                "year": datasets.Value("int32"),
                "text": datasets.Value("string"),
                "label": datasets.ClassLabel(names=["dismissal", "approval"]),
                "language": datasets.Value("string"),
                "region": datasets.Value("string"),
                "canton": datasets.Value("string"),
                "legal area": datasets.Value("string"),
                "source_language": datasets.Value("string"),
            }
        )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            supervised_keys=None,
            homepage="https://github.com/JoelNiklaus/SwissCourtRulingCorpus",
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        # dl_manager is a datasets.download.DownloadManager that can be used to
        # download and extract URLs
        try:
            dl_dir = dl_manager.download(_URLS)
        except Exception:
            logger.warning(
                "This dataset is downloaded through Zenodo which is flaky. "
                "If this download failed try a few times before reporting an issue"
            )
            raise
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"filepath": dl_dir["train"], "mt_filepath": dl_dir["train_mt"]},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"filepath": dl_dir["val"], "mt_filepath": None},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"filepath": dl_dir["test"], "mt_filepath": None},
            ),
        ]

    def _generate_examples(self, filepath, mt_filepath):
        """This function returns the examples in the raw (text) form."""
        if self.config.language in ["all", "all+mt"] + _ORIGINAL_LANGUAGES:
            with open(filepath, encoding="utf-8") as f:
                for id_, row in enumerate(f):
                    data = json.loads(row)
                    _ = data.setdefault("source_language", "n/a")
                    if self.config.language in ["all", "all+mt"] or data["language"] == self.config.language:
                        yield id_, data
        if self.config.language in ["all+mt"] + _MT_LANGUAGES:
            if mt_filepath:  # yield data from mt_filepath
                with open(mt_filepath, encoding="utf-8") as f:
                    for id_, row in enumerate(f):
                        data = json.loads(row)
                        _ = data.setdefault("source_language", "n/a")
                        if (
                            self.config.language == "all+mt" or data["language"] in self.config.language
                        ):  # "de" in "mt_de"
                            yield f"mt_{id_}", data