Datasets:
Sub-tasks:
masked-language-modeling
Languages:
English
Multilinguality:
monolingual
Size Categories:
1K<n<10K
Language Creators:
found
Annotations Creators:
no-annotation
Source Datasets:
extended
ArXiv:
License:
# 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. | |
"""LegalLAMA: Legal LAnguage Model Analysis (LAMA) (LAMA) dataset.""" | |
import json | |
import os | |
import datasets | |
MAIN_CITATION = """ | |
@inproceedings{chalkidis-garneau-etal-2023-lexlms, | |
title = {{LeXFiles and LegalLAMA: Facilitating English Multinational Legal Language Model Development}}, | |
author = "Chalkidis*, Ilias and | |
Garneau*, Nicolas and | |
Goanta, Catalina and | |
Katz, Daniel Martin and | |
Søgaard, Anders", | |
booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics", | |
month = july, | |
year = "2023", | |
address = "Toronto, Canada", | |
publisher = "Association for Computational Linguistics", | |
url = "https://aclanthology.org/xxx", | |
} | |
""" | |
_DESCRIPTION = """LegalLAMA: Legal LAnguage Model Analysis (LAMA) (LAMA) dataset.""" | |
MAIN_PATH = 'https://huggingface.co/datasets/lexlms/legal_lama/resolve/main' | |
class LegalLAMAConfig(datasets.BuilderConfig): | |
"""BuilderConfig for XAI - Fairness.""" | |
def __init__( | |
self, | |
data_url, | |
**kwargs, | |
): | |
"""BuilderConfig for LegalLAMA. | |
Args: | |
data_url: `string`, url to download the zip file from | |
**kwargs: keyword arguments forwarded to super. | |
""" | |
super(LegalLAMAConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs) | |
self.data_url = data_url | |
class LegalLAMA(datasets.GeneratorBasedBuilder): | |
"""LegalLAMA: A multilingual benchmark for evaluating fairness in legal text processing. Version 1.0""" | |
BUILDER_CONFIGS = [ | |
LegalLAMAConfig( | |
name="canadian_crimes", | |
data_url=os.path.join(MAIN_PATH, "canadian_crimes.jsonl"), | |
), | |
LegalLAMAConfig( | |
name="canadian_sections", | |
data_url=os.path.join(MAIN_PATH, "canadian_sections.jsonl"), | |
), | |
LegalLAMAConfig( | |
name="cjeu_terms", | |
data_url=os.path.join(MAIN_PATH, "cjeu_terms.jsonl"), | |
), | |
LegalLAMAConfig( | |
name="ecthr_terms", | |
data_url=os.path.join(MAIN_PATH, "ecthr_terms.jsonl"), | |
), | |
LegalLAMAConfig( | |
name="ecthr_articles", | |
data_url=os.path.join(MAIN_PATH, "ecthr_articles.jsonl"), | |
), | |
LegalLAMAConfig( | |
name="us_crimes", | |
data_url=os.path.join(MAIN_PATH, "us_crimes.jsonl"), | |
), | |
LegalLAMAConfig( | |
name="us_terms", | |
data_url=os.path.join(MAIN_PATH, "us_terms.jsonl"), | |
), | |
LegalLAMAConfig( | |
name="contract_types", | |
data_url=os.path.join(MAIN_PATH, "contract_types.jsonl"), | |
), | |
LegalLAMAConfig( | |
name="contract_sections", | |
data_url=os.path.join(MAIN_PATH, "contract_sections.jsonl"), | |
), | |
] | |
def _info(self): | |
features = {"text": datasets.Value("string"), "label": datasets.Value("string"), "category": datasets.Value("string")} | |
return datasets.DatasetInfo( | |
description=self.config.description, | |
features=datasets.Features(features), | |
homepage="https://huggingface.co/datasets/lexlms/legal_lama", | |
citation=MAIN_CITATION, | |
) | |
def _split_generators(self, dl_manager): | |
data_dir = dl_manager.download(self.config.data_url) | |
return [ | |
datasets.SplitGenerator( | |
name=datasets.Split.TEST, | |
# These kwargs will be passed to _generate_examples | |
gen_kwargs={ | |
"filepath": data_dir, | |
"split": "test", | |
}, | |
), | |
] | |
def _get_category(self, sample): | |
if 'canadian_article' in sample: | |
category = sample['canadian_article'] | |
elif 'legal_topic' in sample: | |
category = sample['legal_topic'] | |
elif 'echr_article' in sample: | |
category = sample['echr_article'] | |
else: | |
category = sample['obj_label'] | |
return category | |
def _generate_examples(self, filepath, split): | |
"""This function returns the examples in the raw (text) form.""" | |
with open(filepath, encoding="utf-8") as f: | |
for id_, row in enumerate(f): | |
data = json.loads(row) | |
example = { | |
"text": data["masked_sentences"][0], | |
"label": data["obj_label"], | |
"category": self._get_category(data) | |
} | |
yield id_, example |