jmnybl commited on
Commit
2ef61f9
1 Parent(s): 4a159ce

added target and references

Browse files
Files changed (1) hide show
  1. turku_paraphrase_corpus.py +21 -6
turku_paraphrase_corpus.py CHANGED
@@ -89,7 +89,8 @@ class TurkuParaphraseCorpus(datasets.GeneratorBasedBuilder):
89
  "goeswith": datasets.Value("string"),
90
  "fold": datasets.Value("int32"),
91
  "input": datasets.Value("string"),
92
- "output": datasets.Value("string"),
 
93
  "label": datasets.Value("string"),
94
  "binary_label": datasets.Value("string"),
95
  "is_rewrite": datasets.Value("bool"),
@@ -103,6 +104,8 @@ class TurkuParaphraseCorpus(datasets.GeneratorBasedBuilder):
103
  "fold": datasets.Value("int32"),
104
  "text1": datasets.Value("string"),
105
  "text2": datasets.Value("string"),
 
 
106
  "label": datasets.Value("string"),
107
  "binary_label": datasets.Value("string"),
108
  "is_rewrite": datasets.Value("bool"),
@@ -173,7 +176,7 @@ class TurkuParaphraseCorpus(datasets.GeneratorBasedBuilder):
173
  "goeswith": orig_example["goeswith"] if orig_example["goeswith"]!=None else "not available",
174
  "fold": orig_example["fold"],
175
  "input": orig_example["txt1"],
176
- "output": orig_example["txt2"],
177
  "label": orig_example["label"],
178
  "binary_label": "positive" if orig_example["label"] != "2" else "negative",
179
  "is_rewrite": False}
@@ -183,15 +186,20 @@ class TurkuParaphraseCorpus(datasets.GeneratorBasedBuilder):
183
  if ">" in label:
184
  processed.append(d)
185
  elif "<" in label:
186
- processed.append(self._flip_example(d, "input", "output"))
187
  else:
188
  processed.append(d)
189
- processed.append(self._flip_example(d, "input", "output"))
190
 
191
  for rew in orig_example["rewrites"]:
192
- r = self._generate_rew(d, rew, "input", "output")
193
  processed.append(r)
194
- processed.append(self._flip_example(r, "input", "output"))
 
 
 
 
 
195
  return processed
196
 
197
  def _prepare_plain_and_classification(self, orig_example):
@@ -214,6 +222,12 @@ class TurkuParaphraseCorpus(datasets.GeneratorBasedBuilder):
214
  processed.append(r)
215
  if self.config.name == "classification":
216
  processed.append(self._flip_example(d, "text1", "text2"))
 
 
 
 
 
 
217
  return processed
218
 
219
  def _generate_rew(self, orig, rew, field1, field2):
@@ -238,5 +252,6 @@ class TurkuParaphraseCorpus(datasets.GeneratorBasedBuilder):
238
  flipped["label"] = example["label"].replace(">", "<")
239
  flipped[field1] = example[field2]
240
  flipped[field2] = example[field1]
 
241
  return flipped
242
 
89
  "goeswith": datasets.Value("string"),
90
  "fold": datasets.Value("int32"),
91
  "input": datasets.Value("string"),
92
+ "target": datasets.Value("string"),
93
+ "references": [datasets.Value("string")],
94
  "label": datasets.Value("string"),
95
  "binary_label": datasets.Value("string"),
96
  "is_rewrite": datasets.Value("bool"),
104
  "fold": datasets.Value("int32"),
105
  "text1": datasets.Value("string"),
106
  "text2": datasets.Value("string"),
107
+ "target": datasets.Value("string"),
108
+ "references": [datasets.Value("string")],
109
  "label": datasets.Value("string"),
110
  "binary_label": datasets.Value("string"),
111
  "is_rewrite": datasets.Value("bool"),
176
  "goeswith": orig_example["goeswith"] if orig_example["goeswith"]!=None else "not available",
177
  "fold": orig_example["fold"],
178
  "input": orig_example["txt1"],
179
+ "target": orig_example["txt2"],
180
  "label": orig_example["label"],
181
  "binary_label": "positive" if orig_example["label"] != "2" else "negative",
182
  "is_rewrite": False}
186
  if ">" in label:
187
  processed.append(d)
188
  elif "<" in label:
189
+ processed.append(self._flip_example(d, "input", "target"))
190
  else:
191
  processed.append(d)
192
+ processed.append(self._flip_example(d, "input", "target"))
193
 
194
  for rew in orig_example["rewrites"]:
195
+ r = self._generate_rew(d, rew, "input", "target")
196
  processed.append(r)
197
+ processed.append(self._flip_example(r, "input", "target"))
198
+
199
+
200
+ # add references (copy target to references field)
201
+ for i in range(len(processed)):
202
+ processed[i]["references"] = [processed[i]["target"]]
203
  return processed
204
 
205
  def _prepare_plain_and_classification(self, orig_example):
222
  processed.append(r)
223
  if self.config.name == "classification":
224
  processed.append(self._flip_example(d, "text1", "text2"))
225
+
226
+ # add empty references, and add target (copy label to target)
227
+ for i in range(len(processed)):
228
+ processed[i]["references"] = []
229
+ processed[i]["target"] = processed[i]["label"]
230
+
231
  return processed
232
 
233
  def _generate_rew(self, orig, rew, field1, field2):
252
  flipped["label"] = example["label"].replace(">", "<")
253
  flipped[field1] = example[field2]
254
  flipped[field2] = example[field1]
255
+
256
  return flipped
257