File size: 5,475 Bytes
507bf63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3febd65
507bf63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c11dbe
 
4f492f1
 
507bf63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4254220
507bf63
144a86e
507bf63
 
 
dd1e8fe
a9343a1
 
 
507bf63
 
 
 
 
 
 
 
 
 
dd1e8fe
3febd65
 
 
507bf63
 
 
 
 
 
 
 
 
 
 
 
 
 
4f492f1
507bf63
14febf7
507bf63
14febf7
507bf63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144a86e
507bf63
 
 
dd1e8fe
a9343a1
 
3febd65
4254220
 
507bf63
 
 
 
 
 
 
 
 
 
dd1e8fe
3febd65
 
 
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
148
149
150
151
152
# 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"],
                }