Datasets:

ArXiv:
Elron commited on
Commit
5f2e7a1
1 Parent(s): 038689a

Upload templates.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. templates.py +15 -2
templates.py CHANGED
@@ -60,6 +60,11 @@ class Template(StreamInstanceOperator):
60
 
61
 
62
  class InputOutputTemplate(Template):
 
 
 
 
 
63
  input_format: str = None
64
  output_format: str = None
65
 
@@ -88,6 +93,8 @@ class InputOutputTemplate(Template):
88
 
89
 
90
  class MultipleChoiceTemplate(Template):
 
 
91
  input_format: str
92
  target_prefix: str = ""
93
  choices_field: str = "choices"
@@ -264,6 +271,11 @@ class YesNoTemplate(Template):
264
 
265
 
266
  class KeyValTemplate(Template):
 
 
 
 
 
267
  pairs_seperator: str = ", "
268
  key_val_seperator: str = ": "
269
  use_keys_for_inputs: bool = True
@@ -312,9 +324,10 @@ class OutputQuantizingTemplate(InputOutputTemplate):
312
  quantum: float = 0.1
313
 
314
  def outputs_to_target_and_references(self, outputs: Dict[str, object]) -> str:
 
315
  quantized_outputs = {
316
- key: round(input_float / self.quantum) * self.quantum
317
- for key, input_float in outputs.items()
318
  }
319
  return super().outputs_to_target_and_references(quantized_outputs)
320
 
 
60
 
61
 
62
  class InputOutputTemplate(Template):
63
+ """Generate field 'source' from fields designated as input, and fields 'target' and 'references' from fields designated as output, of the processed instance.
64
+
65
+ Args specify the formatting strings with which to glue together the input and output designated fields of the processed instance into one string ('source' and 'target'), and into a list of strings ('references').
66
+ """
67
+
68
  input_format: str = None
69
  output_format: str = None
70
 
 
93
 
94
 
95
  class MultipleChoiceTemplate(Template):
96
+ """Formats the input (that specifies the question), the multiple choices to select the answer from, and specifies the field with the correct answer."""
97
+
98
  input_format: str
99
  target_prefix: str = ""
100
  choices_field: str = "choices"
 
271
 
272
 
273
  class KeyValTemplate(Template):
274
+ """Generate field 'source' from fields designated as input, and fields 'target' and 'references' from fields designated as output, of the processed instance.
275
+
276
+ Args specify with what separators to glue together the input and output designated fields of the processed instance into one string ('source' and 'target'), and into a list of strings ('references').
277
+ """
278
+
279
  pairs_seperator: str = ", "
280
  key_val_seperator: str = ": "
281
  use_keys_for_inputs: bool = True
 
324
  quantum: float = 0.1
325
 
326
  def outputs_to_target_and_references(self, outputs: Dict[str, object]) -> str:
327
+ quantum_str = f"{self.quantum:.10f}".rstrip("0").rstrip(".")
328
  quantized_outputs = {
329
+ key: f"{round(value / self.quantum) * self.quantum:{quantum_str}}"
330
+ for key, value in outputs.items()
331
  }
332
  return super().outputs_to_target_and_references(quantized_outputs)
333