holylovenia commited on
Commit
e056be5
·
1 Parent(s): 2ed9f3d

Upload wrete.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. wrete.py +148 -0
wrete.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from sys import stdout
3
+ from tempfile import tempdir
4
+ from typing import List
5
+ from unicodedata import category
6
+
7
+ import datasets
8
+ import pandas as pd
9
+
10
+ from nusacrowd.utils import schemas
11
+ from nusacrowd.utils.configs import NusantaraConfig
12
+ from nusacrowd.utils.constants import Tasks, DEFAULT_SOURCE_VIEW_NAME, DEFAULT_NUSANTARA_VIEW_NAME
13
+
14
+ _DATASETNAME = "wrete"
15
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
16
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
17
+
18
+ _LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
19
+ _LOCAL = False
20
+ _CITATION = """\
21
+ @INPROCEEDINGS{8904199,
22
+ author={Purwarianti, Ayu and Crisdayanti, Ida Ayu Putu Ari},
23
+ booktitle={2019 International Conference of Advanced Informatics: Concepts, Theory and Applications (ICAICTA)},
24
+ title={Improving Bi-LSTM Performance for Indonesian Sentiment Analysis Using Paragraph Vector},
25
+ year={2019},
26
+ pages={1-5},
27
+ doi={10.1109/ICAICTA.2019.8904199}
28
+ }
29
+
30
+ @inproceedings{wilie2020indonlu,
31
+ title={IndoNLU: Benchmark and Resources for Evaluating Indonesian Natural Language Understanding},
32
+ author={Wilie, Bryan and Vincentio, Karissa and Winata, Genta Indra and Cahyawijaya, Samuel and Li, Xiaohong and Lim, Zhi Yuan and Soleman, Sidik and Mahendra, Rahmad and Fung, Pascale and Bahar, Syafri and others},
33
+ booktitle={Proceedings of the 1st Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the 10th International Joint Conference on Natural Language Processing},
34
+ pages={843--857},
35
+ year={2020}
36
+ }
37
+ """
38
+
39
+
40
+ _DESCRIPTION = """\
41
+ WReTe, The Wiki Revision Edits Textual Entailment dataset (Setya and Mahendra, 2018) consists of 450 sentence pairs constructed from Wikipedia revision history. The dataset contains pairs of sentences and binary semantic relations between the pairs. The data are labeled as entailed when the meaning of the second sentence can be derived from the first one, and not entailed otherwise
42
+ """
43
+
44
+ _HOMEPAGE = "https://github.com/IndoNLP/indonlu"
45
+
46
+ _LICENSE = "Creative Common Attribution Share-Alike 4.0 International"
47
+
48
+ _URLs = {
49
+ "train": "https://github.com/IndoNLP/indonlu/raw/master/dataset/wrete_entailment-ui/train_preprocess.csv",
50
+ "validation": "https://github.com/IndoNLP/indonlu/raw/master/dataset/wrete_entailment-ui/valid_preprocess.csv",
51
+ "test": "https://github.com/IndoNLP/indonlu/raw/master/dataset/wrete_entailment-ui/test_preprocess_masked_label.csv",
52
+ }
53
+
54
+ _SUPPORTED_TASKS = [Tasks.TEXTUAL_ENTAILMENT]
55
+
56
+ _SOURCE_VERSION = "1.0.0"
57
+ _NUSANTARA_VERSION = "1.0.0"
58
+
59
+
60
+ class WReTe(datasets.GeneratorBasedBuilder):
61
+ """WReTe consists of premise, hypothesis, category, and label. The Data are labeled as entailed when the meaning of the second sentence can be derived from the first one, and not entailed otherwise"""
62
+
63
+ BUILDER_CONFIGS = [
64
+ NusantaraConfig(
65
+ name="wrete_source",
66
+ version=datasets.Version(_SOURCE_VERSION),
67
+ description="WReTe source schema",
68
+ schema="source",
69
+ subset_id="wrete",
70
+ ),
71
+ NusantaraConfig(
72
+ name="wrete_nusantara_pairs",
73
+ version=datasets.Version(_NUSANTARA_VERSION),
74
+ description="WReTe Nusantara schema",
75
+ schema="nusantara_pairs",
76
+ subset_id="wrete",
77
+ ),
78
+ ]
79
+
80
+ DEFAULT_CONFIG_NAME = "wrete_source"
81
+ labels = ["NotEntail", "Entail_or_Paraphrase"]
82
+
83
+ def _info(self):
84
+ if self.config.schema == "source":
85
+ features = datasets.Features({"index": datasets.Value("int32"),
86
+ "sent_A": datasets.Value("string"),
87
+ "sent_B": datasets.Value("string"),
88
+ "category" : datasets.Value("string"),
89
+ "label": datasets.Value("string")})
90
+ elif self.config.schema == "nusantara_pairs":
91
+ features = schemas.pairs_features(self.labels)
92
+
93
+ return datasets.DatasetInfo(
94
+ description=_DESCRIPTION,
95
+ features=features,
96
+ homepage=_HOMEPAGE,
97
+ license=_LICENSE,
98
+ citation=_CITATION,
99
+ )
100
+
101
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
102
+ train_csv_path = Path(dl_manager.download_and_extract(_URLs["train"]))
103
+ validation_csv_path = Path(dl_manager.download_and_extract(_URLs["validation"]))
104
+ test_csv_path = Path(dl_manager.download_and_extract(_URLs["test"]))
105
+ data_files = {
106
+ "train": train_csv_path,
107
+ "validation": validation_csv_path,
108
+ "test": test_csv_path,
109
+ }
110
+
111
+ return [
112
+ datasets.SplitGenerator(
113
+ name=datasets.Split.TRAIN,
114
+ gen_kwargs={"filepath": data_files["train"]},
115
+ ),
116
+ datasets.SplitGenerator(
117
+ name=datasets.Split.VALIDATION,
118
+ gen_kwargs={"filepath": data_files["validation"]},
119
+ ),
120
+ datasets.SplitGenerator(
121
+ name=datasets.Split.TEST,
122
+ gen_kwargs={"filepath": data_files["test"]},
123
+ ),
124
+ ]
125
+
126
+ def _generate_examples(self, filepath: Path):
127
+ df = pd.read_csv(filepath, sep=",", quotechar='"').reset_index()
128
+
129
+ if self.config.schema == "source":
130
+ for row in df.itertuples():
131
+ ex = {"index": row.index,
132
+ "sent_A" : row.sent_A,
133
+ "sent_B" : row.sent_B,
134
+ "category" : row.category,
135
+ "label" : row.label
136
+ }
137
+ yield row.index, ex
138
+ elif self.config.schema == "nusantara_pairs":
139
+ for row in df.itertuples():
140
+ ex = {
141
+ "id": row.index,
142
+ "text_1": row.sent_A,
143
+ "text_2": row.sent_B,
144
+ "label": row.label
145
+ }
146
+ yield row.index, ex
147
+ else:
148
+ raise ValueError(f"Invalid config: {self.config.name}")