holylovenia commited on
Commit
69e4b62
1 Parent(s): 3b93899

Upload id_sts.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. id_sts.py +123 -0
id_sts.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from typing import Dict, List, Tuple
3
+
4
+ import datasets
5
+ import pandas as pd
6
+
7
+ from nusacrowd.utils import schemas
8
+ from nusacrowd.utils.configs import NusantaraConfig
9
+ from nusacrowd.utils.constants import Tasks
10
+
11
+ _CITATION = """
12
+ """
13
+
14
+ _DATASETNAME = "id_sts"
15
+
16
+ _DESCRIPTION = """\
17
+ SemEval is a series of international natural language processing (NLP) research workshops whose mission is
18
+ to advance the current state of the art in semantic analysis and to help create high-quality annotated datasets in a
19
+ range of increasingly challenging problems in natural language semantics. This is a translated version of SemEval Dataset
20
+ from 2012-2016 for Semantic Textual Similarity Task to Indonesian language.
21
+ """
22
+
23
+ _HOMEPAGE = "https://github.com/ahmadizzan/sts-indo"
24
+
25
+ _LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
26
+ _LOCAL = False
27
+
28
+ _LICENSE = "Unknown"
29
+
30
+ _URLS = {
31
+ _DATASETNAME: {
32
+ "train": "https://raw.githubusercontent.com/ahmadizzan/sts-indo/master/data/final-data/train.tsv",
33
+ "test": "https://raw.githubusercontent.com/ahmadizzan/sts-indo/master/data/final-data/test.tsv",
34
+ }
35
+ }
36
+
37
+ _SUPPORTED_TASKS = [Tasks.SEMANTIC_SIMILARITY]
38
+
39
+ _SOURCE_VERSION = "1.0.0"
40
+
41
+ _NUSANTARA_VERSION = "1.0.0"
42
+
43
+
44
+ class IdSts(datasets.GeneratorBasedBuilder):
45
+ """id_sts, translated version of SemEval Dataset
46
+ from 2012-2016 for Semantic Textual Similarity Task to Indonesian language"""
47
+
48
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
49
+ NUSANTARA_VERSION = datasets.Version(_NUSANTARA_VERSION)
50
+
51
+ BUILDER_CONFIGS = [
52
+ NusantaraConfig(
53
+ name="id_sts_source",
54
+ version=SOURCE_VERSION,
55
+ description="ID_STS source schema",
56
+ schema="source",
57
+ subset_id="id_sts",
58
+ ),
59
+ NusantaraConfig(
60
+ name="id_sts_nusantara_pairs_score",
61
+ version=NUSANTARA_VERSION,
62
+ description="ID_STS Nusantara schema",
63
+ schema="nusantara_pairs_score",
64
+ subset_id="id_sts",
65
+ ),
66
+ ]
67
+
68
+ DEFAULT_CONFIG_NAME = "id_sts_source"
69
+
70
+ def _info(self) -> datasets.DatasetInfo:
71
+
72
+ if self.config.schema == "source":
73
+ features = datasets.Features(
74
+ {
75
+ "text_1": datasets.Value("string"),
76
+ "text_2": datasets.Value("string"),
77
+ "label": datasets.Value("float64"),
78
+ }
79
+ )
80
+ elif self.config.schema == "nusantara_pairs_score":
81
+ features = schemas.pairs_features_score()
82
+
83
+ return datasets.DatasetInfo(
84
+ description=_DESCRIPTION,
85
+ features=features,
86
+ homepage=_HOMEPAGE,
87
+ license=_LICENSE,
88
+ citation=_CITATION,
89
+ )
90
+
91
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
92
+ urls = _URLS[_DATASETNAME]
93
+ train_data_path = Path(dl_manager.download(urls["train"]))
94
+ test_data_path = Path(dl_manager.download(urls["test"]))
95
+
96
+ return [
97
+ datasets.SplitGenerator(
98
+ name=datasets.Split.TRAIN,
99
+ gen_kwargs={"filepath": train_data_path, "split": "train"},
100
+ ),
101
+ datasets.SplitGenerator(
102
+ name=datasets.Split.TEST,
103
+ gen_kwargs={"filepath": test_data_path, "split": "test"},
104
+ ),
105
+ ]
106
+
107
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
108
+ """Yields examples as (key, example) tuples."""
109
+ # Dataset does not have id, using row index as id
110
+ df = pd.read_csv(filepath, delimiter="\t").reset_index()
111
+ df.columns = ["id", "score", "original_text_1", "original_text_2", "source", "text_1", "text_2"]
112
+
113
+ if self.config.schema == "source":
114
+ for row in df.itertuples():
115
+ ex = {"text_1": row.text_1, "text_2": row.text_2, "label": row.score}
116
+ yield row.id, ex
117
+
118
+ elif self.config.schema == "nusantara_pairs_score":
119
+ for row in df.itertuples():
120
+ ex = {"id": str(row.id), "text_1": row.text_1, "text_2": row.text_2, "label": row.score}
121
+ yield row.id, ex
122
+ else:
123
+ raise ValueError(f"Invalid config: {self.config.name}")