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
+
from pathlib import Path
|
| 3 |
+
from typing import Dict, List, Tuple
|
| 4 |
+
|
| 5 |
+
import datasets
|
| 6 |
+
|
| 7 |
+
from nusacrowd.utils.configs import NusantaraConfig
|
| 8 |
+
from nusacrowd.utils.constants import Tasks
|
| 9 |
+
from nusacrowd.utils import schemas
|
| 10 |
+
import json
|
| 11 |
+
|
| 12 |
+
_CITATION = """\
|
| 13 |
+
@misc{quoraFirstQuora,
|
| 14 |
+
author = {},
|
| 15 |
+
title = {{F}irst {Q}uora {D}ataset {R}elease: {Q}uestion {P}airs --- quoradata.quora.com},
|
| 16 |
+
howpublished = {https://quoradata.quora.com/First-Quora-Dataset-Release-Question-Pairs},
|
| 17 |
+
year = 2017,
|
| 18 |
+
note = {Online},
|
| 19 |
+
}
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
_LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
| 23 |
+
_LOCAL = False
|
| 24 |
+
|
| 25 |
+
_DATASETNAME = "id_qqp"
|
| 26 |
+
|
| 27 |
+
_DESCRIPTION = """\
|
| 28 |
+
Quora Question Pairs (QQP) dataset consists of over 400,000 question pairs,
|
| 29 |
+
and each question pair is annotated with a binary value indicating whether
|
| 30 |
+
the two questions are paraphrase of each other. This dataset is translated
|
| 31 |
+
version of QQP to Indonesian Language.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
_HOMEPAGE = "https://github.com/louisowen6/quora_paraphrasing_id"
|
| 35 |
+
|
| 36 |
+
_LICENSE = "Apache License, Version 2.0"
|
| 37 |
+
|
| 38 |
+
_URLS = {
|
| 39 |
+
_DATASETNAME: [
|
| 40 |
+
"https://github.com/louisowen6/quora_paraphrasing_id/raw/main/ID_Quora_Paraphrasing_train.json",
|
| 41 |
+
"https://github.com/louisowen6/quora_paraphrasing_id/raw/main/ID_Quora_Paraphrasing_val.json",
|
| 42 |
+
]
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
_SUPPORTED_TASKS = [Tasks.PARAPHRASING]
|
| 46 |
+
|
| 47 |
+
_SOURCE_VERSION = "1.0.0"
|
| 48 |
+
|
| 49 |
+
_NUSANTARA_VERSION = "1.0.0"
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class IdQuoraQuestionPairs(datasets.GeneratorBasedBuilder):
|
| 53 |
+
"""
|
| 54 |
+
Quora Question Pairs (QQP) dataset consists of over 400,000 question pairs,
|
| 55 |
+
and each question pair is annotated with a binary value indicating whether
|
| 56 |
+
the two questions are paraphrase of each other. This dataset is translated
|
| 57 |
+
version of QQP to Indonesian Language.
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 61 |
+
NUSANTARA_VERSION = datasets.Version(_NUSANTARA_VERSION)
|
| 62 |
+
|
| 63 |
+
BUILDER_CONFIGS = [
|
| 64 |
+
NusantaraConfig(
|
| 65 |
+
name="id_qqp_source",
|
| 66 |
+
version=SOURCE_VERSION,
|
| 67 |
+
description="ID QQP source schema",
|
| 68 |
+
schema="source",
|
| 69 |
+
subset_id="id_qqp",
|
| 70 |
+
),
|
| 71 |
+
NusantaraConfig(
|
| 72 |
+
name="id_qqp_nusantara_t2t",
|
| 73 |
+
version=NUSANTARA_VERSION,
|
| 74 |
+
description="ID QQP Nusantara schema",
|
| 75 |
+
schema="nusantara_t2t",
|
| 76 |
+
subset_id="id_qqp",
|
| 77 |
+
),
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
DEFAULT_CONFIG_NAME = "id_qqp_source"
|
| 81 |
+
|
| 82 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 83 |
+
|
| 84 |
+
if self.config.schema == "source":
|
| 85 |
+
|
| 86 |
+
features = datasets.Features(
|
| 87 |
+
{
|
| 88 |
+
"id": datasets.Value("string"),
|
| 89 |
+
"question_1": datasets.Value("string"),
|
| 90 |
+
"question_2": datasets.Value("string")
|
| 91 |
+
}
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
elif self.config.schema == "nusantara_t2t":
|
| 95 |
+
features = schemas.text2text_features
|
| 96 |
+
|
| 97 |
+
return datasets.DatasetInfo(
|
| 98 |
+
description=_DESCRIPTION,
|
| 99 |
+
features=features,
|
| 100 |
+
homepage=_HOMEPAGE,
|
| 101 |
+
license=_LICENSE,
|
| 102 |
+
citation=_CITATION,
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 107 |
+
urls = _URLS[_DATASETNAME]
|
| 108 |
+
data_dir = dl_manager.download_and_extract(urls)
|
| 109 |
+
return [
|
| 110 |
+
datasets.SplitGenerator(
|
| 111 |
+
name=datasets.Split.TRAIN,
|
| 112 |
+
gen_kwargs={
|
| 113 |
+
"filepath": data_dir[0],
|
| 114 |
+
},
|
| 115 |
+
),
|
| 116 |
+
datasets.SplitGenerator(
|
| 117 |
+
name=datasets.Split.VALIDATION,
|
| 118 |
+
gen_kwargs={
|
| 119 |
+
"filepath": data_dir[1],
|
| 120 |
+
},
|
| 121 |
+
),
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
def _generate_examples(self, filepath: Path) -> Tuple[int, Dict]:
|
| 125 |
+
|
| 126 |
+
with open(filepath, "r") as f:
|
| 127 |
+
lines = f.readlines()
|
| 128 |
+
|
| 129 |
+
if self.config.schema == "source":
|
| 130 |
+
|
| 131 |
+
for i, line in enumerate(lines):
|
| 132 |
+
line = json.loads(line.strip())
|
| 133 |
+
|
| 134 |
+
sample = {
|
| 135 |
+
"id": str(i),
|
| 136 |
+
"question_1": line["question_1"],
|
| 137 |
+
"question_2": line["question_2"]
|
| 138 |
+
}
|
| 139 |
+
yield i, sample
|
| 140 |
+
|
| 141 |
+
elif self.config.schema == "nusantara_t2t":
|
| 142 |
+
|
| 143 |
+
for i, line in enumerate(lines):
|
| 144 |
+
line = json.loads(line.strip())
|
| 145 |
+
|
| 146 |
+
sample = {
|
| 147 |
+
"id": str(i),
|
| 148 |
+
"text_1": line["question_1"],
|
| 149 |
+
"text_2": line["question_2"],
|
| 150 |
+
"text_1_name": "question_1",
|
| 151 |
+
"text_2_name": "question_2"
|
| 152 |
+
}
|
| 153 |
+
yield i, sample
|