unitxt.templates module

class unitxt.templates.InputOutputTemplate(*argv, **kwargs)

Bases: 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’).

class unitxt.templates.KeyValTemplate(*argv, **kwargs)

Bases: 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’).

class unitxt.templates.MultiLabelTemplate(*argv, **kwargs)

Bases: InputOutputTemplate

postprocessors: List[str] = ['processors.to_list_by_comma']
class unitxt.templates.MultiReferenceTemplate(*argv, **kwargs)

Bases: InputOutputTemplate

class unitxt.templates.MultipleChoiceTemplate(*argv, **kwargs)

Bases: Template

Formats the input (that specifies the question), the multiple choices to select the answer from, and specifies the field with the correct answer.

class unitxt.templates.OutputQuantizingTemplate(*argv, **kwargs)

Bases: InputOutputTemplate

class unitxt.templates.SpanLabelingBaseTemplate(*argv, **kwargs)

Bases: MultiLabelTemplate

class unitxt.templates.SpanLabelingJsonTemplate(*argv, **kwargs)

Bases: SpanLabelingBaseTemplate

postprocessors: List[str] = ['processors.load_json', 'processors.dict_of_lists_to_value_key_pairs']
class unitxt.templates.SpanLabelingTemplate(*argv, **kwargs)

Bases: SpanLabelingBaseTemplate

escape_characters: List[str] = [':', ',']
postprocessors: List[str] = ['processors.to_span_label_pairs']
class unitxt.templates.Template(*argv, **kwargs)

Bases: StreamInstanceOperator

The role of template is to take the fields of every instance and verbalize it.

Meaning the template is taking the instance and generating source, target and references.

class unitxt.templates.TemplatesDict

Bases: Dict

verify()
class unitxt.templates.TemplatesList(*argv, **kwargs)

Bases: ListCollection

class unitxt.templates.YesNoTemplate(*argv, **kwargs)

Bases: Template

A template for generating binary Yes/No questions asking whether an input text is of a specific class.

input_format:

Defines the format of the question.

class_field:

Defines the field that contains the name of the class that this template asks of.

label_field:

Defines the field which contains the true label of the input text. If a gold label is equal to the value in class_name, then the correct output is self.yes_answer (by default, “Yes”). Otherwise the correct output is self.no_answer (by default, “No”).

yes_answer:

The output value for when the gold label equals self.class_name. Defaults to “Yes”.

no_answer:

The output value for when the gold label differs from self.class_name. Defaults to “No”.

unitxt.templates.escape_chars(s, chars_to_escape)