๐ 2kยถ
Note
ID: cards.ffqa_filtered.2k | 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": 2048
}
},
{
"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": "2k[10%]",
"train": "2k[80%]",
"validation": "2k[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.