Aashraya Sachdeva
commited on
Commit
•
d6d432e
1
Parent(s):
5a0b8a1
add base file
Browse files- legaleval_rr.py +133 -0
legaleval_rr.py
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
import datasets
|
4 |
+
|
5 |
+
logger = datasets.logging.get_logger(__name__)
|
6 |
+
|
7 |
+
# TODO: Add BibTeX citation
|
8 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
9 |
+
_CITATION = """\
|
10 |
+
@InProceedings{huggingface:dataset,
|
11 |
+
title = {A great new dataset},
|
12 |
+
author={huggingface, Inc.
|
13 |
+
},
|
14 |
+
year={2020}
|
15 |
+
}
|
16 |
+
"""
|
17 |
+
|
18 |
+
# TODO: Add description of the dataset here
|
19 |
+
# You can copy an official description
|
20 |
+
_DESCRIPTION = """\
|
21 |
+
SemEval 2023 Task LegalEval
|
22 |
+
"""
|
23 |
+
|
24 |
+
# TODO: Add a link to an official homepage for the dataset here
|
25 |
+
_HOMEPAGE = ""
|
26 |
+
|
27 |
+
# TODO: Add the licence for the dataset here if you can find it
|
28 |
+
_LICENSE = ""
|
29 |
+
|
30 |
+
# TODO: Add link to the official dataset URLs here
|
31 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
32 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
33 |
+
_URLS = ""
|
34 |
+
|
35 |
+
|
36 |
+
class LegalevalRrConfig(datasets.BuilderConfig):
|
37 |
+
"""BuilderConfig for Multiconer2"""
|
38 |
+
|
39 |
+
def __init__(self, **kwargs):
|
40 |
+
"""BuilderConfig for Multiconer2.
|
41 |
+
Args:
|
42 |
+
**kwargs: keyword arguments forwarded to super.
|
43 |
+
"""
|
44 |
+
super(LegalevalRrConfig, self).__init__(**kwargs)
|
45 |
+
|
46 |
+
|
47 |
+
class LegalevalRr(datasets.GeneratorBasedBuilder):
|
48 |
+
VERSION = datasets.Version("1.0.0")
|
49 |
+
|
50 |
+
# This is an example of a dataset with multiple configurations.
|
51 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
52 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
53 |
+
|
54 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
55 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
56 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
57 |
+
|
58 |
+
# You will be able to load one or the other configurations in the following list with
|
59 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
60 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
61 |
+
BUILDER_CONFIGS = [
|
62 |
+
LegalevalRrConfig(name="it", version=VERSION),
|
63 |
+
LegalevalRrConfig(name="cl", version=VERSION),
|
64 |
+
LegalevalRrConfig(name="all", version=VERSION),
|
65 |
+
]
|
66 |
+
|
67 |
+
DEFAULT_CONFIG_NAME = "all"
|
68 |
+
|
69 |
+
def _info(self):
|
70 |
+
return datasets.DatasetInfo(
|
71 |
+
description=_DESCRIPTION,
|
72 |
+
features=datasets.Features(
|
73 |
+
{
|
74 |
+
"id": datasets.Value("uint32"),
|
75 |
+
"annotation_id": datasets.Value("string"),
|
76 |
+
"text": datasets.Value("string"),
|
77 |
+
"label":
|
78 |
+
datasets.features.ClassLabel(
|
79 |
+
names=[
|
80 |
+
'NONE',
|
81 |
+
"RPC",
|
82 |
+
"RATIO",
|
83 |
+
"PRE_NOT_RELIED",
|
84 |
+
"PRE_RELIED",
|
85 |
+
"STA",
|
86 |
+
"ANALYSIS",
|
87 |
+
"ARG_RESPONDENT",
|
88 |
+
"ARG_PETITIONER",
|
89 |
+
"ISSUE",
|
90 |
+
"RLC",
|
91 |
+
"FAC",
|
92 |
+
"PREAMBLE"]
|
93 |
+
)
|
94 |
+
}
|
95 |
+
),
|
96 |
+
supervised_keys=None,
|
97 |
+
homepage="",
|
98 |
+
citation=_CITATION,
|
99 |
+
)
|
100 |
+
|
101 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
102 |
+
"""Returns SplitGenerators."""
|
103 |
+
|
104 |
+
downloaded_files = dl_manager.download_and_extract({
|
105 |
+
"train": "train.json",
|
106 |
+
"dev": "dev.json",
|
107 |
+
})
|
108 |
+
|
109 |
+
return [
|
110 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
111 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
112 |
+
]
|
113 |
+
|
114 |
+
def _generate_examples(self, filepath):
|
115 |
+
logger.info("⏳ Generating examples from = %s", filepath)
|
116 |
+
config_name = self.config.name
|
117 |
+
with open(filepath, encoding="utf-8") as f:
|
118 |
+
data = json.load(f)
|
119 |
+
cnt = 0
|
120 |
+
for row in data:
|
121 |
+
meta_group = row["meta"]["group"]
|
122 |
+
if config_name == "it" and meta_group != "Tax":
|
123 |
+
continue
|
124 |
+
if config_name == "cl" and meta_group != "Criminal":
|
125 |
+
continue
|
126 |
+
for annotation in row["annotations"][0]['result']:
|
127 |
+
yield cnt, {
|
128 |
+
"id": row["id"],
|
129 |
+
"annotation_id": annotation["id"],
|
130 |
+
"text": annotation["value"]["text"],
|
131 |
+
"label": annotation["value"]["labels"][0],
|
132 |
+
}
|
133 |
+
cnt += 1
|