rename
Browse files- invalsi.py → Invalsi.py +45 -80
invalsi.py → Invalsi.py
RENAMED
|
@@ -12,7 +12,6 @@
|
|
| 12 |
# See the License for the specific language governing permissions and
|
| 13 |
# limitations under the License.
|
| 14 |
# TODO: Address all TODOs and remove all explanatory comments
|
| 15 |
-
"""TODO: Add a description here."""
|
| 16 |
|
| 17 |
|
| 18 |
import csv
|
|
@@ -22,8 +21,6 @@ import os
|
|
| 22 |
import datasets
|
| 23 |
|
| 24 |
|
| 25 |
-
# TODO: Add BibTeX citation
|
| 26 |
-
# Find for instance the citation on arxiv or on the dataset repo/website
|
| 27 |
_CITATION = """\
|
| 28 |
@misc{esuli2024invalsi,
|
| 29 |
title={The Invalsi Benchmark: measuring Language Models Mathematical and Language understanding in Italian},
|
|
@@ -35,54 +32,34 @@ _CITATION = """\
|
|
| 35 |
}
|
| 36 |
"""
|
| 37 |
|
| 38 |
-
# TODO: Add description of the dataset here
|
| 39 |
-
# You can copy an official description
|
| 40 |
_DESCRIPTION = """\
|
| 41 |
This new dataset is designed to measure Language Models mathematical and language understanding in Italian.
|
| 42 |
"""
|
| 43 |
|
| 44 |
-
# TODO: Add a link to an official homepage for the dataset here
|
| 45 |
_HOMEPAGE = ""
|
| 46 |
|
| 47 |
-
# TODO: Add the licence for the dataset here if you can find it
|
| 48 |
_LICENSE = "CC BY 4.0"
|
| 49 |
|
| 50 |
-
|
| 51 |
-
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
| 52 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
| 53 |
_URLS = {
|
| 54 |
-
"mate": "https
|
| 55 |
"ita": "https://huggingface.co/datasets/ai4text/Invalsi/tree/main/invalsi_ita_data",
|
| 56 |
}
|
| 57 |
|
| 58 |
|
| 59 |
-
|
| 60 |
-
class Invalsi(datasets.GeneratorBasedBuilder):
|
| 61 |
-
"""TODO: Short description of my dataset."""
|
| 62 |
-
|
| 63 |
-
VERSION = datasets.Version("0.1")
|
| 64 |
|
| 65 |
-
|
| 66 |
-
# If you don't want/need to define several sub-sets in your dataset,
|
| 67 |
-
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
| 68 |
|
| 69 |
-
# If you need to make complex sub-parts in the datasets with configurable options
|
| 70 |
-
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
| 71 |
-
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
| 72 |
-
|
| 73 |
-
# You will be able to load one or the other configurations in the following list with
|
| 74 |
-
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
| 75 |
-
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
| 76 |
BUILDER_CONFIGS = [
|
| 77 |
datasets.BuilderConfig(name="mate", version=VERSION, description="Mathematical Understanding"),
|
| 78 |
datasets.BuilderConfig(name="ita", version=VERSION, description="Italian Understanding"),
|
| 79 |
]
|
| 80 |
|
| 81 |
-
|
| 82 |
|
| 83 |
def _info(self):
|
| 84 |
-
|
| 85 |
-
if self.config.name == "mate": # This is the name of the configuration selected in BUILDER_CONFIGS above
|
| 86 |
features = datasets.Features(
|
| 87 |
{
|
| 88 |
"domanda": datasets.Value("string"),
|
|
@@ -91,7 +68,7 @@ class Invalsi(datasets.GeneratorBasedBuilder):
|
|
| 91 |
"test_id": datasets.Value("string"),
|
| 92 |
}
|
| 93 |
)
|
| 94 |
-
elif self.config.name == "ita":
|
| 95 |
features = datasets.Features(
|
| 96 |
{
|
| 97 |
"testo": datasets.Value("string"),
|
|
@@ -101,19 +78,12 @@ class Invalsi(datasets.GeneratorBasedBuilder):
|
|
| 101 |
"test_id": datasets.Value("string"),
|
| 102 |
}
|
| 103 |
)
|
|
|
|
| 104 |
return datasets.DatasetInfo(
|
| 105 |
-
# This is the description that will appear on the datasets page.
|
| 106 |
description=_DESCRIPTION,
|
| 107 |
-
|
| 108 |
-
features=features, # Here we define them above because they are different between the two configurations
|
| 109 |
-
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
| 110 |
-
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
| 111 |
-
# supervised_keys=("sentence", "label"),
|
| 112 |
-
# Homepage of the dataset for documentation
|
| 113 |
homepage=_HOMEPAGE,
|
| 114 |
-
# License for the dataset if available
|
| 115 |
license=_LICENSE,
|
| 116 |
-
# Citation for the dataset
|
| 117 |
citation=_CITATION,
|
| 118 |
)
|
| 119 |
|
|
@@ -125,20 +95,13 @@ class Invalsi(datasets.GeneratorBasedBuilder):
|
|
| 125 |
# 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.
|
| 126 |
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 127 |
urls = _URLS[self.config.name]
|
| 128 |
-
data_dir = dl_manager.download_and_extract(urls)
|
|
|
|
| 129 |
if self.config.name == "mate":
|
| 130 |
-
data_file = "invalsi_mate_clean.csv"
|
| 131 |
elif self.config.name == "ita":
|
| 132 |
-
data_file = "invalsi_ita_clean.csv"
|
| 133 |
return [
|
| 134 |
-
# datasets.SplitGenerator(
|
| 135 |
-
# name=datasets.Split.TRAIN,
|
| 136 |
-
# # These kwargs will be passed to _generate_examples
|
| 137 |
-
# gen_kwargs={
|
| 138 |
-
# "filepath": os.path.join(data_dir, "train.jsonl"),
|
| 139 |
-
# "split": "train",
|
| 140 |
-
# },
|
| 141 |
-
# ),
|
| 142 |
datasets.SplitGenerator(
|
| 143 |
name=datasets.Split.VALIDATION,
|
| 144 |
# These kwargs will be passed to _generate_examples
|
|
@@ -147,36 +110,38 @@ class Invalsi(datasets.GeneratorBasedBuilder):
|
|
| 147 |
"split": "val",
|
| 148 |
},
|
| 149 |
),
|
| 150 |
-
# datasets.SplitGenerator(
|
| 151 |
-
# name=datasets.Split.TEST,
|
| 152 |
-
# # These kwargs will be passed to _generate_examples
|
| 153 |
-
# gen_kwargs={
|
| 154 |
-
# "filepath": os.path.join(data_dir, "test.jsonl"),
|
| 155 |
-
# "split": "test"
|
| 156 |
-
# },
|
| 157 |
-
# ),
|
| 158 |
]
|
| 159 |
|
| 160 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
| 161 |
def _generate_examples(self, filepath, split):
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
#
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# See the License for the specific language governing permissions and
|
| 13 |
# limitations under the License.
|
| 14 |
# TODO: Address all TODOs and remove all explanatory comments
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
import csv
|
|
|
|
| 21 |
import datasets
|
| 22 |
|
| 23 |
|
|
|
|
|
|
|
| 24 |
_CITATION = """\
|
| 25 |
@misc{esuli2024invalsi,
|
| 26 |
title={The Invalsi Benchmark: measuring Language Models Mathematical and Language understanding in Italian},
|
|
|
|
| 32 |
}
|
| 33 |
"""
|
| 34 |
|
|
|
|
|
|
|
| 35 |
_DESCRIPTION = """\
|
| 36 |
This new dataset is designed to measure Language Models mathematical and language understanding in Italian.
|
| 37 |
"""
|
| 38 |
|
|
|
|
| 39 |
_HOMEPAGE = ""
|
| 40 |
|
|
|
|
| 41 |
_LICENSE = "CC BY 4.0"
|
| 42 |
|
| 43 |
+
|
|
|
|
|
|
|
| 44 |
_URLS = {
|
| 45 |
+
"mate": "https:/invalsi_mate_data//huggingface.co/datasets/ai4text/Invalsi/tree/main/invalsi_mate_data",
|
| 46 |
"ita": "https://huggingface.co/datasets/ai4text/Invalsi/tree/main/invalsi_ita_data",
|
| 47 |
}
|
| 48 |
|
| 49 |
|
| 50 |
+
class invalsi(datasets.GeneratorBasedBuilder):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
VERSION = datasets.Version("0.1.0")
|
|
|
|
|
|
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
BUILDER_CONFIGS = [
|
| 55 |
datasets.BuilderConfig(name="mate", version=VERSION, description="Mathematical Understanding"),
|
| 56 |
datasets.BuilderConfig(name="ita", version=VERSION, description="Italian Understanding"),
|
| 57 |
]
|
| 58 |
|
| 59 |
+
DEFAULT_CONFIG_NAME = "mate"
|
| 60 |
|
| 61 |
def _info(self):
|
| 62 |
+
if self.config.name == "mate":
|
|
|
|
| 63 |
features = datasets.Features(
|
| 64 |
{
|
| 65 |
"domanda": datasets.Value("string"),
|
|
|
|
| 68 |
"test_id": datasets.Value("string"),
|
| 69 |
}
|
| 70 |
)
|
| 71 |
+
elif self.config.name == "ita":
|
| 72 |
features = datasets.Features(
|
| 73 |
{
|
| 74 |
"testo": datasets.Value("string"),
|
|
|
|
| 78 |
"test_id": datasets.Value("string"),
|
| 79 |
}
|
| 80 |
)
|
| 81 |
+
|
| 82 |
return datasets.DatasetInfo(
|
|
|
|
| 83 |
description=_DESCRIPTION,
|
| 84 |
+
features=features,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
homepage=_HOMEPAGE,
|
|
|
|
| 86 |
license=_LICENSE,
|
|
|
|
| 87 |
citation=_CITATION,
|
| 88 |
)
|
| 89 |
|
|
|
|
| 95 |
# 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.
|
| 96 |
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 97 |
urls = _URLS[self.config.name]
|
| 98 |
+
# data_dir = dl_manager.download_and_extract(urls)
|
| 99 |
+
data_dir = "."
|
| 100 |
if self.config.name == "mate":
|
| 101 |
+
data_file = "Invalsi/invalsi_mate_data/invalsi_mate_clean.csv"
|
| 102 |
elif self.config.name == "ita":
|
| 103 |
+
data_file = "Invalsi/invalsi_ita_data/invalsi_ita_clean.csv"
|
| 104 |
return [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
datasets.SplitGenerator(
|
| 106 |
name=datasets.Split.VALIDATION,
|
| 107 |
# These kwargs will be passed to _generate_examples
|
|
|
|
| 110 |
"split": "val",
|
| 111 |
},
|
| 112 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
]
|
| 114 |
|
|
|
|
| 115 |
def _generate_examples(self, filepath, split):
|
| 116 |
+
ds = datasets.load_dataset("csv", data_files=filepath)["train"]
|
| 117 |
+
for key, row in enumerate(ds):
|
| 118 |
+
# data = json.loads(row)
|
| 119 |
+
if self.config.name == "mate":
|
| 120 |
+
# Yields examples as (key, example) tuples
|
| 121 |
+
out = {
|
| 122 |
+
# "domanda": datasets.Value("string"),
|
| 123 |
+
# "risposta": datasets.Value("string"),
|
| 124 |
+
# "immagine": datasets.Value("string"),
|
| 125 |
+
# "test_id": datasets.Value("string"),
|
| 126 |
+
"domanda": row["domanda"],
|
| 127 |
+
"risposta": row["risposta"],
|
| 128 |
+
|
| 129 |
+
"test_id": row["test_id"],
|
| 130 |
+
}
|
| 131 |
+
if "image_file_names" in row:
|
| 132 |
+
out["immagine"] = row["image_file_names"]
|
| 133 |
+
|
| 134 |
+
yield key, out
|
| 135 |
+
elif self.config.name == "ita":
|
| 136 |
+
yield key, {
|
| 137 |
+
# "testo": datasets.Value("string"),
|
| 138 |
+
# "domanda": datasets.Value("string"),
|
| 139 |
+
# "risposta": datasets.Value("string"),
|
| 140 |
+
# "immagine": datasets.Value("string"),
|
| 141 |
+
# "test_id": datasets.Value("string"),
|
| 142 |
+
"testo": row["testo"],
|
| 143 |
+
"domanda": row["domanda"],
|
| 144 |
+
"risposta": row["risposta"],
|
| 145 |
+
"immagine": row["image_file_names"],
|
| 146 |
+
"test_id": row["test_id"],
|
| 147 |
+
}
|