π 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"
},
{
"field_to_field": [
[
"wikipedia/0",
"first_wiki"
]
],
"type": "copy_fields"
},
{
"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"
},
{
"_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 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 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.regard
Read more about catalog usage here.