Datasets:

Languages:
English
Multilinguality:
monolingual
Size Categories:
1K<n<10K
Language Creators:
found
Annotations Creators:
no-annotation
Source Datasets:
extended
ArXiv:
License:
File size: 5,213 Bytes
42b7615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
831b124
42b7615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464765c
 
 
 
 
 
 
 
 
 
 
42b7615
 
 
 
 
 
 
 
464765c
42b7615
 
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
# 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