import os import datasets import json import pandas as pd _CITATION = """\ @article{son2023hae, title={HAE-RAE Bench: Evaluation of Korean Knowledge in Language Models}, author={Son, Guijin and Lee, Hanwool and Kim, Suwan and Lee, Jaecheol and Yeom, Je Won and Jung, Jihyu and Kim, Jung Woo and Kim, Songseong}, journal={arXiv preprint arXiv:2309.02706}, year={2023} } """ _DESCRIPTION = """\ HAE-RAE Bench """ _HOMEPAGE = "https://huggingface.co/HAERAE-HUB" _LICENSE = "cc-by-nc-nd-4.0" split_names = ['standard_nomenclature', 'correct_definition_matching', 'date_understanding', 'general_knowledge', 'history', 'loan_word', 'lyrics_denoising', 'proverbs_denoising', 'rare_word', 'reading_comprehension'] class HRBConfig(datasets.BuilderConfig): def __init__(self, **kwargs): super().__init__(version=datasets.Version("1.0.1"), **kwargs) class HRB(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [ HRBConfig( name=name, ) for name in split_names ] def _info(self): features = datasets.Features( { "query": datasets.Value("string"), "options" : datasets.Value("string"), "answer": datasets.Value("string"), "category": datasets.Value("string"), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): train_path = dl_manager.download_and_extract("./data/hrb.v1.1.jsonl") return [ datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "filepath": train_path, }, ), ] def _generate_examples(self, filepath): with open(filepath, encoding="utf-8") as f: buffer = [] for key, row in enumerate(f): data = json.loads(row) if data["category"] == self.config.name: buffer.append({ "query": data["query"], "options" : data["options"], "answer": data["answer"], "category": data["category"] }) for idx, dat in enumerate(buffer): yield idx,dat