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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import datasets
|
| 3 |
+
|
| 4 |
+
_CITATION = """\
|
| 5 |
+
@inproceedings{koto-etal-2023-indommlu,
|
| 6 |
+
title = "Large Language Models Only Pass Primary School Exams in {I}ndonesia: A Comprehensive Test on {I}ndo{MMLU}",
|
| 7 |
+
author = "Fajri Koto and Nurul Aisyah and Haonan Li and Timothy Baldwin",
|
| 8 |
+
booktitle = "Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing (EMNLP)",
|
| 9 |
+
month = December,
|
| 10 |
+
year = "2023",
|
| 11 |
+
address = "Singapore",
|
| 12 |
+
publisher = "Association for Computational Linguistics",
|
| 13 |
+
}"""
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
subject2english = {
|
| 17 |
+
'Sejarah': 'History',
|
| 18 |
+
'Geografi': 'Geography',
|
| 19 |
+
'Bahasa Lampung': 'Lampungic',
|
| 20 |
+
'IPS': 'Social science',
|
| 21 |
+
'Bahasa Bali': 'Balinese',
|
| 22 |
+
'Bahasa Makassar': 'Makassarese',
|
| 23 |
+
'Bahasa Banjar': 'Banjarese',
|
| 24 |
+
'Kimia': 'Chemistry',
|
| 25 |
+
'Biologi': 'Biology',
|
| 26 |
+
'IPA': 'Science',
|
| 27 |
+
'Agama Kristen': 'Christian religion',
|
| 28 |
+
'Kesenian': 'Art',
|
| 29 |
+
'Agama Islam': 'Islam religion',
|
| 30 |
+
'Agama Hindu': 'Hindu religion',
|
| 31 |
+
'Bahasa Madura': 'Madurese',
|
| 32 |
+
'Penjaskes': 'Sport',
|
| 33 |
+
'Bahasa Indonesia': 'Indonesian language',
|
| 34 |
+
'Fisika': 'Physics',
|
| 35 |
+
'Budaya Alam Minangkabau': 'Minangkabau culture',
|
| 36 |
+
'Bahasa Dayak Ngaju': 'Dayak language',
|
| 37 |
+
'Sosiologi': 'Sociology',
|
| 38 |
+
'Ekonomi': 'Economy',
|
| 39 |
+
'Bahasa Sunda': 'Sundanese',
|
| 40 |
+
'Bahasa Jawa': 'Javanese',
|
| 41 |
+
'PPKN': 'Civic education',
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
subject2group = {
|
| 45 |
+
'Sejarah': 'Humanities',
|
| 46 |
+
'Geografi': 'Social science',
|
| 47 |
+
'Bahasa Lampung': 'Local languages and cultures',
|
| 48 |
+
'IPS': 'Social science',
|
| 49 |
+
'Bahasa Bali': 'Local languages and cultures',
|
| 50 |
+
'Bahasa Makassar': 'Local languages and cultures',
|
| 51 |
+
'Bahasa Banjar': 'Local languages and cultures',
|
| 52 |
+
'Kimia': 'STEM',
|
| 53 |
+
'Biologi': 'STEM',
|
| 54 |
+
'IPA': 'STEM',
|
| 55 |
+
'Agama Kristen': 'Humanities',
|
| 56 |
+
'Kesenian': 'Humanities',
|
| 57 |
+
'Agama Islam': 'Humanities',
|
| 58 |
+
'Agama Hindu': 'Humanities',
|
| 59 |
+
'Bahasa Madura': 'Local languages and cultures',
|
| 60 |
+
'Penjaskes': 'Humanities',
|
| 61 |
+
'Bahasa Indonesia': 'Indonesian language',
|
| 62 |
+
'Fisika': 'STEM',
|
| 63 |
+
'Budaya Alam Minangkabau': 'Local languages and cultures',
|
| 64 |
+
'Bahasa Dayak Ngaju': 'Local languages and cultures',
|
| 65 |
+
'Sosiologi': 'Social science',
|
| 66 |
+
'Ekonomi': 'Social science',
|
| 67 |
+
'Bahasa Sunda': 'Local languages and cultures',
|
| 68 |
+
'Bahasa Jawa': 'Local languages and cultures',
|
| 69 |
+
'PPKN': 'Social science',
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
special_case = ['SD-SMP-SMA', 'SD-SMP']
|
| 73 |
+
level_mapper = {
|
| 74 |
+
'SMA': 'SMA',
|
| 75 |
+
'Seleksi PTN': 'University entrance test',
|
| 76 |
+
'SD': 'SD',
|
| 77 |
+
'SMP': 'SMP',
|
| 78 |
+
'Kelas I SD': 'SD',
|
| 79 |
+
'Kelas X SMA': 'SMA',
|
| 80 |
+
'Kelas XI SMA': 'SMA',
|
| 81 |
+
'Kelas XII SMA': 'SMA',
|
| 82 |
+
'V SD': 'SD',
|
| 83 |
+
'VI SD': 'SD',
|
| 84 |
+
'VII SMP': 'SMP',
|
| 85 |
+
'VIII SMP ': 'SMP',
|
| 86 |
+
'IX SMP': 'SMP',
|
| 87 |
+
'Kelas III SD':'SD',
|
| 88 |
+
'Kelas IV SD': 'SD',
|
| 89 |
+
'Kelas II SD': 'SD'
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
def fix_level(level, kelas):
|
| 93 |
+
#Fixing Level
|
| 94 |
+
if level in special_case:
|
| 95 |
+
kelas = float(kelas)
|
| 96 |
+
if kelas >=1 and kelas <= 6:
|
| 97 |
+
level = 'SD'
|
| 98 |
+
elif kelas >=7 and kelas <= 9:
|
| 99 |
+
level = 'SMP'
|
| 100 |
+
elif kelas >=10:
|
| 101 |
+
level = 'SMA'
|
| 102 |
+
else:
|
| 103 |
+
print(level)
|
| 104 |
+
fixed_level = level_mapper[level]
|
| 105 |
+
|
| 106 |
+
#Fixing class
|
| 107 |
+
fixed_kelas = -1
|
| 108 |
+
if kelas.strip() in ['PTN', '2023-10-12 00:00:00']:
|
| 109 |
+
fixed_kelas = 13
|
| 110 |
+
elif kelas == '4,5,6':
|
| 111 |
+
fixed_kelas = 6
|
| 112 |
+
else:
|
| 113 |
+
fixed_kelas = int(kelas.strip())
|
| 114 |
+
|
| 115 |
+
# sanity check over the level and kelas
|
| 116 |
+
return fixed_level, fixed_kelas
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
_URL = {
|
| 120 |
+
'test': "https://huggingface.co/datasets/indolem/IndoMMLU/resolve/main/test.csv",
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
class IndoMMLUConfig(datasets.BuilderConfig):
|
| 124 |
+
"""IndoMMLUConfig for IndoMMLU"""
|
| 125 |
+
|
| 126 |
+
def __init__(self, **kwargs):
|
| 127 |
+
"""BuilderConfig for IndoStoryCloze.
|
| 128 |
+
**kwargs: keyword arguments forwarded to super.
|
| 129 |
+
"""
|
| 130 |
+
# Version history:
|
| 131 |
+
# 1.0.0: Release version
|
| 132 |
+
super().__init__(version=datasets.Version("1.0.0"), **kwargs)
|
| 133 |
+
self.features = ['subject', 'group', 'level', 'class', 'question', 'options', 'answer', 'is_for_fewshot']
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
class IndoMMLU(datasets.GeneratorBasedBuilder):
|
| 137 |
+
"""The IndoMMLU Datasets."""
|
| 138 |
+
|
| 139 |
+
BUILDER_CONFIGS = [IndoMMLUConfig()]
|
| 140 |
+
|
| 141 |
+
def _info(self):
|
| 142 |
+
features = {feature: datasets.Value("string") for feature in self.config.features}
|
| 143 |
+
|
| 144 |
+
return datasets.DatasetInfo(
|
| 145 |
+
description='IndoMMLU',
|
| 146 |
+
features=datasets.Features(features),
|
| 147 |
+
homepage='https://github.com/fajri91/IndoMMLU',
|
| 148 |
+
citation=_CITATION
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
def _split_generators(self, dl_manager):
|
| 152 |
+
downloaded_file = dl_manager.download_and_extract(_URLs)
|
| 153 |
+
|
| 154 |
+
return [
|
| 155 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"data_file": downloaded_file['test']}),
|
| 156 |
+
]
|
| 157 |
+
|
| 158 |
+
def _generate_examples(self, data_file):
|
| 159 |
+
data = csv.DictReader(open(data_file, newline=''))
|
| 160 |
+
for i, row in enumerate(data):
|
| 161 |
+
fixed_level, fixed_kelas = fix_level(row['level'], row['kelas'])
|
| 162 |
+
yield i, {
|
| 163 |
+
"subject": subject2english[row['subject']],
|
| 164 |
+
"group": subject2group[row['subject']],
|
| 165 |
+
"level": fixed_level,
|
| 166 |
+
"class": fixed_class,
|
| 167 |
+
"question": row['soal'],
|
| 168 |
+
"options": row['jawaban'].split('\n'),
|
| 169 |
+
"answer": row['kunci'],
|
| 170 |
+
"is_for_fewshot": row['is_for_fewshot']
|
| 171 |
+
}
|