Elron commited on
Commit
4aee30b
1 Parent(s): e1bc3cc

Upload dialog_operators.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. dialog_operators.py +9 -9
dialog_operators.py CHANGED
@@ -36,9 +36,9 @@ class SerializeDialog(InstanceFieldOperator):
36
  format: Optional[SystemFormat] = None
37
  last_response_to_field: Optional[str] = None
38
  context_field: Optional[str] = None
39
- context_seperator: str = " "
40
 
41
- def standartize_format(self, demo_format):
42
  turn_format = demo_format.replace("{source}", "{user}")
43
  turn_format = turn_format.replace("{target}", "{system}")
44
  return turn_format.replace("{target_prefix}", "")
@@ -49,7 +49,7 @@ class SerializeDialog(InstanceFieldOperator):
49
  def slice_last_turn(self, turn_format):
50
  return turn_format[: turn_format.index("{system}") + len("{system}")]
51
 
52
- def slice_last_reponse(self, turn_format):
53
  return turn_format[: turn_format.index("{user}") + len("{user}")]
54
 
55
  def get_turn_format(self, turn_format, step, length):
@@ -58,7 +58,7 @@ class SerializeDialog(InstanceFieldOperator):
58
  if step == length - 1:
59
  turn_format = self.slice_last_turn(turn_format)
60
  if self.last_response_to_field is not None:
61
- turn_format = self.slice_last_reponse(turn_format)
62
  return turn_format
63
 
64
  def get_general_turn_format(self, instance):
@@ -67,20 +67,20 @@ class SerializeDialog(InstanceFieldOperator):
67
  if self.format is None
68
  else self.format
69
  )
70
- return self.standartize_format(general_format.demo_format)
71
 
72
  def process_instance_value(
73
- self, structred_dialog: List[Dict[str, str]], instance: Dict[str, Any]
74
  ):
75
  dialog = (
76
  ""
77
  if self.context_field is None
78
- else instance[self.context_field] + self.context_seperator
79
  )
80
  general_turn_format = self.get_general_turn_format(instance)
81
- for i, turn in enumerate(structred_dialog):
82
  turn_format = self.get_turn_format(
83
- general_turn_format, i, len(structred_dialog)
84
  )
85
  dialog += turn_format.format(**turn)
86
  if self.last_response_to_field is not None:
 
36
  format: Optional[SystemFormat] = None
37
  last_response_to_field: Optional[str] = None
38
  context_field: Optional[str] = None
39
+ context_separator: str = " "
40
 
41
+ def standardize_format(self, demo_format):
42
  turn_format = demo_format.replace("{source}", "{user}")
43
  turn_format = turn_format.replace("{target}", "{system}")
44
  return turn_format.replace("{target_prefix}", "")
 
49
  def slice_last_turn(self, turn_format):
50
  return turn_format[: turn_format.index("{system}") + len("{system}")]
51
 
52
+ def slice_last_response(self, turn_format):
53
  return turn_format[: turn_format.index("{user}") + len("{user}")]
54
 
55
  def get_turn_format(self, turn_format, step, length):
 
58
  if step == length - 1:
59
  turn_format = self.slice_last_turn(turn_format)
60
  if self.last_response_to_field is not None:
61
+ turn_format = self.slice_last_response(turn_format)
62
  return turn_format
63
 
64
  def get_general_turn_format(self, instance):
 
67
  if self.format is None
68
  else self.format
69
  )
70
+ return self.standardize_format(general_format.demo_format)
71
 
72
  def process_instance_value(
73
+ self, structured_dialog: List[Dict[str, str]], instance: Dict[str, Any]
74
  ):
75
  dialog = (
76
  ""
77
  if self.context_field is None
78
+ else instance[self.context_field] + self.context_separator
79
  )
80
  general_turn_format = self.get_general_turn_format(instance)
81
+ for i, turn in enumerate(structured_dialog):
82
  turn_format = self.get_turn_format(
83
+ general_turn_format, i, len(structured_dialog)
84
  )
85
  dialog += turn_format.format(**turn)
86
  if self.last_response_to_field is not None: