Upload templates.py with huggingface_hub
Browse files156 unmodified lines15715815916016116216353 unmodified lines217218219220221222223134 unmodified lines3583593603613623633643653663679 unmodified lines37737837938038138238338438538638738838939039139221 unmodified lines4144154164174184194206 unmodified lines42742842943043143243351 unmodified lines485486487488489490491492156 unmodified linestarget_prefix: str = ""choices_field: str = "choices"target_field: str = "label"choices_seperator: str = ", "source_choice_format: str = "{choice_numeral}. {choice_text}"target_choice_format: str = "{choice_numeral}"enumerator: str = "capitals"53 unmodified linesreturn {"numerals": self.inputs_to_numerals(inputs),**inputs,self.choices_field: self.choices_seperator.join(choices),}def inputs_to_source(self, inputs: Dict[str, object]) -> Tuple[str, str]:134 unmodified linesArgs 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')."""pairs_seperator: str = ", "key_val_seperator: str = ": "use_keys_for_inputs: bool = Trueoutputs_key_val_seperator: str = ": "use_keys_for_outputs: bool = Falsedef process_dict(9 unmodified linesdef inputs_to_source(self, inputs: Dict[str, object]) -> Tuple[str, str]:return self.process_dict(inputs,key_val_sep=self.key_val_seperator,pairs_sep=self.pairs_seperator,use_keys=self.use_keys_for_inputs,)def outputs_to_target_and_references(self, outputs: Dict[str, object]) -> str:target = self.process_dict(outputs,key_val_sep=self.key_val_seperator,pairs_sep=self.pairs_seperator,use_keys=self.use_keys_for_outputs,)return target, [target]21 unmodified linesclass MultiLabelTemplate(InputOutputTemplate):labels_field: str = "labels"labels_seprator: str = ", "postprocessors: List[str] = ["processors.to_list_by_comma"]output_format: str = "{labels}"empty_label: str = "None"6 unmodified lines)if len(labels) == 0:labels = [self.empty_label]labels_str = self.labels_seprator.join(labels)return super().outputs_to_target_and_references({self.labels_field: labels_str})51 unmodified linesdef outputs_to_target_and_references(self, outputs: Dict[str, object]) -> Dict[str, object]:span_lables_pairs = self.extract_span_label_pairs(outputs)targets = self.span_label_pairs_to_targets(span_lables_pairs)return super().outputs_to_target_and_references({"labels": targets})@abstractmethod156 unmodified lines15715815916016116216353 unmodified lines217218219220221222223134 unmodified lines3583593603613623633643653663679 unmodified lines37737837938038138238338438538638738838939039139221 unmodified lines4144154164174184194206 unmodified lines42742842943043143243351 unmodified lines485486487488489490491492156 unmodified linestarget_prefix: str = ""choices_field: str = "choices"target_field: str = "label"choices_separator: str = ", "source_choice_format: str = "{choice_numeral}. {choice_text}"target_choice_format: str = "{choice_numeral}"enumerator: str = "capitals"53 unmodified linesreturn {"numerals": self.inputs_to_numerals(inputs),**inputs,self.choices_field: self.choices_separator.join(choices),}def inputs_to_source(self, inputs: Dict[str, object]) -> Tuple[str, str]:134 unmodified linesArgs 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')."""pairs_separator: str = ", "key_val_separator: str = ": "use_keys_for_inputs: bool = Trueoutputs_key_val_separator: str = ": "use_keys_for_outputs: bool = Falsedef process_dict(9 unmodified linesdef inputs_to_source(self, inputs: Dict[str, object]) -> Tuple[str, str]:return self.process_dict(inputs,key_val_sep=self.key_val_separator,pairs_sep=self.pairs_separator,use_keys=self.use_keys_for_inputs,)def outputs_to_target_and_references(self, outputs: Dict[str, object]) -> str:target = self.process_dict(outputs,key_val_sep=self.key_val_separator,pairs_sep=self.pairs_separator,use_keys=self.use_keys_for_outputs,)return target, [target]21 unmodified linesclass MultiLabelTemplate(InputOutputTemplate):labels_field: str = "labels"labels_separator: str = ", "postprocessors: List[str] = ["processors.to_list_by_comma"]output_format: str = "{labels}"empty_label: str = "None"6 unmodified lines)if len(labels) == 0:labels = [self.empty_label]labels_str = self.labels_separator.join(labels)return super().outputs_to_target_and_references({self.labels_field: labels_str})51 unmodified linesdef outputs_to_target_and_references(self, outputs: Dict[str, object]) -> Dict[str, object]:span_labels_pairs = self.extract_span_label_pairs(outputs)targets = self.span_label_pairs_to_targets(span_labels_pairs)return super().outputs_to_target_and_references({"labels": targets})@abstractmethod
templates.py+13-13