Upload iapp_squad.py with huggingface_hub
Browse files- iapp_squad.py +128 -0
iapp_squad.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
from seacrowd.utils import schemas
|
| 7 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 8 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
| 9 |
+
|
| 10 |
+
_DATASETNAME = "iapp_squad"
|
| 11 |
+
_CITATION = """\
|
| 12 |
+
@dataset
|
| 13 |
+
{
|
| 14 |
+
kobkrit_viriyayudhakorn_2021_4539916,
|
| 15 |
+
author = {Kobkrit Viriyayudhakorn and Charin Polpanumas},
|
| 16 |
+
title = {iapp_wiki_qa_squad},
|
| 17 |
+
month = feb,
|
| 18 |
+
year = 2021,
|
| 19 |
+
publisher = {Zenodo},
|
| 20 |
+
version = 1,
|
| 21 |
+
doi = {10.5281/zenodo.4539916},
|
| 22 |
+
url = {https://doi.org/10.5281/zenodo.4539916}
|
| 23 |
+
}
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
_DESCRIPTION = """
|
| 27 |
+
`iapp_wiki_qa_squad` is an extractive question answering dataset from Thai Wikipedia articles.
|
| 28 |
+
It is adapted from [the original iapp-wiki-qa-dataset](https://github.com/iapp-technology/iapp-wiki-qa-dataset)
|
| 29 |
+
to [SQuAD](https://rajpurkar.github.io/SQuAD-explorer/) format, resulting in
|
| 30 |
+
5761/742/739 questions from 1529/191/192 articles.
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
_HOMEPAGE = "https://github.com/iapp-technology/iapp-wiki-qa-dataset"
|
| 34 |
+
_LICENSE = Licenses.MIT.value
|
| 35 |
+
_HF_URL = " https://huggingface.co/datasets/iapp_wiki_qa_squad"
|
| 36 |
+
_SUPPORTED_TASKS = [Tasks.QUESTION_ANSWERING]
|
| 37 |
+
_LOCAL = False
|
| 38 |
+
_LANGUAGES = ["tha"]
|
| 39 |
+
_SOURCE_VERSION = "1.0.0"
|
| 40 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 41 |
+
|
| 42 |
+
_URLS = {
|
| 43 |
+
"train": "https://raw.githubusercontent.com/iapp-technology/iapp-wiki-qa-dataset/main/squad_format/data/train.jsonl",
|
| 44 |
+
"validation": "https://raw.githubusercontent.com/iapp-technology/iapp-wiki-qa-dataset/main/squad_format/data/valid.jsonl",
|
| 45 |
+
"test": "https://raw.githubusercontent.com/iapp-technology/iapp-wiki-qa-dataset/main/squad_format/data/test.jsonl",
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class IappWikiQASquadDataset(datasets.GeneratorBasedBuilder):
|
| 50 |
+
BUILDER_CONFIGS = [
|
| 51 |
+
SEACrowdConfig(name=f"{_DATASETNAME}_source", version=datasets.Version(_SOURCE_VERSION), description=_DESCRIPTION, subset_id=f"{_DATASETNAME}", schema="source"),
|
| 52 |
+
SEACrowdConfig(name=f"{_DATASETNAME}_seacrowd_qa", version=datasets.Version(_SEACROWD_VERSION), description=_DESCRIPTION, subset_id=f"{_DATASETNAME}", schema="seacrowd_qa"),
|
| 53 |
+
]
|
| 54 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
| 55 |
+
|
| 56 |
+
def _info(self):
|
| 57 |
+
if self.config.schema == "source":
|
| 58 |
+
features = datasets.Features(
|
| 59 |
+
{
|
| 60 |
+
"question_id": datasets.Value("string"),
|
| 61 |
+
"article_id": datasets.Value("string"),
|
| 62 |
+
"title": datasets.Value("string"),
|
| 63 |
+
"context": datasets.Value("string"),
|
| 64 |
+
"question": datasets.Value("string"),
|
| 65 |
+
"answers": datasets.features.Sequence(
|
| 66 |
+
{
|
| 67 |
+
"text": datasets.Value("string"),
|
| 68 |
+
"answer_start": datasets.Value("int32"),
|
| 69 |
+
"answer_end": datasets.Value("int32"),
|
| 70 |
+
}
|
| 71 |
+
),
|
| 72 |
+
}
|
| 73 |
+
)
|
| 74 |
+
elif self.config.schema == "seacrowd_qa":
|
| 75 |
+
features = schemas.qa_features
|
| 76 |
+
features["meta"] = {
|
| 77 |
+
"answer_start": datasets.Value("int32"),
|
| 78 |
+
"answer_end": datasets.Value("int32"),
|
| 79 |
+
}
|
| 80 |
+
return datasets.DatasetInfo(description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, citation=_CITATION, license=_LICENSE)
|
| 81 |
+
|
| 82 |
+
def _split_generators(self, dl_manager):
|
| 83 |
+
file_paths = dl_manager.download_and_extract(_URLS)
|
| 84 |
+
return [
|
| 85 |
+
datasets.SplitGenerator(
|
| 86 |
+
name=datasets.Split.TRAIN,
|
| 87 |
+
gen_kwargs={"filepath": file_paths["train"]},
|
| 88 |
+
),
|
| 89 |
+
datasets.SplitGenerator(
|
| 90 |
+
name=datasets.Split.VALIDATION,
|
| 91 |
+
gen_kwargs={"filepath": file_paths["validation"]},
|
| 92 |
+
),
|
| 93 |
+
datasets.SplitGenerator(
|
| 94 |
+
name=datasets.Split.TEST,
|
| 95 |
+
gen_kwargs={"filepath": file_paths["test"]},
|
| 96 |
+
),
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
def _generate_examples(self, filepath):
|
| 100 |
+
"""Yields examples."""
|
| 101 |
+
with open(filepath, encoding="utf-8") as f:
|
| 102 |
+
for id_, row in enumerate(f):
|
| 103 |
+
data = json.loads(row)
|
| 104 |
+
if self.config.schema == "source":
|
| 105 |
+
yield id_, {
|
| 106 |
+
"question_id": data["question_id"],
|
| 107 |
+
"article_id": data["article_id"],
|
| 108 |
+
"title": data["title"],
|
| 109 |
+
"context": data["context"],
|
| 110 |
+
"question": data["question"],
|
| 111 |
+
"answers": {
|
| 112 |
+
"text": data["answers"]["text"],
|
| 113 |
+
"answer_start": data["answers"]["answer_start"],
|
| 114 |
+
"answer_end": data["answers"]["answer_end"],
|
| 115 |
+
},
|
| 116 |
+
}
|
| 117 |
+
elif self.config.schema == "seacrowd_qa":
|
| 118 |
+
yield id_, {
|
| 119 |
+
"id": id_,
|
| 120 |
+
"question_id": data["question_id"],
|
| 121 |
+
"document_id": data["article_id"],
|
| 122 |
+
"question": data["question"],
|
| 123 |
+
"type": "abstractive",
|
| 124 |
+
"choices": [],
|
| 125 |
+
"context": data["context"],
|
| 126 |
+
"answer": data["answers"]["text"],
|
| 127 |
+
"meta": {"answer_start": data["answers"]["answer_start"][0], "answer_end": data["answers"]["answer_end"][0]},
|
| 128 |
+
}
|