πŸ“„ boldΒΆ

Note

ID: cards.bold | Type: TaskCard

{
    "loader": {
        "path": "AlexaAI/bold",
        "type": "load_hf"
    },
    "preprocess_steps": [
        {
            "mapper": {
                "train": "test"
            },
            "type": "rename_splits"
        },
        {
            "fields": {
                "input_label": {}
            },
            "type": "add_fields"
        },
        {
            "field_to_field": [
                [
                    "prompts/0",
                    "first_prompt"
                ]
            ],
            "type": "copy_fields",
            "use_query": true
        },
        {
            "field_to_field": [
                [
                    "wikipedia/0",
                    "first_wiki"
                ]
            ],
            "type": "copy_fields",
            "use_query": true
        },
        {
            "condition": "in",
            "type": "filter_by_condition",
            "values": {
                "domain": [
                    "race",
                    "gender"
                ]
            }
        },
        {
            "page_size": 10000,
            "type": "shuffle"
        },
        {
            "field_to_field": {
                "category": "input_label/category",
                "first_prompt": "input_label/input",
                "first_wiki": "input_label/wiki"
            },
            "type": "copy_fields",
            "use_query": true
        },
        {
            "_argv": [
                "input_label"
            ],
            "function": "json.dumps",
            "to_field": "input_label",
            "type": "apply"
        }
    ],
    "task": {
        "inputs": [
            "first_prompt"
        ],
        "metrics": [
            "metrics.regard"
        ],
        "outputs": [
            "input_label"
        ],
        "type": "form_task"
    },
    "templates": {
        "items": [
            {
                "input_format": "{first_prompt}\n",
                "output_format": "{input_label}",
                "type": "input_output_template"
            }
        ],
        "type": "templates_list"
    },
    "type": "task_card"
}

Explanation about TaskCardΒΆ

TaskCard delineates the phases in transforming the source dataset into a model-input, and specifies the metrics for evaluation of model-output.

Attributes:

loader: specifies the source address and the loading operator that can access that source and transform it into a unitxt multistream.

preprocess_steps: list of unitxt operators to process the data source into a model-input.

task: specifies the fields (of the already (pre)processed instance) making the inputs, the fields making the outputs, and the metrics to be used for evaluating the model output.

templates: format strings to be applied on the input fields (specified by the task) and the output fields. The template also carries the instructions and the list of postprocessing steps, to be applied to the model output.

Explanation about CopyFieldsΒΆ

Copies values from specified fields to specified fields.

Args (of parent class):

field_to_field (Union[List[List], Dict[str, str]]): A list of lists, where each sublist contains the source field and the destination field, or a dictionary mapping source fields to destination fields. use_query (bool): Whether to use dpath for accessing fields. Defaults to False.

Examples:

An input instance {β€œa”: 2, β€œb”: 3}, when processed by CopyField(field_to_field={β€œa”: β€œb”} would yield {β€œa”: 2, β€œb”: 2}, and when processed by CopyField(field_to_field={β€œa”: β€œc”} would yield {β€œa”: 2, β€œb”: 3, β€œc”: 2}

with use_query=True, we can also copy inside the field: CopyFields(field_to_field={β€œa/0”: β€œa”}, use_query=True) would process instance {β€œa”: [1, 3]} into {β€œa”: 1}

Explanation about ShuffleΒΆ

Shuffles the order of instances in each page of a stream.

Args (of superclass):

page_size (int): The size of each page in the stream. Defaults to 1000.

Explanation about FormTaskΒΆ

FormTask packs the different instance fields into dictionaries by their roles in the task.

The output instance contains three fields:

β€œinputs” whose value is a sub-dictionary of the input instance, consisting of all the fields listed in Arg β€˜inputs’. β€œoutputs” – for the fields listed in Arg β€œoutputs”. β€œmetrics” – to contain the value of Arg β€˜metrics’

Explanation about AddFieldsΒΆ

Adds specified fields to each instance in a given stream or all streams (default) If fields exist, updates them.

Args:

fields (Dict[str, object]): The fields to add to each instance. use_query (bool) : Use β€˜/’ to access inner fields use_deepcopy (bool) : Deep copy the input value to avoid later modifications

Examples:

# Add a β€˜classes’ field with a value of a list β€œpositive” and β€œnegative” to all streams AddFields(fields={β€œclasses”: [β€œpositive”,”negatives”]})

# Add a β€˜start’ field under the β€˜span’ field with a value of 0 to all streams AddFields(fields={β€œspan/start”: 0}

# Add a β€˜classes’ field with a value of a list β€œpositive” and β€œnegative” to β€˜train’ stream AddFields(fields={β€œclasses”: [β€œpositive”,”negatives”], apply_to_stream=[β€œtrain”]})

# Add a β€˜classes’ field on a given list, prevent modification of original list # from changing the instance. AddFields(fields={β€œclasses”: alist}), use_deepcopy=True) # if now alist is modified, still the instances remain intact.

Explanation about InputOutputTemplateΒΆ

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

Explanation about ApplyΒΆ

A class used to apply a python function and store the result in a field.

Args:

function (str): name of function. to_field (str): the field to store the result additional arguments are field names passed to the function

Examples: Store in field β€œb” the uppercase string of the value in field β€œa” Apply(β€œa”, function=str.upper, to_field=”b”)

Dump the json representation of field β€œt” and store back in the same field. Apply(β€œt”, function=json.dumps, to_field=”t”)

Set the time in a field β€˜b’. Apply(function=time.time, to_field=”b”)

Explanation about FilterByConditionΒΆ

Filters a stream, yielding only instances for which the required values follows the required condition operator.

Raises an error if a required key is missing.

Args:

values (Dict[str, Any]): Values that instances must match using the condition to be included in the output. condition: the name of the desired condition operator between the key and the value in values (β€œgt”, β€œge”, β€œlt”, β€œle”, β€œne”, β€œeq”) error_on_filtered_all (bool, optional): If True, raises an error if all instances are filtered out. Defaults to True.

Examples:

FilterByCondition(values = {β€œa”:4}, condition = β€œgt”) will yield only instances where β€œa”>4 FilterByCondition(values = {β€œa”:4}, condition = β€œle”) will yield only instances where β€œa”<=4 FilterByCondition(values = {β€œa”:[4,8]}, condition = β€œin”) will yield only instances where β€œa” is 4 or 8 FilterByCondition(values = {β€œa”:[4,8]}, condition = β€œnot in”) will yield only instances where β€œa” different from 4 or 8

References: metrics.regard

Read more about catalog usage here.