import os import datasets import pandas as pd _URL = r"https://huggingface.co/datasets/chuxuecao/hkmmlu/resolve/main/hkmmlu.zip" task_list = ['basic_medical_science.json', 'business_management.json', 'chinese_conditions.json', 'chinese_history.json', 'chinese_world_culture.json', 'chinese_world_geography.json', 'clinical_psychology.json', 'college_math.json', 'culture_commonsense.json', 'dentistry.json', 'economics.json', 'educational_psychology.json', 'financial_analysis.json', 'fire_science.json', 'hk_celebrity.json', 'hk_cultural_art.json', 'hk_current_affairs.json', 'hk_education.json', 'hk_entertainment_industry_management.json', 'hk_events_festivals.json', 'hk_film_television.json', 'hk_government_political_system.json', 'hk_historical_development_geography.json', 'hk_history.json', 'hk_human_geography.json', 'hk_law.json', 'hk_life_knowledge.json', 'hk_literature.json', 'hk_livelihood.json', 'hk_music.json', 'hk_party_politics.json', 'hk_physical_geography.json', 'hk_politicians_events.json', 'hk_society.json', 'hk_transport_infrastructure.json', 'hk_transportation.json', 'hk_urban_regional_development.json', 'hkdse_biology.json', 'hkdse_business_accounting_finance.json', 'hkdse_chemistry.json', 'hkdse_economics.json', 'hkdse_geography.json', 'hkdse_information_and_communication_technology.json', 'hkdse_mathematics.json', 'hkdse_physics.json', 'hkdse_tourism.json', 'human_behavior.json', 'insurance_studies.json', 'logic_reasoning.json', 'management_accounting.json', 'marketing_management.json', 'mechanical.json', 'nautical_science.json', 'optometry.json', 'organic_chemistry.json', 'pharmacology.json', 'pharmacy.json', 'physics.json', 'science_technology_commonsense.json', 'social_commonsense.json', 'statistics_and_machine_learning.json', 'technical.json', 'traditional_chinese_medicine_clinical_medicine.json', 'veterinary_pathology.json', 'veterinary_pharmacology.json', 'world_entertainment.json'] class HKMMLUConfig(datasets.BuilderConfig): def __init__(self, **kwargs): super().__init__(version=datasets.Version("1.0.0"), **kwargs) class HKMMLU(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [ HKMMLUConfig(name=task_name) for task_name in task_list ] def _info(self): features = datasets.Features( { "Question": datasets.Value("string"), "A": datasets.Value("string"), "B": datasets.Value("string"), "C": datasets.Value("string"), "D": datasets.Value("string"), "Answer": datasets.Value("string"), } ) return datasets.DatasetInfo( features=features ) def _split_generators(self, dl_manager): data_dir = dl_manager.download_and_extract(_URL) task_name = self.config.name return [ datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "filepath": os.path.join(data_dir, f"test/{task_name}.csv"), }, ), datasets.SplitGenerator( name=datasets.Split("dev"), gen_kwargs={ "filepath": os.path.join(data_dir, f"dev/{task_name}.csv"), }, ), ] def _generate_examples(self, filepath): df = pd.read_csv(filepath, header=0, index_col=0, encoding="utf-8") for i, instance in enumerate(df.to_dict(orient="records")): yield i, instance