Elron commited on
Commit
5f04977
1 Parent(s): da8d65a

Upload templates.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. templates.py +13 -13
templates.py CHANGED
@@ -157,7 +157,7 @@ class MultipleChoiceTemplate(Template):
157
  target_prefix: str = ""
158
  choices_field: str = "choices"
159
  target_field: str = "label"
160
- choices_seperator: str = ", "
161
  source_choice_format: str = "{choice_numeral}. {choice_text}"
162
  target_choice_format: str = "{choice_numeral}"
163
  enumerator: str = "capitals"
@@ -217,7 +217,7 @@ class MultipleChoiceTemplate(Template):
217
  return {
218
  "numerals": self.inputs_to_numerals(inputs),
219
  **inputs,
220
- self.choices_field: self.choices_seperator.join(choices),
221
  }
222
 
223
  def inputs_to_source(self, inputs: Dict[str, object]) -> Tuple[str, str]:
@@ -358,10 +358,10 @@ class KeyValTemplate(Template):
358
  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').
359
  """
360
 
361
- pairs_seperator: str = ", "
362
- key_val_seperator: str = ": "
363
  use_keys_for_inputs: bool = True
364
- outputs_key_val_seperator: str = ": "
365
  use_keys_for_outputs: bool = False
366
 
367
  def process_dict(
@@ -377,16 +377,16 @@ class KeyValTemplate(Template):
377
  def inputs_to_source(self, inputs: Dict[str, object]) -> Tuple[str, str]:
378
  return self.process_dict(
379
  inputs,
380
- key_val_sep=self.key_val_seperator,
381
- pairs_sep=self.pairs_seperator,
382
  use_keys=self.use_keys_for_inputs,
383
  )
384
 
385
  def outputs_to_target_and_references(self, outputs: Dict[str, object]) -> str:
386
  target = self.process_dict(
387
  outputs,
388
- key_val_sep=self.key_val_seperator,
389
- pairs_sep=self.pairs_seperator,
390
  use_keys=self.use_keys_for_outputs,
391
  )
392
  return target, [target]
@@ -414,7 +414,7 @@ class OutputQuantizingTemplate(InputOutputTemplate):
414
 
415
  class MultiLabelTemplate(InputOutputTemplate):
416
  labels_field: str = "labels"
417
- labels_seprator: str = ", "
418
  postprocessors: List[str] = ["processors.to_list_by_comma"]
419
  output_format: str = "{labels}"
420
  empty_label: str = "None"
@@ -427,7 +427,7 @@ class MultiLabelTemplate(InputOutputTemplate):
427
  )
428
  if len(labels) == 0:
429
  labels = [self.empty_label]
430
- labels_str = self.labels_seprator.join(labels)
431
  return super().outputs_to_target_and_references({self.labels_field: labels_str})
432
 
433
 
@@ -485,8 +485,8 @@ class SpanLabelingBaseTemplate(MultiLabelTemplate):
485
  def outputs_to_target_and_references(
486
  self, outputs: Dict[str, object]
487
  ) -> Dict[str, object]:
488
- span_lables_pairs = self.extract_span_label_pairs(outputs)
489
- targets = self.span_label_pairs_to_targets(span_lables_pairs)
490
  return super().outputs_to_target_and_references({"labels": targets})
491
 
492
  @abstractmethod
 
157
  target_prefix: str = ""
158
  choices_field: str = "choices"
159
  target_field: str = "label"
160
+ choices_separator: str = ", "
161
  source_choice_format: str = "{choice_numeral}. {choice_text}"
162
  target_choice_format: str = "{choice_numeral}"
163
  enumerator: str = "capitals"
 
217
  return {
218
  "numerals": self.inputs_to_numerals(inputs),
219
  **inputs,
220
+ self.choices_field: self.choices_separator.join(choices),
221
  }
222
 
223
  def inputs_to_source(self, inputs: Dict[str, object]) -> Tuple[str, str]:
 
358
  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').
359
  """
360
 
361
+ pairs_separator: str = ", "
362
+ key_val_separator: str = ": "
363
  use_keys_for_inputs: bool = True
364
+ outputs_key_val_separator: str = ": "
365
  use_keys_for_outputs: bool = False
366
 
367
  def process_dict(
 
377
  def inputs_to_source(self, inputs: Dict[str, object]) -> Tuple[str, str]:
378
  return self.process_dict(
379
  inputs,
380
+ key_val_sep=self.key_val_separator,
381
+ pairs_sep=self.pairs_separator,
382
  use_keys=self.use_keys_for_inputs,
383
  )
384
 
385
  def outputs_to_target_and_references(self, outputs: Dict[str, object]) -> str:
386
  target = self.process_dict(
387
  outputs,
388
+ key_val_sep=self.key_val_separator,
389
+ pairs_sep=self.pairs_separator,
390
  use_keys=self.use_keys_for_outputs,
391
  )
392
  return target, [target]
 
414
 
415
  class MultiLabelTemplate(InputOutputTemplate):
416
  labels_field: str = "labels"
417
+ labels_separator: str = ", "
418
  postprocessors: List[str] = ["processors.to_list_by_comma"]
419
  output_format: str = "{labels}"
420
  empty_label: str = "None"
 
427
  )
428
  if len(labels) == 0:
429
  labels = [self.empty_label]
430
+ labels_str = self.labels_separator.join(labels)
431
  return super().outputs_to_target_and_references({self.labels_field: labels_str})
432
 
433
 
 
485
  def outputs_to_target_and_references(
486
  self, outputs: Dict[str, object]
487
  ) -> Dict[str, object]:
488
+ span_labels_pairs = self.extract_span_label_pairs(outputs)
489
+ targets = self.span_label_pairs_to_targets(span_labels_pairs)
490
  return super().outputs_to_target_and_references({"labels": targets})
491
 
492
  @abstractmethod