# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # TODO: Address all TODOs and remove all explanatory comments import csv import json import os import datasets _CITATION = """\ @misc{esuli2024invalsi, title={The Invalsi Benchmark: measuring Language Models Mathematical and Language understanding in Italian}, author={Andrea Esuli and Giovanni Puccetti}, year={2024}, eprint={2403.18697}, archivePrefix={arXiv}, primaryClass={cs.CL} } """ _DESCRIPTION = """\ This new dataset is designed to measure Language Models mathematical and language understanding in Italian. """ _HOMEPAGE = "" _LICENSE = "CC BY 4.0" _URLS = { # "mate": "https://huggingface.co/datasets/ai4text/Invalsi/blob/main/invalsi_ita_data.zip", # "ita": "https://huggingface.co/datasets/ai4text/Invalsi/blob/main/invalsi_mate_data.zip", "mate": "./invalsi_mate_data/invalsi_mate_clean.csv", "ita": "./invalsi_ita_data/invalsi_ita_clean.csv", } class invalsi(datasets.GeneratorBasedBuilder): VERSION = datasets.Version("0.1.0") BUILDER_CONFIGS = [ datasets.BuilderConfig(name="mate", version=VERSION, description="Mathematical Understanding"), datasets.BuilderConfig(name="ita", version=VERSION, description="Italian Understanding"), ] DEFAULT_CONFIG_NAME = "mate" def _info(self): if self.config.name == "mate": features = datasets.Features( { "domanda": datasets.Value("string"), "risposta": datasets.Value("string"), "immagine": datasets.Value("string"), "test_id": datasets.Value("string"), } ) elif self.config.name == "ita": features = datasets.Features( { "testo": datasets.Value("string"), "domanda": datasets.Value("string"), "risposta": datasets.Value("string"), "immagine": datasets.Value("string"), "test_id": datasets.Value("string"), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files. # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive urls = _URLS[self.config.name] # data_dir = dl_manager.download_and_extract(urls) data_dir = "./" if self.config.name == "mate": data_file = "invalsi_mate_data/invalsi_mate_clean.csv" elif self.config.name == "ita": data_file = "invalsi_ita_data/invalsi_ita_clean.csv" return [ datasets.SplitGenerator( name=datasets.Split.VALIDATION, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(data_dir, data_file), "split": "val", }, ), ] def _generate_examples(self, filepath, split): ds = datasets.load_dataset("csv", data_files=filepath)["train"] for key, row in enumerate(ds): # data = json.loads(row) if self.config.name == "mate": # Yields examples as (key, example) tuples out = { # "domanda": datasets.Value("string"), # "risposta": datasets.Value("string"), # "immagine": datasets.Value("string"), # "test_id": datasets.Value("string"), "domanda": row["domanda"], "risposta": row["risposta"], "test_id": row["test_id"], } if "image_file_names" in row: out["immagine"] = row["image_file_names"] yield key, out elif self.config.name == "ita": yield key, { # "testo": datasets.Value("string"), # "domanda": datasets.Value("string"), # "risposta": datasets.Value("string"), # "immagine": datasets.Value("string"), # "test_id": datasets.Value("string"), "testo": row["testo"], "domanda": row["domanda"], "risposta": row["risposta"], "immagine": row["image_file_names"], "test_id": row["test_id"], }