Upload aya_evaluation_suite.py with huggingface_hub
Browse files- aya_evaluation_suite.py +147 -0
aya_evaluation_suite.py
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from typing import Dict, List, Tuple
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
from seacrowd.utils import schemas
|
8 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
9 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
10 |
+
|
11 |
+
_CITATION = """
|
12 |
+
@misc{singh2024aya,
|
13 |
+
title={Aya Dataset: An Open-Access Collection for Multilingual Instruction Tuning},
|
14 |
+
author={Shivalika Singh and Freddie Vargus and Daniel Dsouza and Börje F. Karlsson and
|
15 |
+
Abinaya Mahendiran and Wei-Yin Ko and Herumb Shandilya and Jay Patel and Deividas
|
16 |
+
Mataciunas and Laura OMahony and Mike Zhang and Ramith Hettiarachchi and Joseph
|
17 |
+
Wilson and Marina Machado and Luisa Souza Moura and Dominik Krzemiński and Hakimeh
|
18 |
+
Fadaei and Irem Ergün and Ifeoma Okoh and Aisha Alaagib and Oshan Mudannayake and
|
19 |
+
Zaid Alyafeai and Vu Minh Chien and Sebastian Ruder and Surya Guthikonda and Emad A.
|
20 |
+
Alghamdi and Sebastian Gehrmann and Niklas Muennighoff and Max Bartolo and Julia Kreutzer
|
21 |
+
and Ahmet Üstün and Marzieh Fadaee and Sara Hooker},
|
22 |
+
year={2024},
|
23 |
+
eprint={2402.06619},
|
24 |
+
archivePrefix={arXiv},
|
25 |
+
primaryClass={cs.CL}
|
26 |
+
}
|
27 |
+
"""
|
28 |
+
|
29 |
+
_DATASETNAME = "aya_evaluation_suite"
|
30 |
+
|
31 |
+
_DESCRIPTION = """
|
32 |
+
Aya Evaluation Suite contains a total of 26,750 open-ended conversation-style
|
33 |
+
prompts to evaluate multilingual open-ended generation quality.
|
34 |
+
"""
|
35 |
+
|
36 |
+
_HOMEPAGE = "https://huggingface.co/datasets/CohereForAI/aya_evaluation_suite"
|
37 |
+
|
38 |
+
_LANGUAGES = ["ceb", "tha", "mya", "zsm", "jav", "ind", "vie", "sun", "ace", "bjn", "khm", "lao", "min"]
|
39 |
+
|
40 |
+
_LICENSE = Licenses.APACHE_2_0.value
|
41 |
+
|
42 |
+
_LOCAL = False
|
43 |
+
|
44 |
+
_URLS = {
|
45 |
+
_DATASETNAME: "https://huggingface.co/datasets/CohereForAI/aya_evaluation_suite/resolve/main/dolly_machine_translated/test-00000-of-00001.parquet?download=true",
|
46 |
+
}
|
47 |
+
|
48 |
+
_SUPPORTED_TASKS = [Tasks.INSTRUCTION_TUNING]
|
49 |
+
|
50 |
+
_SOURCE_VERSION = "1.0.0"
|
51 |
+
|
52 |
+
_SEACROWD_VERSION = "2024.06.20"
|
53 |
+
|
54 |
+
|
55 |
+
class AyaEvaluationSuiteDataset(datasets.GeneratorBasedBuilder):
|
56 |
+
"""
|
57 |
+
Aya Evaluation Suite contains a total of 26,750 open-ended conversation-style
|
58 |
+
prompts to evaluate multilingual open-ended generation quality.
|
59 |
+
"""
|
60 |
+
|
61 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
62 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
63 |
+
|
64 |
+
BUILDER_CONFIGS = [
|
65 |
+
SEACrowdConfig(
|
66 |
+
name=f"{_DATASETNAME}_{LANG}_source",
|
67 |
+
version=datasets.Version(_SOURCE_VERSION),
|
68 |
+
description=f"{_DATASETNAME} {LANG} source schema",
|
69 |
+
schema="source",
|
70 |
+
subset_id=f"{_DATASETNAME}_{LANG}",
|
71 |
+
)
|
72 |
+
for LANG in _LANGUAGES
|
73 |
+
] + [
|
74 |
+
SEACrowdConfig(
|
75 |
+
name=f"{_DATASETNAME}_{LANG}_seacrowd_t2t",
|
76 |
+
version=datasets.Version(_SEACROWD_VERSION),
|
77 |
+
description=f"{_DATASETNAME} {LANG} SEACrowd schema",
|
78 |
+
schema="seacrowd_t2t",
|
79 |
+
subset_id=f"{_DATASETNAME}_{LANG}",
|
80 |
+
)
|
81 |
+
for LANG in _LANGUAGES
|
82 |
+
]
|
83 |
+
|
84 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_ind_source"
|
85 |
+
|
86 |
+
def _info(self) -> datasets.DatasetInfo:
|
87 |
+
|
88 |
+
if self.config.schema == "source":
|
89 |
+
features = datasets.Features(
|
90 |
+
{
|
91 |
+
"id": datasets.Value("int64"),
|
92 |
+
"inputs": datasets.Value("string"),
|
93 |
+
"targets": datasets.Value("string"),
|
94 |
+
"language": datasets.Value("string"),
|
95 |
+
"script": datasets.Value("string"),
|
96 |
+
"source_id": datasets.Value("int64"),
|
97 |
+
}
|
98 |
+
)
|
99 |
+
|
100 |
+
elif self.config.schema == "seacrowd_t2t":
|
101 |
+
features = schemas.text2text_features
|
102 |
+
|
103 |
+
return datasets.DatasetInfo(
|
104 |
+
description=_DESCRIPTION,
|
105 |
+
features=features,
|
106 |
+
homepage=_HOMEPAGE,
|
107 |
+
license=_LICENSE,
|
108 |
+
citation=_CITATION,
|
109 |
+
)
|
110 |
+
|
111 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
112 |
+
"""Returns SplitGenerators."""
|
113 |
+
|
114 |
+
data_path = Path(dl_manager.download_and_extract(_URLS[_DATASETNAME]))
|
115 |
+
|
116 |
+
return [
|
117 |
+
datasets.SplitGenerator(
|
118 |
+
name=datasets.Split.TRAIN,
|
119 |
+
gen_kwargs={
|
120 |
+
"filepath": data_path,
|
121 |
+
"split": "train",
|
122 |
+
},
|
123 |
+
),
|
124 |
+
]
|
125 |
+
|
126 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
127 |
+
"""Yields examples as (key, example) tuples."""
|
128 |
+
|
129 |
+
language = self.config.name.split("_")[3]
|
130 |
+
|
131 |
+
df = pd.read_parquet(filepath)
|
132 |
+
df = df[df["language"] == language]
|
133 |
+
|
134 |
+
for index, row in df.iterrows():
|
135 |
+
if self.config.schema == "source":
|
136 |
+
example = row.to_dict()
|
137 |
+
|
138 |
+
elif self.config.schema == "seacrowd_t2t":
|
139 |
+
example = {
|
140 |
+
"id": str(index),
|
141 |
+
"text_1": row["inputs"],
|
142 |
+
"text_2": row["targets"],
|
143 |
+
"text_1_name": "inputs",
|
144 |
+
"text_2_name": "targets",
|
145 |
+
}
|
146 |
+
|
147 |
+
yield index, example
|