# -*- coding: utf-8 -*- """BanglaRQA""" import json import os import datasets from datasets.tasks import QuestionAnsweringExtractive logger = datasets.logging.get_logger(__name__) _CITATION = """\ @inproceedings{ekram-etal-2022-banglarqa, title = "{B}angla{RQA}: A Benchmark Dataset for Under-resourced {B}angla Language Reading Comprehension-based Question Answering with Diverse Question-Answer Types", author = "Ekram, Syed Mohammed Sartaj and Rahman, Adham Arik and Altaf, Md. Sajid and Islam, Mohammed Saidul and Rahman, Mehrab Mustafy and Rahman, Md Mezbaur and Hossain, Md Azam and Kamal, Abu Raihan Mostofa", booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2022", month = dec, year = "2022", address = "Abu Dhabi, United Arab Emirates", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2022.findings-emnlp.186", pages = "2518--2532", abstract = "High-resource languages, such as English, have access to a plethora of datasets with various question-answer types resembling real-world reading comprehension. However, there is a severe lack of diverse and comprehensive question-answering datasets in under-resourced languages like Bangla. The ones available are either translated versions of English datasets with a niche answer format or created by human annotations focusing on a specific domain, question type, or answer type. To address these limitations, this paper introduces BanglaRQA, a reading comprehension-based Bangla question-answering dataset with various question-answer types. BanglaRQA consists of 3,000 context passages and 14,889 question-answer pairs created from those passages. The dataset comprises answerable and unanswerable questions covering four unique categories of questions and three types of answers. In addition, this paper also implemented four different Transformer models for question-answering on the proposed dataset. The best-performing model achieved an overall 62.42{\%} EM and 78.11{\%} F1 score. However, detailed analyses showed that the performance varies across question-answer types, leaving room for substantial improvement of the model performance. Furthermore, we demonstrated the effectiveness of BanglaRQA as a training resource by showing strong results on the bn{\_}squad dataset. Therefore, BanglaRQA has the potential to contribute to the advancement of future research by enhancing the capability of language models. The dataset and codes are available at https://github.com/sartajekram419/BanglaRQA", } """ _DESCRIPTION = """\ BanglaRQA is a human-annotated Bangla Question Answering (QA) dataset with diverse question-answer types. """ _URL = "https://huggingface.co/datasets/sartajekram/BanglaRQA/resolve/main/" _URLS = { "train": _URL + "Train.json", "dev": _URL + "Validation.json", "test": _URL + "Test.json" } class BanglaRQAConfig(datasets.BuilderConfig): """BuilderConfig for BanglaRQA.""" def __init__(self, **kwargs): """BuilderConfig for BanglaRQA. Args: **kwargs: keyword arguments forwarded to super. """ super(BanglaRQAConfig, self).__init__(**kwargs) class BanglaRQA(datasets.GeneratorBasedBuilder): """BanglaRQA""" BUILDER_CONFIGS = [ BanglaRQAConfig( name="BanglaRQA", version=datasets.Version("0.0.1", ""), description=_DESCRIPTION, ), ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "passage_id": datasets.Value("string"), "title": datasets.Value("string"), "context": datasets.Value("string"), "question_id": datasets.Value("string"), "question_text": datasets.Value("string"), "is_answerable": datasets.Value("string"), "question_type": datasets.Value("string"), "answers": datasets.features.Sequence( { "answer_text": datasets.Value("string"), "answer_type": datasets.Value("string"), } ) } ), supervised_keys=None, homepage="https://github.com/sartajekram419/BanglaRQA", citation=_CITATION, task_templates=[ QuestionAnsweringExtractive( question_column="question", context_column="context", answers_column="answers" ) ], ) def _split_generators(self, dl_manager): 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"]}), datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}), ] def _generate_examples(self, filepath): """This function returns the examples in the raw (text) form.""" logger.info("generating examples from = %s", filepath) key = 0 with open(filepath, encoding="utf-8") as f: banglaRQA = json.load(f) for article in banglaRQA["data"]: for qa in article["qas"]: yield key, { "passage_id": article["passage_id"], "title": article['title'], "context": article['context'], "question_id": qa["question_id"], "question_text": qa["question_text"], "is_answerable": qa["is_answerable"], "question_type": qa["question_type"], "answers": [ { "answer_text": qa['answers']['answer_text'][0], "answer_type": qa['answers']['answer_type'][0], }, { "answer_text": qa['answers']['answer_text'][1], "answer_type": qa['answers']['answer_type'][1], }, ] } key += 1