Datasets:

Languages:
English
ArXiv:
License:
kiddothe2b commited on
Commit
42b7615
·
1 Parent(s): d2da575

Create legal_lama.py

Browse files
Files changed (1) hide show
  1. legal_lama.py +134 -0
legal_lama.py ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """LegalLAMA: Legal LAnguage Model Analysis (LAMA) (LAMA) dataset."""
16
+
17
+ import json
18
+ import os
19
+ import datasets
20
+
21
+
22
+ MAIN_CITATION = """
23
+ @inproceedings{chalkidis-garneau-etal-2023-lexlms,
24
+ title = {{LeXFiles and LegalLAMA: Facilitating English Multinational Legal Language Model Development}},
25
+ author = "Chalkidis*, Ilias and
26
+ Garneau*, Nicolas and
27
+ Goanta, Catalina and
28
+ Katz, Daniel Martin and
29
+ Søgaard, Anders",
30
+ booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics",
31
+ month = july,
32
+ year = "2023",
33
+ address = "Toronto, Canada",
34
+ publisher = "Association for Computational Linguistics",
35
+ url = "https://aclanthology.org/xxx",
36
+ }
37
+ """
38
+
39
+ _DESCRIPTION = """LegalLAMA: Legal LAnguage Model Analysis (LAMA) (LAMA) dataset."""
40
+ MAIN_PATH = 'https://huggingface.co/datasets/lexlms/legal_lama/resolve/main'
41
+
42
+
43
+ class LegalLAMAConfig(datasets.BuilderConfig):
44
+ """BuilderConfig for XAI - Fairness."""
45
+
46
+ def __init__(
47
+ self,
48
+ data_url,
49
+ **kwargs,
50
+ ):
51
+ """BuilderConfig for LegalLAMA.
52
+
53
+ Args:
54
+ data_url: `string`, url to download the zip file from
55
+ **kwargs: keyword arguments forwarded to super.
56
+ """
57
+ super(LegalLAMAConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
58
+ self.data_url = data_url
59
+
60
+
61
+ class LegalLAMA(datasets.GeneratorBasedBuilder):
62
+ """LegalLAMA: A multilingual benchmark for evaluating fairness in legal text processing. Version 1.0"""
63
+
64
+ BUILDER_CONFIGS = [
65
+ LegalLAMAConfig(
66
+ name="canadian_crimes",
67
+ data_url=os.path.join(MAIN_PATH, "canadian_crimes.jsonl"),
68
+ ),
69
+ LegalLAMAConfig(
70
+ name="canadian_sections",
71
+ data_url=os.path.join(MAIN_PATH, "canadian_sections.jsonl"),
72
+ ),
73
+ LegalLAMAConfig(
74
+ name="cjeu_terms",
75
+ data_url=os.path.join(MAIN_PATH, "cjeu_terms.jsonl"),
76
+ ),
77
+ LegalLAMAConfig(
78
+ name="ecthr_terms",
79
+ data_url=os.path.join(MAIN_PATH, "ecthr_terms.jsonl"),
80
+ ),
81
+ LegalLAMAConfig(
82
+ name="ecthr_articles",
83
+ data_url=os.path.join(MAIN_PATH, "ecthr_articles.jsonl"),
84
+ ),
85
+ LegalLAMAConfig(
86
+ name="us_crimes",
87
+ data_url=os.path.join(MAIN_PATH, "us_crimes.jsonl"),
88
+ ),
89
+ LegalLAMAConfig(
90
+ name="us_terms",
91
+ data_url=os.path.join(MAIN_PATH, "us_terms.jsonl"),
92
+ ),
93
+ LegalLAMAConfig(
94
+ name="contract_types",
95
+ data_url=os.path.join(MAIN_PATH, "contract_types.jsonl"),
96
+ ),
97
+ LegalLAMAConfig(
98
+ name="contract_sections",
99
+ data_url=os.path.join(MAIN_PATH, "contract_sections.jsonl"),
100
+ ),
101
+ ]
102
+
103
+ def _info(self):
104
+ features = {"text": datasets.Value("string"), "label": datasets.Value("string")}
105
+ return datasets.DatasetInfo(
106
+ description=self.config.description,
107
+ features=datasets.Features(features),
108
+ homepage="https://huggingface.co/datasets/lexlms/legal_lama",
109
+ citation=MAIN_CITATION,
110
+ )
111
+
112
+ def _split_generators(self, dl_manager):
113
+ data_dir = dl_manager.download(self.config.data_url)
114
+ return [
115
+ datasets.SplitGenerator(
116
+ name=datasets.Split.TEST,
117
+ # These kwargs will be passed to _generate_examples
118
+ gen_kwargs={
119
+ "filepath": data_dir,
120
+ "split": "test",
121
+ },
122
+ ),
123
+ ]
124
+
125
+ def _generate_examples(self, filepath, split):
126
+ """This function returns the examples in the raw (text) form."""
127
+ with open(filepath, encoding="utf-8") as f:
128
+ for id_, row in enumerate(f):
129
+ data = json.loads(row)
130
+ example = {
131
+ "text": data["masked_sentences"][0],
132
+ "label": data["obj_label"],
133
+ }
134
+ yield id_, example