๐Ÿ“„ 16kยถ

Note

ID: cards.ffqa_filtered.16k | Type: TaskCard

{
    "loader": {
        "path": "abacusai/WikiQA-Free_Form_QA",
        "type": "load_hf"
    },
    "preprocess_steps": [
        {
            "field_to_field": {
                "conversations/0/tok_len": "inputs_len",
                "conversations/0/value": "inputs",
                "conversations/1/value": "answer"
            },
            "type": "copy_fields"
        },
        {
            "fields": [
                "answer"
            ],
            "to_field": "answers",
            "type": "list_field_values"
        },
        {
            "condition": "lt",
            "type": "filter_by_condition",
            "values": {
                "inputs_len": 16384
            }
        },
        {
            "expression": "re.search(r\"Document:\\s(.*)(\\n\\n|$)\", inputs).group(1)",
            "imports_list": [
                "re"
            ],
            "to_field": "context",
            "type": "execute_expression"
        },
        {
            "expression": "re.search(r\"Question:\\s(.*)(\\n\\n|$)\", inputs).group(1)",
            "imports_list": [
                "re"
            ],
            "to_field": "question",
            "type": "execute_expression"
        },
        {
            "fields": {
                "context_type": "document"
            },
            "type": "add_fields"
        },
        {
            "mix": {
                "test": "16k[10%]",
                "train": "16k[80%]",
                "validation": "16k[10%]"
            },
            "type": "split_random_mix"
        }
    ],
    "task": "tasks.qa.with_context.extractive",
    "templates": "templates.qa.with_context.all",
    "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 FilterByConditionยถ

Filters a stream, yielding only instances in which the values in required fields follow the required condition operator.

Raises an error if a required field name is missing from the input instance.

Args:

values (Dict[str, Any]): Field names and respective Values that instances must match according the condition, to be included in the output. condition: the name of the desired condition operator between the specified (sub) fieldโ€™s value and the provided constant value. Supported conditions are (โ€œgtโ€, โ€œgeโ€, โ€œltโ€, โ€œleโ€, โ€œneโ€, โ€œeqโ€, โ€œinโ€,โ€not inโ€) 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 field โ€œaโ€ contains a value > 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 FilterByCondition(values = {โ€œa/bโ€:[4,8]}, condition = โ€œnot inโ€) will yield only instances where โ€œaโ€ is

a dict in which key โ€œbโ€ is mapped to a value that is neither 4 nor 8

FilterByCondition(values = {โ€œa[2]โ€:4}, condition = โ€œleโ€) will yield only instances where โ€œaโ€ is a list whose 3-rd

element is <= 4

Explanation about SplitRandomMixยถ

Splits a multistream into new streams (splits), whose names, source input stream, and amount of instances, are specified by arg โ€˜mixโ€™.

The keys of arg โ€˜mixโ€™, are the names of the new streams, the values are of the form: โ€˜name-of-source-stream[percentage-of-source-stream]โ€™ Each input instance, of any input stream, is selected exactly once for inclusion in any of the output streams.

Examples: When processing a multistream made of two streams whose names are โ€˜trainโ€™ and โ€˜testโ€™, by SplitRandomMix(mix = { โ€œtrainโ€: โ€œtrain[99%]โ€, โ€œvalidationโ€: โ€œtrain[1%]โ€, โ€œtestโ€: โ€œtestโ€ }) the output is a multistream, whose three streams are named โ€˜trainโ€™, โ€˜validationโ€™, and โ€˜testโ€™. Output stream โ€˜trainโ€™ is made of randomly selected 99% of the instances of input stream โ€˜trainโ€™, output stream โ€˜validationโ€™ is made of the remaining 1% instances of input โ€˜trainโ€™, and output stream โ€˜testโ€™ is made of the whole of input stream โ€˜testโ€™.

When processing the above input multistream by SplitRandomMix(mix = { โ€œtrainโ€: โ€œtrain[50%]+test[0.1]โ€, โ€œvalidationโ€: โ€œtrain[50%]+test[0.2]โ€, โ€œtestโ€: โ€œtest[0.7]โ€ }) the output is a multistream, whose three streams are named โ€˜trainโ€™, โ€˜validationโ€™, and โ€˜testโ€™. Output stream โ€˜trainโ€™ is made of randomly selected 50% of the instances of input stream โ€˜trainโ€™ + randomly selected 0.1 (i.e., 10%) of the instances of input stream โ€˜testโ€™. Output stream โ€˜validationโ€™ is made of the remaining 50% instances of input โ€˜trainโ€™+ randomly selected 0.2 (i.e., 20%) of the original instances of input โ€˜testโ€™, that were not selected for output โ€˜trainโ€™, and output stream โ€˜testโ€™ is made of the remaining instances of input โ€˜testโ€™.

Explanation about ExecuteExpressionยถ

Compute an expression, specified as a string to be eval-uated, over the instanceโ€™s fields, and store the result in field to_field.

Raises an error if a field mentioned in the query is missing from the instance.

Args:

expression (str): an expression to be evaluated over the fields of the instance to_field (str): the field where the result is to be stored into imports_list (List[str]): names of imports needed for the eval of the query (e.g. โ€˜reโ€™, โ€˜jsonโ€™)

Examples:

When instance {โ€œaโ€: 2, โ€œbโ€: 3} is process-ed by operator ExecuteExpression(expression=โ€a+bโ€, to_field = โ€œcโ€) the result is {โ€œaโ€: 2, โ€œbโ€: 3, โ€œcโ€: 5}

When instance {โ€œaโ€: โ€œhelloโ€, โ€œbโ€: โ€œworldโ€} is process-ed by operator ExecuteExpression(expression = โ€œa+โ€™ โ€˜+bโ€, to_field = โ€œcโ€) the result is {โ€œaโ€: โ€œhelloโ€, โ€œbโ€: โ€œworldโ€, โ€œcโ€: โ€œhello worldโ€}

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

Explanation about ListFieldValuesยถ

Concatenates values of multiple fields into a list, and assigns it to a new field.

References: tasks.qa.with_context.extractive, templates.qa.with_context.all

Read more about catalog usage here.