|
import json |
|
|
|
import datasets |
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {A great new dataset}, |
|
author={huggingface, Inc. |
|
}, |
|
year={2020} |
|
} |
|
""" |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
SemEval 2023 Task LegalEval |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
|
|
_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") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|