|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""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}, |
|
}""" |
|
|
|
_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): |
|
|
|
|
|
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, |
|
|
|
gen_kwargs={"filepath": dl_dir["train"], "mt_filepath": dl_dir["train_mt"]}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={"filepath": dl_dir["val"], "mt_filepath": None}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
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: |
|
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 |
|
): |
|
yield f"mt_{id_}", data |
|
|