File size: 5,665 Bytes
507bf63 14febf7 507bf63 14febf7 507bf63 14febf7 507bf63 14febf7 |
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 137 138 139 140 141 142 143 144 145 146 147 |
# 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:/invalsi_mate_data//huggingface.co/datasets/ai4text/Invalsi/tree/main/invalsi_mate_data",
"ita": "https://huggingface.co/datasets/ai4text/Invalsi/tree/main/invalsi_ita_data",
}
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)
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"],
}
|