holylovenia
commited on
Upload vihealthqa.py with huggingface_hub
Browse files- vihealthqa.py +157 -0
vihealthqa.py
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
from pathlib import Path
|
3 |
+
from typing import Dict, List, Tuple
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
from seacrowd.utils import schemas
|
9 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
10 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
11 |
+
|
12 |
+
_CITATION = """\
|
13 |
+
@InProceedings{nguyen2022viheathqa,
|
14 |
+
author="Nguyen, Nhung Thi-Hong
|
15 |
+
and Ha, Phuong Phan-Dieu
|
16 |
+
and Nguyen, Luan Thanh
|
17 |
+
and Van Nguyen, Kiet
|
18 |
+
and Nguyen, Ngan Luu-Thuy",
|
19 |
+
title="SPBERTQA: A Two-Stage Question Answering System Based on Sentence Transformers for Medical Texts",
|
20 |
+
booktitle="Knowledge Science, Engineering and Management",
|
21 |
+
year="2022",
|
22 |
+
publisher="Springer International Publishing",
|
23 |
+
address="Cham",
|
24 |
+
pages="371--382",
|
25 |
+
isbn="978-3-031-10986-7"
|
26 |
+
}
|
27 |
+
"""
|
28 |
+
_DATASETNAME = "vihealthqa"
|
29 |
+
_DESCRIPTION = """\
|
30 |
+
Vietnamese Visual Question Answering (ViVQA) consist of 10328 images and 15000 question-answer
|
31 |
+
pairs in Vietnamese for evaluating Vietnamese VQA models. This dataset is built based on 10328 randomly
|
32 |
+
selected images from MS COCO dataset. The question-answer pairs were based on the COCO-QA dataset that
|
33 |
+
was automatically translated from English to Vietnamese.
|
34 |
+
"""
|
35 |
+
_HOMEPAGE = "https://huggingface.co/datasets/tarudesu/ViHealthQA"
|
36 |
+
_LANGUAGES = ["vie"]
|
37 |
+
_LICENSE = Licenses.UNKNOWN.value
|
38 |
+
_PAPER_URL = "https://link.springer.com/chapter/10.1007/978-3-031-10986-7_30"
|
39 |
+
_LOCAL = False
|
40 |
+
_URLS = {
|
41 |
+
"vihealthqa": {
|
42 |
+
"train": "https://huggingface.co/datasets/tarudesu/ViHealthQA/raw/main/train.csv",
|
43 |
+
"val": "https://huggingface.co/datasets/tarudesu/ViHealthQA/raw/main/val.csv",
|
44 |
+
"test": "https://huggingface.co/datasets/tarudesu/ViHealthQA/raw/main/test.csv",
|
45 |
+
}
|
46 |
+
}
|
47 |
+
_SUPPORTED_TASKS = [Tasks.QUESTION_ANSWERING]
|
48 |
+
_SOURCE_VERSION = "1.0.0"
|
49 |
+
_SEACROWD_VERSION = "2024.06.20"
|
50 |
+
|
51 |
+
|
52 |
+
class ViHealthQADataset(datasets.GeneratorBasedBuilder):
|
53 |
+
'''
|
54 |
+
This is a SeaCrowed dataloader for dataset Vietnamese Visual Question Answering (ViVQA), which consists of 10328 images and 15000 question-answer
|
55 |
+
pairs in Vietnamese for evaluating Vietnamese VQA models.
|
56 |
+
'''
|
57 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
58 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
59 |
+
|
60 |
+
BUILDER_CONFIGS = [
|
61 |
+
SEACrowdConfig(
|
62 |
+
name=f"{_DATASETNAME}_source",
|
63 |
+
version=SOURCE_VERSION,
|
64 |
+
description=f"{_DATASETNAME} source schema",
|
65 |
+
schema="source",
|
66 |
+
subset_id=f"{_DATASETNAME}",
|
67 |
+
),
|
68 |
+
SEACrowdConfig(
|
69 |
+
name=f"{_DATASETNAME}_seacrowd_qa",
|
70 |
+
version=SEACROWD_VERSION,
|
71 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
72 |
+
schema="seacrowd_qa",
|
73 |
+
subset_id=f"{_DATASETNAME}",
|
74 |
+
),
|
75 |
+
]
|
76 |
+
|
77 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
78 |
+
|
79 |
+
def _info(self) -> datasets.DatasetInfo:
|
80 |
+
|
81 |
+
if self.config.schema == "source":
|
82 |
+
features = datasets.Features(
|
83 |
+
{
|
84 |
+
"id": datasets.Value("string"),
|
85 |
+
"question": datasets.Value("string"),
|
86 |
+
"answer": datasets.Value("string"),
|
87 |
+
"link": datasets.Value("string")
|
88 |
+
}
|
89 |
+
)
|
90 |
+
elif self.config.schema == "seacrowd_qa":
|
91 |
+
features = schemas.qa_features
|
92 |
+
features["meta"] = {"link": datasets.Value("string")}
|
93 |
+
else:
|
94 |
+
raise ValueError(f"No schema matched for {self.config.schema}")
|
95 |
+
|
96 |
+
return datasets.DatasetInfo(
|
97 |
+
description=_DESCRIPTION,
|
98 |
+
features=features,
|
99 |
+
homepage=_HOMEPAGE,
|
100 |
+
license=_LICENSE,
|
101 |
+
citation=_CITATION,
|
102 |
+
)
|
103 |
+
|
104 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
105 |
+
"""Returns SplitGenerators."""
|
106 |
+
urls = _URLS["vihealthqa"]
|
107 |
+
data_dir = dl_manager.download_and_extract(urls)
|
108 |
+
return [
|
109 |
+
datasets.SplitGenerator(
|
110 |
+
name=datasets.Split.TRAIN,
|
111 |
+
gen_kwargs={
|
112 |
+
"filepath": data_dir["train"],
|
113 |
+
"split": "train",
|
114 |
+
},
|
115 |
+
),
|
116 |
+
datasets.SplitGenerator(
|
117 |
+
name=datasets.Split.VALIDATION,
|
118 |
+
gen_kwargs={
|
119 |
+
"filepath": data_dir["val"],
|
120 |
+
"split": "val",
|
121 |
+
},
|
122 |
+
),
|
123 |
+
datasets.SplitGenerator(
|
124 |
+
name=datasets.Split.TEST,
|
125 |
+
gen_kwargs={
|
126 |
+
"filepath": data_dir["test"],
|
127 |
+
"split": "test",
|
128 |
+
},
|
129 |
+
),
|
130 |
+
]
|
131 |
+
|
132 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
133 |
+
"""Yields examples as (key, example) tuples."""
|
134 |
+
|
135 |
+
raw_examples = pd.read_csv(filepath)
|
136 |
+
|
137 |
+
for eid, exam in raw_examples.iterrows():
|
138 |
+
assert len(exam) == 4
|
139 |
+
exam_id, exam_quest, exam_answer, exam_link = exam
|
140 |
+
|
141 |
+
if self.config.schema == "source":
|
142 |
+
yield eid, {"id": str(exam_id), "question": exam_quest, "answer": exam_answer, "link": exam_link}
|
143 |
+
|
144 |
+
elif self.config.schema == "seacrowd_qa":
|
145 |
+
yield eid, {
|
146 |
+
"id": str(eid),
|
147 |
+
"question_id": exam_id,
|
148 |
+
"document_id": str(eid),
|
149 |
+
"question": exam_quest,
|
150 |
+
"type": None,
|
151 |
+
"choices": [],
|
152 |
+
"context": exam_link,
|
153 |
+
"answer": [exam_answer],
|
154 |
+
"meta": {
|
155 |
+
"link": exam_link,
|
156 |
+
},
|
157 |
+
}
|