# coding=utf-8 # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """KorQuAD v1.0:The Korean Question Answering Dataset""" import pickle import os import sys import datasets from datasets.tasks import QuestionAnsweringExtractive _CITATION = """\ @article{lim2019korquad1, title={Korquad1. 0: Korean qa dataset for machine reading comprehension}, author={Lim, Seungyoung and Kim, Myungji and Lee, Jooyoul}, journal={arXiv preprint arXiv:1909.07005}, year={2019} } """ _DESCRIPTION = """\ KorQuAD 1.0 is a large-scale Korean dataset for machine reading comprehension task consisting of human generated questions for Wikipedia articles. We benchmark the data collecting process of SQuADv1.0 and crowdsourced 70,000+ question-answer pairs. 1,637 articles and 70,079 pairs of question answers were collected. 1,420 articles are used for the training set, 140 for the dev set, and 77 for the test set. 60,407 question-answer pairs are for the training set, 5,774 for the dev set, and 3,898 for the test set. """ _HOMEPAGE = "https://korquad.github.io/KorQuad%201.0/" _LICENSE = "CC BY-ND 2.0 KR" _URL = "https://huggingface.co/datasets/wisenut-nlp-team/squad_kor_v1/resolve/main/" class SquadKorV1(datasets.GeneratorBasedBuilder): """KorQuAD 1.0 dataset""" VERSION = datasets.Version("1.0.0") BUILDER_CONFIGS = [ datasets.BuilderConfig( name="32", version=VERSION, description=_DESCRIPTION, ), datasets.BuilderConfig( name="64", version=VERSION, description=_DESCRIPTION, ),datasets.BuilderConfig( name="128", version=VERSION, description=_DESCRIPTION, ),datasets.BuilderConfig( name="256", version=VERSION, description=_DESCRIPTION, ),datasets.BuilderConfig( name="512", version=VERSION, description=_DESCRIPTION, ), ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "id": datasets.Value("string"), "title": datasets.Value("string"), "context": datasets.Value("string"), "question": datasets.Value("string"), "answers": datasets.features.Sequence( { "text": datasets.Value("string"), "answer_start": datasets.Value("int32"), } ), } ), supervised_keys=None, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, task_templates=[ QuestionAnsweringExtractive( question_column="question", context_column="context", answers_column="answers" ) ], ) def _split_generators(self, dl_manager): """Returns SplitGenerators.""" urls = { "train": _URL + f"squad_kor_v1_train_{self.config.name}tokens.pickle", "dev": _URL + f"squad_kor_v1_validation_{self.config.name}tokens.pickle" } downloaded_files = dl_manager.download_and_extract(urls) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}), ] def _generate_examples(self, filepath): """Yields examples.""" with open(filepath, "rb") as f: squad = pickle.load(f) for data in squad: yield data["id"], { "title": data["title"], "context": data["context"], "question": data["question"], "id": data["id"], "answers": data["answers"] }