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