|  | import csv | 
					
						
						|  | import datasets | 
					
						
						|  |  | 
					
						
						|  | _CITATION = """\ | 
					
						
						|  | @inproceedings{koto-etal-2023-indommlu, | 
					
						
						|  | title = "Large Language Models Only Pass Primary School Exams in {I}ndonesia: A Comprehensive Test on {I}ndo{MMLU}", | 
					
						
						|  | author = "Fajri Koto and Nurul Aisyah and Haonan Li and Timothy Baldwin", | 
					
						
						|  | booktitle = "Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing (EMNLP)", | 
					
						
						|  | month = December, | 
					
						
						|  | year = "2023", | 
					
						
						|  | address = "Singapore", | 
					
						
						|  | publisher = "Association for Computational Linguistics", | 
					
						
						|  | }""" | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | subject2english = { | 
					
						
						|  | 'Sejarah': 'History', | 
					
						
						|  | 'Geografi': 'Geography', | 
					
						
						|  | 'Bahasa Lampung': 'Lampungic', | 
					
						
						|  | 'IPS': 'Social science', | 
					
						
						|  | 'Bahasa Bali': 'Balinese', | 
					
						
						|  | 'Bahasa Makassar': 'Makassarese', | 
					
						
						|  | 'Bahasa Banjar': 'Banjarese', | 
					
						
						|  | 'Kimia': 'Chemistry', | 
					
						
						|  | 'Biologi': 'Biology', | 
					
						
						|  | 'IPA': 'Science', | 
					
						
						|  | 'Agama Kristen': 'Christian religion', | 
					
						
						|  | 'Kesenian': 'Art', | 
					
						
						|  | 'Agama Islam': 'Islam religion', | 
					
						
						|  | 'Agama Hindu': 'Hindu religion', | 
					
						
						|  | 'Bahasa Madura': 'Madurese', | 
					
						
						|  | 'Penjaskes': 'Sport', | 
					
						
						|  | 'Bahasa Indonesia': 'Indonesian language', | 
					
						
						|  | 'Fisika': 'Physics', | 
					
						
						|  | 'Budaya Alam Minangkabau': 'Minangkabau culture', | 
					
						
						|  | 'Bahasa Dayak Ngaju': 'Dayak language', | 
					
						
						|  | 'Sosiologi': 'Sociology', | 
					
						
						|  | 'Ekonomi': 'Economy', | 
					
						
						|  | 'Bahasa Sunda': 'Sundanese', | 
					
						
						|  | 'Bahasa Jawa': 'Javanese', | 
					
						
						|  | 'PPKN': 'Civic education', | 
					
						
						|  | } | 
					
						
						|  |  | 
					
						
						|  | subject2group = { | 
					
						
						|  | 'Sejarah': 'Humanities', | 
					
						
						|  | 'Geografi': 'Social science', | 
					
						
						|  | 'Bahasa Lampung': 'Local languages and cultures', | 
					
						
						|  | 'IPS': 'Social science', | 
					
						
						|  | 'Bahasa Bali': 'Local languages and cultures', | 
					
						
						|  | 'Bahasa Makassar': 'Local languages and cultures', | 
					
						
						|  | 'Bahasa Banjar': 'Local languages and cultures', | 
					
						
						|  | 'Kimia': 'STEM', | 
					
						
						|  | 'Biologi': 'STEM', | 
					
						
						|  | 'IPA': 'STEM', | 
					
						
						|  | 'Agama Kristen': 'Humanities', | 
					
						
						|  | 'Kesenian': 'Humanities', | 
					
						
						|  | 'Agama Islam': 'Humanities', | 
					
						
						|  | 'Agama Hindu': 'Humanities', | 
					
						
						|  | 'Bahasa Madura': 'Local languages and cultures', | 
					
						
						|  | 'Penjaskes': 'Humanities', | 
					
						
						|  | 'Bahasa Indonesia': 'Indonesian language', | 
					
						
						|  | 'Fisika': 'STEM', | 
					
						
						|  | 'Budaya Alam Minangkabau': 'Local languages and cultures', | 
					
						
						|  | 'Bahasa Dayak Ngaju': 'Local languages and cultures', | 
					
						
						|  | 'Sosiologi': 'Social science', | 
					
						
						|  | 'Ekonomi': 'Social science', | 
					
						
						|  | 'Bahasa Sunda': 'Local languages and cultures', | 
					
						
						|  | 'Bahasa Jawa': 'Local languages and cultures', | 
					
						
						|  | 'PPKN': 'Social science', | 
					
						
						|  | } | 
					
						
						|  |  | 
					
						
						|  | special_case = ['SD-SMP-SMA', 'SD-SMP'] | 
					
						
						|  | level_mapper = { | 
					
						
						|  | 'SMA': 'SMA', | 
					
						
						|  | 'Seleksi PTN': 'University entrance test', | 
					
						
						|  | 'SD': 'SD', | 
					
						
						|  | 'SMP': 'SMP', | 
					
						
						|  | 'Kelas I SD': 'SD', | 
					
						
						|  | 'Kelas X SMA': 'SMA', | 
					
						
						|  | 'Kelas XI SMA': 'SMA', | 
					
						
						|  | 'Kelas XII SMA': 'SMA', | 
					
						
						|  | 'V SD': 'SD', | 
					
						
						|  | 'VI SD': 'SD', | 
					
						
						|  | 'VII SMP': 'SMP', | 
					
						
						|  | 'VIII SMP ': 'SMP', | 
					
						
						|  | 'IX SMP': 'SMP', | 
					
						
						|  | 'Kelas III SD':'SD', | 
					
						
						|  | 'Kelas IV SD': 'SD', | 
					
						
						|  | 'Kelas II SD': 'SD' | 
					
						
						|  | } | 
					
						
						|  |  | 
					
						
						|  | def fix_level(level, kelas): | 
					
						
						|  |  | 
					
						
						|  | if level in special_case: | 
					
						
						|  | kelas = float(kelas) | 
					
						
						|  | if kelas >=1 and kelas <= 6: | 
					
						
						|  | level = 'SD' | 
					
						
						|  | elif kelas >=7 and kelas <= 9: | 
					
						
						|  | level = 'SMP' | 
					
						
						|  | elif kelas >=10: | 
					
						
						|  | level = 'SMA' | 
					
						
						|  | else: | 
					
						
						|  | print(level) | 
					
						
						|  | fixed_level = level_mapper[level] | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | fixed_kelas = -1 | 
					
						
						|  | kelas = str(kelas) | 
					
						
						|  | if kelas.strip() in ['PTN', '2023-10-12 00:00:00']: | 
					
						
						|  | fixed_kelas = 13 | 
					
						
						|  | elif kelas == '4,5,6': | 
					
						
						|  | fixed_kelas = 6 | 
					
						
						|  | else: | 
					
						
						|  | fixed_kelas = int(float(kelas.strip())) | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | return fixed_level, fixed_kelas | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | _URL = { | 
					
						
						|  | 'test': "https://huggingface.co/datasets/indolem/IndoMMLU/resolve/main/IndoMMLU.csv", | 
					
						
						|  | } | 
					
						
						|  |  | 
					
						
						|  | class IndoMMLUConfig(datasets.BuilderConfig): | 
					
						
						|  | """IndoMMLUConfig for IndoMMLU""" | 
					
						
						|  |  | 
					
						
						|  | def __init__(self, **kwargs): | 
					
						
						|  | """BuilderConfig for IndoStoryCloze. | 
					
						
						|  | **kwargs: keyword arguments forwarded to super. | 
					
						
						|  | """ | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | super().__init__(version=datasets.Version("1.0.0"), **kwargs) | 
					
						
						|  | self.features = ['subject', 'group', 'level', 'class', 'question', 'options', 'answer', 'is_for_fewshot'] | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | class IndoMMLU(datasets.GeneratorBasedBuilder): | 
					
						
						|  | """The IndoMMLU Datasets.""" | 
					
						
						|  |  | 
					
						
						|  | BUILDER_CONFIGS = [IndoMMLUConfig()] | 
					
						
						|  |  | 
					
						
						|  | def _info(self): | 
					
						
						|  | features = {feature: datasets.Value("string") for feature in self.config.features} | 
					
						
						|  |  | 
					
						
						|  | return datasets.DatasetInfo( | 
					
						
						|  | description='IndoMMLU', | 
					
						
						|  | features=datasets.Features(features), | 
					
						
						|  | homepage='https://github.com/fajri91/IndoMMLU', | 
					
						
						|  | citation=_CITATION | 
					
						
						|  | ) | 
					
						
						|  |  | 
					
						
						|  | def _split_generators(self, dl_manager): | 
					
						
						|  | downloaded_file = dl_manager.download_and_extract(_URL) | 
					
						
						|  |  | 
					
						
						|  | return [ | 
					
						
						|  | datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"data_file": downloaded_file['test']}), | 
					
						
						|  | ] | 
					
						
						|  |  | 
					
						
						|  | def _generate_examples(self, data_file): | 
					
						
						|  | data = csv.DictReader(open(data_file, newline='')) | 
					
						
						|  | for i, row in enumerate(data): | 
					
						
						|  | fixed_level, fixed_kelas = fix_level(row['level'], row['kelas']) | 
					
						
						|  | yield i, { | 
					
						
						|  | "subject": subject2english[row['subject']], | 
					
						
						|  | "group": subject2group[row['subject']], | 
					
						
						|  | "level": fixed_level, | 
					
						
						|  | "class": fixed_kelas, | 
					
						
						|  | "question": row['soal'], | 
					
						
						|  | "options": row['jawaban'].split('\n'), | 
					
						
						|  | "answer": row['kunci'], | 
					
						
						|  | "is_for_fewshot": row['is_for_fewshot'] | 
					
						
						|  | } |