holylovenia
commited on
Commit
•
3a475e9
1
Parent(s):
33f0368
Upload vigetext.py with huggingface_hub
Browse files- vigetext.py +151 -0
vigetext.py
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
|
3 |
+
import datasets
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
from seacrowd.utils import schemas
|
7 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
8 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
9 |
+
|
10 |
+
_CITATION = """
|
11 |
+
@inproceedings{10.1145/3628797.3628837,
|
12 |
+
author = {Nguyen, Duc-Vu and Nguyen, Quoc-Nam},
|
13 |
+
title = {Evaluating the Symbol Binding Ability of Large Language Models for Multiple-Choice Questions in Vietnamese General Education},
|
14 |
+
year = {2023},
|
15 |
+
isbn = {9798400708916},
|
16 |
+
publisher = {Association for Computing Machinery},
|
17 |
+
address = {New York, NY, USA},
|
18 |
+
url = {https://doi.org/10.1145/3628797.3628837},
|
19 |
+
doi = {10.1145/3628797.3628837},
|
20 |
+
booktitle = {Proceedings of the 12th International Symposium on Information and Communication Technology},
|
21 |
+
pages = {379–386},
|
22 |
+
numpages = {8},
|
23 |
+
keywords = {Analysis of Language Models, Multiple Choice Symbol Binding, Multiple Choice Question Answering, Language Modeling},
|
24 |
+
location = {<conf-loc>, <city>Ho Chi Minh</city>, <country>Vietnam</country>, </conf-loc>},
|
25 |
+
series = {SOICT '23}
|
26 |
+
}
|
27 |
+
"""
|
28 |
+
|
29 |
+
_DATASETNAME = "vigetext"
|
30 |
+
|
31 |
+
_DESCRIPTION = """
|
32 |
+
The high-quality dataset with structured guidelines for typing LaTeX formulas in Mathematics, Physics, Chemistry, and
|
33 |
+
Biology. Objective was to cover the entire scope of the Vietnamese General Education Examination spanning from 2017 to 2023.
|
34 |
+
This comprehensive approach included the challenging examinations of the years 2017 and 2018, which have been significant
|
35 |
+
for nearly all Vietnamese students in recent years. It is important to highlight that the exact and unquestionably correct
|
36 |
+
answers have been exclusively obtained from the Vietnamese Ministry of Education.
|
37 |
+
"""
|
38 |
+
|
39 |
+
_HOMEPAGE = "https://huggingface.co/datasets/uitnlp/ViGEText_17to23"
|
40 |
+
|
41 |
+
_LANGUAGES = ["vie"]
|
42 |
+
|
43 |
+
_LICENSE = Licenses.UNKNOWN.value
|
44 |
+
|
45 |
+
_LOCAL = False
|
46 |
+
|
47 |
+
_URLS = {
|
48 |
+
_DATASETNAME: {
|
49 |
+
"train": "https://huggingface.co/datasets/uitnlp/ViGEText_17to23/resolve/main/data/train-00000-of-00001.parquet",
|
50 |
+
"validation": "https://huggingface.co/datasets/uitnlp/ViGEText_17to23/resolve/main/data/validation-00000-of-00001.parquet",
|
51 |
+
"test": "https://huggingface.co/datasets/uitnlp/ViGEText_17to23/resolve/main/data/test-00000-of-00001.parquet",
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
_SUPPORTED_TASKS = [Tasks.QUESTION_ANSWERING]
|
56 |
+
|
57 |
+
_SOURCE_VERSION = "1.0.0"
|
58 |
+
|
59 |
+
_SEACROWD_VERSION = "2024.06.20"
|
60 |
+
|
61 |
+
|
62 |
+
class VigetextDataset(datasets.GeneratorBasedBuilder):
|
63 |
+
"""Vigetext is a dataset for evaluating the Symbol Binding Ability of Large Language Models for Multiple-Choice Questions in Vietnamese General Education."""
|
64 |
+
|
65 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
66 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
67 |
+
|
68 |
+
BUILDER_CONFIGS = [
|
69 |
+
SEACrowdConfig(
|
70 |
+
name=f"{_DATASETNAME}_source",
|
71 |
+
version=SOURCE_VERSION,
|
72 |
+
description=f"{_DATASETNAME} source schema",
|
73 |
+
schema="source",
|
74 |
+
subset_id=_DATASETNAME,
|
75 |
+
),
|
76 |
+
SEACrowdConfig(
|
77 |
+
name=f"{_DATASETNAME}_seacrowd_qa",
|
78 |
+
version=SEACROWD_VERSION,
|
79 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
80 |
+
schema="seacrowd_qa",
|
81 |
+
subset_id=_DATASETNAME,
|
82 |
+
),
|
83 |
+
]
|
84 |
+
|
85 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
86 |
+
|
87 |
+
def _info(self) -> datasets.DatasetInfo:
|
88 |
+
if self.config.schema == "source":
|
89 |
+
features = datasets.Features(
|
90 |
+
{
|
91 |
+
"id": datasets.Value("string"),
|
92 |
+
"input": datasets.Value("string"),
|
93 |
+
"target": datasets.Value("string"),
|
94 |
+
}
|
95 |
+
)
|
96 |
+
|
97 |
+
else:
|
98 |
+
features = schemas.qa_features
|
99 |
+
|
100 |
+
return datasets.DatasetInfo(
|
101 |
+
description=_DESCRIPTION,
|
102 |
+
features=features,
|
103 |
+
homepage=_HOMEPAGE,
|
104 |
+
license=_LICENSE,
|
105 |
+
citation=_CITATION,
|
106 |
+
)
|
107 |
+
|
108 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> list[datasets.SplitGenerator]:
|
109 |
+
"""Returns SplitGenerators."""
|
110 |
+
urls = _URLS[_DATASETNAME]
|
111 |
+
data_dir = dl_manager.download_and_extract(urls)
|
112 |
+
|
113 |
+
return [
|
114 |
+
datasets.SplitGenerator(
|
115 |
+
name=datasets.Split.TRAIN,
|
116 |
+
gen_kwargs={"filepath": data_dir, "split": "train"},
|
117 |
+
),
|
118 |
+
datasets.SplitGenerator(
|
119 |
+
name=datasets.Split.VALIDATION,
|
120 |
+
gen_kwargs={"filepath": data_dir, "split": "validation"},
|
121 |
+
),
|
122 |
+
datasets.SplitGenerator(
|
123 |
+
name=datasets.Split.TEST,
|
124 |
+
gen_kwargs={"filepath": data_dir, "split": "test"},
|
125 |
+
),
|
126 |
+
]
|
127 |
+
|
128 |
+
def _generate_examples(self, filepath: Path, split: str) -> tuple[int, dict]:
|
129 |
+
df = pd.read_parquet(filepath[split])
|
130 |
+
data = df.to_dict(orient="records")
|
131 |
+
for i, item in enumerate(data):
|
132 |
+
if self.config.schema == "source":
|
133 |
+
yield i, {
|
134 |
+
"id": item["id"],
|
135 |
+
"input": item["input"],
|
136 |
+
"target": item["target"],
|
137 |
+
}
|
138 |
+
else:
|
139 |
+
question_and_options = item["input"].split("\n")
|
140 |
+
answer_map = {opt[0]: opt[2:].strip() for opt in question_and_options[1:]}
|
141 |
+
yield i, {
|
142 |
+
"id": str(i),
|
143 |
+
"question_id": item["id"],
|
144 |
+
"document_id": "",
|
145 |
+
"question": question_and_options[0],
|
146 |
+
"type": "multiple_choice",
|
147 |
+
"choices": [opt[2:].strip() for opt in question_and_options[1:]], # remove A., B., ... in the options
|
148 |
+
"context": "",
|
149 |
+
"answer": [answer_map[item["target"]]],
|
150 |
+
"meta": {}
|
151 |
+
}
|