Datasets:
File size: 8,946 Bytes
5b49ee1 8f15a82 5b49ee1 810f0e4 5b49ee1 088a242 5b49ee1 810f0e4 5b49ee1 2eebf1d 5b49ee1 810f0e4 5b49ee1 810f0e4 5b49ee1 088a242 5b49ee1 810f0e4 5b49ee1 810f0e4 5b49ee1 810f0e4 5b49ee1 810f0e4 5b49ee1 810f0e4 5b49ee1 810f0e4 5b49ee1 810f0e4 5b49ee1 810f0e4 5b49ee1 810f0e4 088a242 810f0e4 088a242 810f0e4 5b49ee1 810f0e4 088a242 5b49ee1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
"""Korean Balanced Evaluation of Significant Tasks"""
import csv
import pandas as pd
import datasets
_CITATAION = """\
@misc{https://doi.org/10.48550/arxiv.2204.04541,
doi = {10.48550/ARXIV.2204.04541},
url = {https://arxiv.org/abs/2204.04541},
author = {Kim, Dohyeong and Jang, Myeongjun and Kwon, Deuk Sin and Davis, Eric},
title = {KOBEST: Korean Balanced Evaluation of Significant Tasks},
publisher = {arXiv},
year = {2022},
}
"""
_DESCRIPTION = """\
The dataset contains data for KoBEST dataset
"""
_URL = "https://github.com/SKT-LSL/KoBEST_datarepo/raw/main"
_DATA_URLS = {
"boolq": {
"train": _URL + "/v1.0/BoolQ/train.tsv",
"dev": _URL + "/v1.0/BoolQ/dev.tsv",
"test": _URL + "/v1.0/BoolQ/test.tsv",
},
"copa": {
"train": _URL + "/v1.0/COPA/train.tsv",
"dev": _URL + "/v1.0/COPA/dev.tsv",
"test": _URL + "/v1.0/COPA/test.tsv",
},
"sentineg": {
"train": _URL + "/v1.0/SentiNeg/train.tsv",
"dev": _URL + "/v1.0/SentiNeg/dev.tsv",
"test": _URL + "/v1.0/SentiNeg/test.tsv",
"test_originated": _URL + "/v1.0/SentiNeg/test.tsv",
},
"hellaswag": {
"train": _URL + "/v1.0/HellaSwag/train.tsv",
"dev": _URL + "/v1.0/HellaSwag/dev.tsv",
"test": _URL + "/v1.0/HellaSwag/test.tsv",
},
"wic": {
"train": _URL + "/v1.0/WiC/train.tsv",
"dev": _URL + "/v1.0/WiC/dev.tsv",
"test": _URL + "/v1.0/WiC/test.tsv",
},
}
_LICENSE = "CC-BY-SA-4.0"
class KoBESTConfig(datasets.BuilderConfig):
"""Config for building KoBEST"""
def __init__(self, description, data_url, citation, url, **kwargs):
"""
Args:
description: `string`, brief description of the dataset
data_url: `dictionary`, dict with url for each split of data.
citation: `string`, citation for the dataset.
url: `string`, url for information about the dataset.
**kwrags: keyword arguments frowarded to super
"""
super(KoBESTConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
self.description = description
self.data_url = data_url
self.citation = citation
self.url = url
class KoBEST(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
KoBESTConfig(name=name, description=_DESCRIPTION, data_url=_DATA_URLS[name], citation=_CITATAION, url=_URL)
for name in ["boolq", "copa", 'sentineg', 'hellaswag', 'wic']
]
BUILDER_CONFIG_CLASS = KoBESTConfig
def _info(self):
features = {}
if self.config.name == "boolq":
labels = ["False", "True"]
features["paragraph"] = datasets.Value("string")
features["question"] = datasets.Value("string")
features["label"] = datasets.features.ClassLabel(names=labels)
if self.config.name == "copa":
labels = ["alternative_1", "alternative_2"]
features["premise"] = datasets.Value("string")
features["question"] = datasets.Value("string")
features["alternative_1"] = datasets.Value("string")
features["alternative_2"] = datasets.Value("string")
features["label"] = datasets.features.ClassLabel(names=labels)
if self.config.name == "wic":
labels = ["False", "True"]
features["word"] = datasets.Value("string")
features["context_1"] = datasets.Value("string")
features["context_2"] = datasets.Value("string")
features["label"] = datasets.features.ClassLabel(names=labels)
if self.config.name == "hellaswag":
labels = ["ending_1", "ending_2", "ending_3", "ending_4"]
features["context"] = datasets.Value("string")
features["ending_1"] = datasets.Value("string")
features["ending_2"] = datasets.Value("string")
features["ending_3"] = datasets.Value("string")
features["ending_4"] = datasets.Value("string")
features["label"] = datasets.features.ClassLabel(names=labels)
if self.config.name == "sentineg":
labels = ["negative", "positive"]
features["sentence"] = datasets.Value("string")
features["label"] = datasets.features.ClassLabel(names=labels)
return datasets.DatasetInfo(
description=_DESCRIPTION, features=datasets.Features(features), homepage=_URL, citation=_CITATAION
)
def _split_generators(self, dl_manager):
train = dl_manager.download_and_extract(self.config.data_url["train"])
dev = dl_manager.download_and_extract(self.config.data_url["dev"])
test = dl_manager.download_and_extract(self.config.data_url["test"])
if self.config.data_url.get("test_originated"):
test_originated = dl_manager.download_and_extract(self.config.data_url["test_originated"])
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train, "split": "train"}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": dev, "split": "dev"}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test, "split": "test"}),
datasets.SplitGenerator(name="test_originated", gen_kwargs={"filepath": test_originated, "split": "test_originated"}),
]
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train, "split": "train"}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": dev, "split": "dev"}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test, "split": "test"}),
]
def _generate_examples(self, filepath, split):
if self.config.name == "boolq":
df = pd.read_csv(filepath, sep="\t")
df = df.dropna()
df = df[['Text', 'Question', 'Answer']]
df = df.rename(columns={
'Text': 'paragraph',
'Question': 'question',
'Answer': 'label',
})
df['label'] = [0 if str(s) == 'False' else 1 for s in df['label'].tolist()]
elif self.config.name == "copa":
df = pd.read_csv(filepath, sep="\t")
df = df.dropna()
df = df[['sentence', 'question', '1', '2', 'Answer']]
df = df.rename(columns={
'sentence': 'premise',
'question': 'question',
'1': 'alternative_1',
'2': 'alternative_2',
'Answer': 'label',
})
df['label'] = [i-1 for i in df['label'].tolist()]
elif self.config.name == "wic":
df = pd.read_csv(filepath, sep="\t")
df = df.dropna()
df = df[['Target', 'SENTENCE1', 'SENTENCE2', 'ANSWER']]
df = df.rename(columns={
'Target': 'word',
'SENTENCE1': 'context_1',
'SENTENCE2': 'context_2',
'ANSWER': 'label',
})
df['label'] = [0 if str(s) == 'False' else 1 for s in df['label'].tolist()]
elif self.config.name == "hellaswag":
df = pd.read_csv(filepath, sep="\t")
df = df.dropna()
df = df[['context', 'choice1', 'choice2', 'choice3', 'choice4', 'label']]
df = df.rename(columns={
'context': 'context',
'choice1': 'ending_1',
'choice2': 'ending_2',
'choice3': 'ending_3',
'choice4': 'ending_4',
'label': 'label',
})
elif self.config.name == "sentineg":
df = pd.read_csv(filepath, sep="\t")
df = df.dropna()
if split == "test_originated":
df = df[['Text_origin', 'Label_origin']]
df = df.rename(columns={
'Text_origin': 'sentence',
'Label_origin': 'label',
})
else:
df = df[['Text', 'Label']]
df = df.rename(columns={
'Text': 'sentence',
'Label': 'label',
})
else:
raise NotImplementedError
for id_, row in df.iterrows():
features = {key: row[key] for key in row.keys()}
yield id_, features
if __name__ == "__main__":
dataset = datasets.load_dataset("kobest_v1.py", 'sentineg', ignore_verifications=True)
ds = dataset['test_originated']
print(ds)
# for task in ['boolq', 'copa', 'wic', 'hellaswag', 'sentineg']:
# dataset = datasets.load_dataset("kobest_v1.py", task, ignore_verifications=True)
# print(dataset)
# print(dataset['train']['label'])
|