holylovenia
commited on
Upload copal.py with huggingface_hub
Browse files
copal.py
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
from seacrowd.utils import schemas
|
5 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
6 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
7 |
+
|
8 |
+
_CITATION = """\
|
9 |
+
@article{wibowo2023copal,
|
10 |
+
title={COPAL-ID: Indonesian Language Reasoning with Local Culture and Nuances},
|
11 |
+
author={Wibowo, Haryo Akbarianto and Fuadi, Erland Hilman and Nityasya, Made Nindyatama and Prasojo, Radityo Eko and Aji, Alham Fikri},
|
12 |
+
journal={arXiv preprint arXiv:2311.01012},
|
13 |
+
year={2023}
|
14 |
+
}
|
15 |
+
"""
|
16 |
+
_DATASETNAME = "copal"
|
17 |
+
|
18 |
+
_DESCRIPTION = """\
|
19 |
+
COPAL is a novel Indonesian language common sense reasoning dataset. Unlike the previous Indonesian COPA dataset (XCOPA-ID), COPAL-ID incorporates Indonesian local and cultural nuances,
|
20 |
+
providing a more natural portrayal of day-to-day causal reasoning within the Indonesian cultural sphere.
|
21 |
+
Professionally written by natives from scratch, COPAL-ID is more fluent and free from awkward phrases, unlike the translated XCOPA-ID.
|
22 |
+
Additionally, COPAL-ID is presented in both standard Indonesian and Jakartan Indonesian–a commonly used dialect.
|
23 |
+
It consists of premise, choice1, choice2, question, and label, similar to the COPA dataset.
|
24 |
+
"""
|
25 |
+
|
26 |
+
_HOMEPAGE = "https://huggingface.co/datasets/haryoaw/COPAL"
|
27 |
+
|
28 |
+
_LICENSE = Licenses.CC_BY_SA_4_0.value
|
29 |
+
|
30 |
+
_URLS = {"test": "https://huggingface.co/datasets/haryoaw/COPAL/resolve/main/test_copal.csv?download=true", "test_colloquial": "https://huggingface.co/datasets/haryoaw/COPAL/resolve/main/test_copal_colloquial.csv?download=true"}
|
31 |
+
|
32 |
+
_SUPPORTED_TASKS = [Tasks.COMMONSENSE_REASONING]
|
33 |
+
|
34 |
+
_LOCAL = False
|
35 |
+
_LANGUAGES = ["ind"]
|
36 |
+
|
37 |
+
_SOURCE_VERSION = "1.0.0"
|
38 |
+
|
39 |
+
_SEACROWD_VERSION = "2024.06.20"
|
40 |
+
|
41 |
+
|
42 |
+
class COPAL(datasets.GeneratorBasedBuilder):
|
43 |
+
|
44 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
45 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
46 |
+
|
47 |
+
BUILDER_CONFIGS = [
|
48 |
+
SEACrowdConfig(
|
49 |
+
name=f"{_DATASETNAME}_source",
|
50 |
+
version=SOURCE_VERSION,
|
51 |
+
description="COPAL test source schema",
|
52 |
+
schema="source",
|
53 |
+
subset_id="copal",
|
54 |
+
),
|
55 |
+
SEACrowdConfig(
|
56 |
+
name=f"{_DATASETNAME}_colloquial_source",
|
57 |
+
version=SOURCE_VERSION,
|
58 |
+
description="COPAL test colloquial source schema",
|
59 |
+
schema="source",
|
60 |
+
subset_id="copal",
|
61 |
+
),
|
62 |
+
SEACrowdConfig(
|
63 |
+
name=f"{_DATASETNAME}_seacrowd_qa",
|
64 |
+
version=SEACROWD_VERSION,
|
65 |
+
description="COPAL test seacrowd schema",
|
66 |
+
schema="seacrowd_qa",
|
67 |
+
subset_id="copal",
|
68 |
+
),
|
69 |
+
SEACrowdConfig(
|
70 |
+
name=f"{_DATASETNAME}_colloquial_seacrowd_qa",
|
71 |
+
version=SEACROWD_VERSION,
|
72 |
+
description="COPAL test colloquial seacrowd schema",
|
73 |
+
schema="seacrowd_qa",
|
74 |
+
subset_id="copal",
|
75 |
+
),
|
76 |
+
]
|
77 |
+
|
78 |
+
DEFAULT_CONFIG_NAME = "copal_source"
|
79 |
+
|
80 |
+
def _info(self):
|
81 |
+
if self.config.schema == "source":
|
82 |
+
features = datasets.Features(
|
83 |
+
{
|
84 |
+
"premise": datasets.Value("string"),
|
85 |
+
"choice1": datasets.Value("string"),
|
86 |
+
"choice2": datasets.Value("string"),
|
87 |
+
"question": datasets.Value("string"),
|
88 |
+
"idx": datasets.Value("int64"),
|
89 |
+
"label": datasets.Value("int64"),
|
90 |
+
"terminology": datasets.Value("int64"),
|
91 |
+
"culture": datasets.Value("int64"),
|
92 |
+
"language": datasets.Value("int64"),
|
93 |
+
}
|
94 |
+
)
|
95 |
+
elif self.config.schema == "seacrowd_qa":
|
96 |
+
features = schemas.qa_features
|
97 |
+
features["meta"] = {"terminology": datasets.Value("int64"), "culture": datasets.Value("int64"), "language": datasets.Value("int64")}
|
98 |
+
|
99 |
+
return datasets.DatasetInfo(
|
100 |
+
description=_DESCRIPTION,
|
101 |
+
features=features,
|
102 |
+
homepage=_HOMEPAGE,
|
103 |
+
license=_LICENSE,
|
104 |
+
citation=_CITATION,
|
105 |
+
)
|
106 |
+
|
107 |
+
def _split_generators(self, dl_manager):
|
108 |
+
data_dir = dl_manager.download_and_extract(_URLS)
|
109 |
+
if "colloquial" in self.config.name:
|
110 |
+
data_url = data_dir["test_colloquial"]
|
111 |
+
else:
|
112 |
+
data_url = data_dir["test"]
|
113 |
+
return [
|
114 |
+
datasets.SplitGenerator(
|
115 |
+
name=datasets.Split.TEST,
|
116 |
+
gen_kwargs={"filepath": data_url},
|
117 |
+
),
|
118 |
+
]
|
119 |
+
|
120 |
+
def _generate_examples(self, filepath):
|
121 |
+
df = pd.read_csv(filepath, sep=",", header="infer").reset_index()
|
122 |
+
if self.config.schema == "source":
|
123 |
+
for row in df.itertuples():
|
124 |
+
entry = {
|
125 |
+
"premise": row.premise,
|
126 |
+
"choice1": row.choice1,
|
127 |
+
"choice2": row.choice2,
|
128 |
+
"question": row.question,
|
129 |
+
"idx": row.idx,
|
130 |
+
"label": row.label,
|
131 |
+
"terminology": row.Terminology,
|
132 |
+
"culture": row.Culture,
|
133 |
+
"language": row.Language,
|
134 |
+
}
|
135 |
+
yield row.index, entry
|
136 |
+
|
137 |
+
elif self.config.schema == "seacrowd_qa":
|
138 |
+
for row in df.itertuples():
|
139 |
+
entry = {
|
140 |
+
"id": row.idx,
|
141 |
+
"question_id": str(row.idx),
|
142 |
+
"document_id": str(row.idx),
|
143 |
+
"question": row.question,
|
144 |
+
"type": "multiple_choice",
|
145 |
+
"choices": [row.choice1, row.choice2],
|
146 |
+
"context": row.premise,
|
147 |
+
"answer": [row.choice1 if row.label == 0 else row.choice2],
|
148 |
+
"meta": {"terminology": row.Terminology, "culture": row.Culture, "language": row.Language},
|
149 |
+
}
|
150 |
+
yield row.index, entry
|
151 |
+
else:
|
152 |
+
raise ValueError(f"Invalid config: {self.config.name}")
|