# 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.zip", "ita": "./invalsi_ita_data.zip", } 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( # TODO: add after the image col is there "immagine": datasets.Value("string"), { "testo": datasets.Value("string"), "domanda": datasets.Value("string"), "risposta": datasets.Value("string"), "test_id": datasets.Value("string"), "tipo": datasets.Value("string"), "alt1": datasets.Value("string"), "alt2": datasets.Value("string"), "alt3": 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"), "tipo": datasets.Value("string"), "alt1": datasets.Value("string"), "alt2": datasets.Value("string"), "alt3": datasets.Value("string"), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): urls = _URLS[self.config.name] data_dir = dl_manager.extract(urls) 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 = { "testo": row["testo"], "domanda": row["domanda"], "risposta": row["risposta"], "test_id": row["test_id"], "tipo": row["tipo"], "alt1": row["alt1"], "alt2": row["alt2"], "alt3": row["alt3"], # TODO: add after the image col is there "immagine": datasets.Value("string"), # "immagine": row["image_file_names"], } yield key, out elif self.config.name == "ita": yield key, { "testo": row["testo"], "domanda": row["domanda"], "risposta": row["risposta"], "immagine": row["image_file_names"], "test_id": row["test_id"], "tipo": row["tipo"], "alt1": row["alt1"], "alt2": row["alt2"], "alt3": row["alt3"], }