Upload templates.py with huggingface_hub
Browse files59 unmodified lines606162636465666768697022 unmodified lines93949596979899100170 unmodified lines27127227327427527627727827928028142 unmodified lines32432532632732831631732933033133233359 unmodified lines
class InputOutputTemplate(Template): """Generate field 'source' from fields designated as input, and fields 'target' and 'references' from fields designated as output, of the processed instance.
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'). """
input_format: str = None output_format: str = None
22 unmodified lines
class MultipleChoiceTemplate(Template): """Formats the input (that specifies the question), the multiple choices to select the answer from, and specifies the field with the correct answer."""
input_format: str target_prefix: str = "" choices_field: str = "choices"170 unmodified lines
class KeyValTemplate(Template): """Generate field 'source' from fields designated as input, and fields 'target' and 'references' from fields designated as output, of the processed instance.
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'). """
pairs_seperator: str = ", " key_val_seperator: str = ": " use_keys_for_inputs: bool = True42 unmodified lines quantum: float = 0.1
def outputs_to_target_and_references(self, outputs: Dict[str, object]) -> str: quantum_str = f"{self.quantum:.10f}".rstrip("0").rstrip(".") quantized_outputs = { key: round(input_float / self.quantum) * self.quantum for key, input_float in outputs.items() key: f"{round(value / self.quantum) * self.quantum:{quantum_str}}" for key, value in outputs.items() } return super().outputs_to_target_and_references(quantized_outputs)
templates.py+15-2