πŸ“„ atta_qΒΆ

Note

ID: cards.atta_q | Type: TaskCard

{
    "loader": {
        "path": "ibm/AttaQ",
        "type": "load_hf"
    },
    "preprocess_steps": [
        {
            "mapper": {
                "train": "test"
            },
            "type": "rename_splits"
        },
        {
            "page_size": 2800,
            "type": "shuffle"
        },
        {
            "fields": {
                "input_label": {}
            },
            "type": "add_fields"
        },
        {
            "field_to_field": {
                "input": "input_label/input",
                "label": "input_label/label"
            },
            "type": "copy_fields"
        },
        {
            "_argv": [
                "input_label"
            ],
            "function": "json.dumps",
            "to_field": "input_label",
            "type": "apply"
        }
    ],
    "task": {
        "inputs": [
            "input"
        ],
        "metrics": [
            "metrics.safety"
        ],
        "outputs": [
            "input_label"
        ],
        "type": "form_task"
    },
    "templates": {
        "items": [
            {
                "input_format": "{input}\n",
                "output_format": "{input_label}",
                "type": "input_output_template"
            },
            {
                "input_format": "{input}",
                "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 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 FormTaskΒΆ

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

Attributes:
inputs (Union[Dict[str, str], List[str]]):

Dictionary with string names of instance input fields and types of respective values. In case a list is passed, each type will be assumed to be Any.

outputs (Union[Dict[str, str], List[str]]):

Dictionary with string names of instance output fields and types of respective values. In case a list is passed, each type will be assumed to be Any.

metrics (List[str]): List of names of metrics to be used in the task. prediction_type (Optional[str]):

Need to be consistent with all used metrics. Defaults to None, which means that it will be set to Any.

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

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 field names containing / , we can also copy inside the field: CopyFields(field_to_field={β€œa/0”: β€œa”}) would process instance {β€œa”: [1, 3]} into {β€œa”: 1}

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 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 β€˜/’ 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.

References: metrics.safety

Read more about catalog usage here.