holylovenia
commited on
Commit
•
a20b20b
1
Parent(s):
afcbb54
Upload id_short_answer_grading.py with huggingface_hub
Browse files- id_short_answer_grading.py +195 -0
id_short_answer_grading.py
ADDED
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from pathlib import Path
|
3 |
+
from typing import Dict, List, Tuple
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
from nusacrowd.nusa_datasets.id_short_answer_grading.utils.id_short_answer_grading_utils import \
|
8 |
+
create_saintek_and_soshum_dataset
|
9 |
+
from nusacrowd.utils import schemas
|
10 |
+
from nusacrowd.utils.configs import NusantaraConfig
|
11 |
+
from nusacrowd.utils.constants import Tasks
|
12 |
+
|
13 |
+
_CITATION = """\
|
14 |
+
@article{
|
15 |
+
JLK,
|
16 |
+
author = {Muh Haidir and Ayu Purwarianti},
|
17 |
+
title = { Short Answer Grading Using Contextual Word Embedding and Linear Regression},
|
18 |
+
journal = {Jurnal Linguistik Komputasional},
|
19 |
+
volume = {3},
|
20 |
+
number = {2},
|
21 |
+
year = {2020},
|
22 |
+
keywords = {},
|
23 |
+
abstract = {Abstract—One of the obstacles in an efficient MOOC is the evaluation of student answers, including the short answer grading which requires large effort from instructors to conduct it manually.
|
24 |
+
Thus, NLP research in short answer grading has been conducted in order to support the automation, using several techniques such as rule
|
25 |
+
and machine learning based. Here, we’ve conducted experiments on deep learning based short answer grading to compare the answer
|
26 |
+
representation and answer assessment method. In the answer representation, we compared word embedding and sentence embedding models
|
27 |
+
such as BERT, and its modification. In the answer assessment method, we use linear regression. There are 2 datasets that we used, available
|
28 |
+
English short answer grading dataset with 80 questions and 2442 to get the best configuration for model and Indonesian short answer grading
|
29 |
+
dataset with 36 questions and 9165 short answers as testing data. Here, we’ve collected Indonesian short answers for Biology and Geography
|
30 |
+
subjects from 534 respondents where the answer grading was done by 7 experts. The best root mean squared error for both dataset was achieved
|
31 |
+
by using BERT pretrained, 0.880 for English dataset dan 1.893 for Indonesian dataset.},
|
32 |
+
issn = {2621-9336}, pages = {54--61}, doi = {10.26418/jlk.v3i2.38},
|
33 |
+
url = {https://inacl.id/journal/index.php/jlk/article/view/38}
|
34 |
+
}\
|
35 |
+
"""
|
36 |
+
_DATASETNAME = "id_short_answer_grading"
|
37 |
+
|
38 |
+
_DESCRIPTION = """\
|
39 |
+
Indonesian short answers for Biology and Geography subjects from 534 respondents where the answer grading was done by 7 experts.\
|
40 |
+
"""
|
41 |
+
|
42 |
+
_HOMEPAGE = "https://github.com/AgeMagi/tugas-akhir"
|
43 |
+
_LOCAL = False
|
44 |
+
_LANGUAGES = ["ind"]
|
45 |
+
|
46 |
+
_LICENSE = "Unknown"
|
47 |
+
|
48 |
+
_URLS = {
|
49 |
+
"saintek": {
|
50 |
+
"train": {
|
51 |
+
"question": "https://raw.githubusercontent.com/AgeMagi/tugas-akhir/master/data/question-saintek.csv",
|
52 |
+
"score": "https://raw.githubusercontent.com/AgeMagi/tugas-akhir/master/data/score-saintek.csv",
|
53 |
+
},
|
54 |
+
"test": {
|
55 |
+
"question": "https://raw.githubusercontent.com/AgeMagi/tugas-akhir/master/data/question-saintek-test.csv",
|
56 |
+
"score": "https://raw.githubusercontent.com/AgeMagi/tugas-akhir/master/data/score-saintek-test.csv",
|
57 |
+
},
|
58 |
+
},
|
59 |
+
"soshum": {
|
60 |
+
"train": {
|
61 |
+
"question": "https://raw.githubusercontent.com/AgeMagi/tugas-akhir/master/data/question-soshum.csv",
|
62 |
+
"score": "https://raw.githubusercontent.com/AgeMagi/tugas-akhir/master/data/score-soshum.csv",
|
63 |
+
},
|
64 |
+
"test": {
|
65 |
+
"question": "https://raw.githubusercontent.com/AgeMagi/tugas-akhir/master/data/question-soshum-test.csv",
|
66 |
+
"score": "https://raw.githubusercontent.com/AgeMagi/tugas-akhir/master/data/score-soshum-test.csv",
|
67 |
+
},
|
68 |
+
},
|
69 |
+
}
|
70 |
+
|
71 |
+
_SUPPORTED_TASKS = [Tasks.SHORT_ANSWER_GRADING]
|
72 |
+
|
73 |
+
_SOURCE_VERSION = "1.0.0"
|
74 |
+
|
75 |
+
_NUSANTARA_VERSION = "1.0.0"
|
76 |
+
|
77 |
+
|
78 |
+
class IdShortAnswerGrading(datasets.GeneratorBasedBuilder):
|
79 |
+
"""Indonesian short answers for Biology and Geography subjects from 534 respondents where the answer grading was done by 7 experts."""
|
80 |
+
|
81 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
82 |
+
NUSANTARA_VERSION = datasets.Version(_NUSANTARA_VERSION)
|
83 |
+
|
84 |
+
BUILDER_CONFIGS = [
|
85 |
+
NusantaraConfig(
|
86 |
+
name="id_short_answer_grading_source",
|
87 |
+
version=SOURCE_VERSION,
|
88 |
+
description="id_short_answer_grading source schema",
|
89 |
+
schema="source",
|
90 |
+
subset_id="id_short_answer_grading",
|
91 |
+
),
|
92 |
+
NusantaraConfig(
|
93 |
+
name="id_short_answer_grading_nusantara_pairs_score",
|
94 |
+
version=NUSANTARA_VERSION,
|
95 |
+
description="id_short_answer_grading Nusantara schema",
|
96 |
+
schema="nusantara_pairs_score",
|
97 |
+
subset_id="id_short_answer_grading",
|
98 |
+
),
|
99 |
+
]
|
100 |
+
|
101 |
+
DEFAULT_CONFIG_NAME = "id_short_answer_grading_source"
|
102 |
+
|
103 |
+
def _info(self) -> datasets.DatasetInfo:
|
104 |
+
if self.config.schema == "source":
|
105 |
+
features = datasets.Features(
|
106 |
+
{
|
107 |
+
"index": datasets.Value("int64"),
|
108 |
+
"type-problem": datasets.Value("int64"),
|
109 |
+
"pertanyaan": datasets.Value("string"),
|
110 |
+
"kunci-jawaban": datasets.Value("string"),
|
111 |
+
"jawaban": datasets.Value("string"),
|
112 |
+
"score": datasets.Value("int64"),
|
113 |
+
}
|
114 |
+
)
|
115 |
+
elif self.config.schema == "nusantara_pairs_score":
|
116 |
+
features = schemas.pairs_features([0, 1, 2, 3, 4, 5])
|
117 |
+
|
118 |
+
return datasets.DatasetInfo(
|
119 |
+
description=_DESCRIPTION,
|
120 |
+
features=features,
|
121 |
+
homepage=_HOMEPAGE,
|
122 |
+
license=_LICENSE,
|
123 |
+
citation=_CITATION,
|
124 |
+
)
|
125 |
+
|
126 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
127 |
+
"""Returns SplitGenerators."""
|
128 |
+
saintek_question = Path(dl_manager.download_and_extract(_URLS["saintek"]["train"]["question"]))
|
129 |
+
saintek_score = Path(dl_manager.download_and_extract(_URLS["saintek"]["train"]["score"]))
|
130 |
+
saintek_question_test = Path(dl_manager.download_and_extract(_URLS["saintek"]["test"]["question"]))
|
131 |
+
saintek_score_test = Path(dl_manager.download_and_extract(_URLS["saintek"]["test"]["score"]))
|
132 |
+
|
133 |
+
soshum_question = Path(dl_manager.download_and_extract(_URLS["soshum"]["train"]["question"]))
|
134 |
+
soshum_score = Path(dl_manager.download_and_extract(_URLS["soshum"]["train"]["score"]))
|
135 |
+
soshum_question_test = Path(dl_manager.download_and_extract(_URLS["soshum"]["test"]["question"]))
|
136 |
+
soshum_score_test = Path(dl_manager.download_and_extract(_URLS["soshum"]["test"]["score"]))
|
137 |
+
|
138 |
+
data_files = {
|
139 |
+
"saintek_question": saintek_question,
|
140 |
+
"saintek_score": saintek_score,
|
141 |
+
"saintek_question_test": saintek_question_test,
|
142 |
+
"saintek_score_test": saintek_score_test,
|
143 |
+
"soshum_question": soshum_question,
|
144 |
+
"soshum_score": soshum_score,
|
145 |
+
"soshum_question_test": soshum_question_test,
|
146 |
+
"soshum_score_test": soshum_score_test,
|
147 |
+
}
|
148 |
+
|
149 |
+
return [
|
150 |
+
datasets.SplitGenerator(
|
151 |
+
name=datasets.Split.TRAIN,
|
152 |
+
gen_kwargs={
|
153 |
+
"saintek_question": os.path.join(data_files["saintek_question"]),
|
154 |
+
"soshum_question": os.path.join(data_files["soshum_question"]),
|
155 |
+
"saintek_score": os.path.join(data_files["saintek_score"]),
|
156 |
+
"soshum_score": os.path.join(data_files["soshum_score"]),
|
157 |
+
"split": "train",
|
158 |
+
},
|
159 |
+
),
|
160 |
+
datasets.SplitGenerator(
|
161 |
+
name=datasets.Split.TEST,
|
162 |
+
gen_kwargs={
|
163 |
+
"saintek_question": os.path.join(data_files["saintek_question_test"]),
|
164 |
+
"soshum_question": os.path.join(data_files["soshum_question_test"]),
|
165 |
+
"saintek_score": os.path.join(data_files["saintek_score_test"]),
|
166 |
+
"soshum_score": os.path.join(data_files["soshum_score_test"]),
|
167 |
+
"split": "test",
|
168 |
+
},
|
169 |
+
),
|
170 |
+
]
|
171 |
+
|
172 |
+
def _generate_examples(self, saintek_question: Path, soshum_question: Path, saintek_score: Path, soshum_score: Path, split: str) -> Tuple[int, Dict]:
|
173 |
+
"""Yields examples as (key, example) tuples."""
|
174 |
+
df = create_saintek_and_soshum_dataset(saintek_question, soshum_question, saintek_score, soshum_score)
|
175 |
+
if self.config.schema == "source":
|
176 |
+
for row in df.itertuples():
|
177 |
+
entry = {
|
178 |
+
"index": row.index,
|
179 |
+
"type-problem": row.type_problem,
|
180 |
+
"pertanyaan": row.pertanyaan,
|
181 |
+
"kunci-jawaban": row.kunci_jawaban,
|
182 |
+
"jawaban": row.jawaban,
|
183 |
+
"score": row.score,
|
184 |
+
}
|
185 |
+
yield row.index, entry
|
186 |
+
|
187 |
+
elif self.config.schema == "nusantara_pairs_score":
|
188 |
+
for row in df.itertuples():
|
189 |
+
entry = {
|
190 |
+
"id": str(row.index),
|
191 |
+
"text_1": row.pertanyaan,
|
192 |
+
"text_2": row.jawaban,
|
193 |
+
"label": row.score,
|
194 |
+
}
|
195 |
+
yield row.index, entry
|