# 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. """Dataset for the Lower Court Insertion task.""" import json import datasets logger = datasets.logging.get_logger(__name__) try: import lzma as xz except ImportError: import pylzma as xz # TODO: Add final BibTeX citation # Find for instance the citation on arxiv or on the dataset repo/website _CITATION = """\ @misc{baumgartner_nina_occlusion_2022, title = {From Occlusion to Transparancy – An Occlusion-Based Explainability Approach for Legal Judgment Prediction in Switzerland}, shorttitle = {From Occlusion to Transparancy}, 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.}, author = {{Baumgartner, Nina}}, year = {2022}, langid = {english} } """ # You can copy an official description _DESCRIPTION = """\ This dataset contains an implementation of lower court insertion for the SwissJudgmentPrediction task. """ _LICENSE = "cc-by-sa-4.0" _LANGUAGES = [ "de", "fr", "it", ] _URL = "https://huggingface.co/datasets/rcds/lower_court_insertion_swiss_judgment_prediction/resolve/main/data/" _URLS = { "test": _URL + "lci_test.jsonl" } class LowerCourtInsertionSwissJudgmentPredictionConfig(datasets.BuilderConfig): """BuilderConfig for LowerCourtInsertionSwissJudgmentPrediction.""" def __init__(self, language: str, **kwargs): """BuilderConfig for LowerCourtInsertionSwissJudgmentPrediction. Args: language: One of de, fr, it, or all **kwargs: keyword arguments forwarded to super. """ super(LowerCourtInsertionSwissJudgmentPredictionConfig, self).__init__(**kwargs) self.language = language class LowerCourtInsertionSwissJudgmentPrediction(datasets.GeneratorBasedBuilder): """This dataset contains court decision for the lower court insertion task in swiss judgment prediction""" VERSION = datasets.Version("1.1.0") BUILDER_CONFIG_CLASS = LowerCourtInsertionSwissJudgmentPredictionConfig BUILDER_CONFIGS = [ LowerCourtInsertionSwissJudgmentPredictionConfig( name=lang, language=lang, version=datasets.Version("1.1.0", ""), description=f"Plain text import of OcclusionSwissJudgmentPrediction for the {lang} language", ) for lang in _LANGUAGES ] + [ LowerCourtInsertionSwissJudgmentPredictionConfig( name="all", language="all", version=datasets.Version("1.1.0", ""), description="Plain text import of OcclusionSwissJudgmentPrediction for all languages", ) ] def _info(self): features = datasets.Features( { "id": datasets.Value("int32"), "year": datasets.Value("int32"), "label": datasets.Value("string"), "language": datasets.Value("string"), "region": datasets.Value("string"), "canton": datasets.Value("string"), "legal_area": datasets.Value("string"), "explainability_label": datasets.Value("string"), "lower_court": datasets.Value("string"), "text": datasets.Value("string") } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, supervised_keys=None, homepage="https://github.com/ninabaumgartner/SwissCourtRulingCorpus", license=_LICENSE, 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( "If this download failed try a few times before reporting an issue" ) raise return [ datasets.SplitGenerator( name="test", # These kwargs will be passed to _generate_examples gen_kwargs={"filepath": dl_dir["test"]}, ), ] def _generate_examples(self, filepath): """This function returns the examples in the raw (text) form.""" if self.config.language in ["all"] + _LANGUAGES: with open(filepath, encoding="utf-8") as f: for id_, row in enumerate(f): data = json.loads(row) _ = data.setdefault("language", "n/a") if self.config.language in ["all"] or data["language"] == self.config.language: yield id_, data