File size: 4,865 Bytes
d6d432e 3c6e63e d6d432e 3c6e63e d6d432e |
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 |
import json
import datasets
logger = datasets.logging.get_logger(__name__)
# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@InProceedings{huggingface:dataset,
title = {A great new dataset},
author={huggingface, Inc.
},
year={2020}
}
"""
# TODO: Add description of the dataset here
# You can copy an official description
_DESCRIPTION = """\
SemEval 2023 Task LegalEval
"""
# TODO: Add a link to an official homepage for the dataset here
_HOMEPAGE = ""
# TODO: Add the licence for the dataset here if you can find it
_LICENSE = ""
# TODO: Add link to the official dataset URLs here
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
_URLS = ""
class LegalevalRrConfig(datasets.BuilderConfig):
"""BuilderConfig for Multiconer2"""
def __init__(self, **kwargs):
"""BuilderConfig for Multiconer2.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(LegalevalRrConfig, self).__init__(**kwargs)
class LegalevalRr(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
# This is an example of a dataset with multiple configurations.
# If you don't want/need to define several sub-sets in your dataset,
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
# If you need to make complex sub-parts in the datasets with configurable options
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
# BUILDER_CONFIG_CLASS = MyBuilderConfig
# You will be able to load one or the other configurations in the following list with
# data = datasets.load_dataset('my_dataset', 'first_domain')
# data = datasets.load_dataset('my_dataset', 'second_domain')
BUILDER_CONFIGS = [
LegalevalRrConfig(name="it", version=VERSION),
LegalevalRrConfig(name="cl", version=VERSION),
LegalevalRrConfig(name="all", version=VERSION),
]
DEFAULT_CONFIG_NAME = "all"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("uint32"),
"annotation_id": datasets.Value("string"),
"text": datasets.Value("string"),
"label":
datasets.features.ClassLabel(
names=[
'NONE',
"RPC",
"RATIO",
"PRE_NOT_RELIED",
"PRE_RELIED",
"STA",
"ANALYSIS",
"ARG_RESPONDENT",
"ARG_PETITIONER",
"ISSUE",
"RLC",
"FAC",
"PREAMBLE"]
)
}
),
supervised_keys=None,
homepage="",
citation=_CITATION,
)
def _split_generators(self, dl_manager: datasets.DownloadManager):
"""Returns SplitGenerators."""
downloaded_files = dl_manager.download_and_extract({
"train": "train.json",
"dev": "dev.json",
"test": "RR_TEST_DATA_FS.json"
})
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
]
def _generate_examples(self, filepath):
logger.info("⏳ Generating examples from = %s", filepath)
config_name = self.config.name
with open(filepath, encoding="utf-8") as f:
data = json.load(f)
cnt = 0
for row in data:
meta_group = row["meta"]["group"]
if config_name == "it" and meta_group != "Tax":
continue
if config_name == "cl" and meta_group != "Criminal":
continue
for annotation in row["annotations"][0]['result']:
yield cnt, {
"id": row["id"],
"annotation_id": annotation["id"],
"text": annotation["value"]["text"],
"label": annotation["value"]["labels"][0],
}
cnt += 1
|