📄 Pairwise Hf Space Processing Steps

Note

ID: operators.mt_bench.pairwise_hf_space_processing_steps | Type: SequentialOperator

{
    "__type__": "sequential_operator",
    "steps": [
        {
            "__type__": "rename_fields",
            "apply_to_streams": [
                "questions"
            ],
            "field_to_field": {
                "turns": "model_input"
            }
        },
        {
            "__type__": "rename_fields",
            "apply_to_streams": [
                "judgment"
            ],
            "field_to_field": {
                "g1_judgment": "judge_output_model_1_ordered_first",
                "g1_user_prompt": "judge_input_model_1_ordered_first",
                "g1_winner": "winner_model_1_ordered_first",
                "g2_judgment": "judge_output_model_2_ordered_first",
                "g2_user_prompt": "judge_input_model_2_ordered_first",
                "g2_winner": "winner_model_2_ordered_first"
            }
        },
        {
            "__type__": "copy",
            "apply_to_streams": [
                "judgment"
            ],
            "field": "judge/0",
            "to_field": "judge_model_id"
        },
        {
            "__type__": "apply",
            "_argv": [
                "model_1"
            ],
            "apply_to_streams": [
                "judgment"
            ],
            "function": "str.lower",
            "to_field": "model_1"
        },
        {
            "__type__": "map_instance_values",
            "apply_to_streams": [
                "judgment"
            ],
            "mappers": {
                "model_1": {
                    "vicuna-13b-hao-0515": "vicuna-13b-v1.3",
                    "vicuna-30b-gpt4": "vicuna-33b-v1.3"
                }
            },
            "strict": false
        },
        {
            "__type__": "apply",
            "_argv": [
                "model_2"
            ],
            "apply_to_streams": [
                "judgment"
            ],
            "function": "str.lower",
            "to_field": "model_2"
        },
        {
            "__type__": "map_instance_values",
            "apply_to_streams": [
                "judgment"
            ],
            "mappers": {
                "model_2": {
                    "vicuna-13b-hao-0515": "vicuna-13b-v1.3",
                    "vicuna-30b-gpt4": "vicuna-33b-v1.3"
                }
            },
            "strict": false
        },
        {
            "__type__": "copy",
            "apply_to_streams": [
                "judgment"
            ],
            "field": "judge_model_id/0",
            "to_field": "judge_model_id"
        },
        {
            "__type__": "filter_by_condition_based_on_fields",
            "apply_to_streams": [
                "judgment"
            ],
            "condition": "eq",
            "values": {
                "winner_model_1_ordered_first": "winner_model_2_ordered_first"
            }
        },
        {
            "__type__": "copy",
            "apply_to_streams": [
                "judgment"
            ],
            "field_to_field": {
                "winner_model_1_ordered_first": "winner"
            }
        },
        {
            "__type__": "rename_fields",
            "apply_to_streams": [
                "model_answer"
            ],
            "field_to_field": {
                "choices": "model_output"
            }
        },
        {
            "__type__": "apply",
            "_argv": [
                "model_id"
            ],
            "apply_to_streams": [
                "model_answer"
            ],
            "function": "str.lower",
            "to_field": "model_id"
        },
        {
            "__type__": "map_instance_values",
            "apply_to_streams": [
                "model_answer"
            ],
            "mappers": {
                "model_id": {
                    "vicuna-13b-hao-0515": "vicuna-13b-v1.3",
                    "vicuna-30b-gpt4": "vicuna-33b-v1.3"
                }
            },
            "strict": false
        },
        {
            "__type__": "copy",
            "apply_to_streams": [
                "model_answer"
            ],
            "field": "model_output/0/turns",
            "to_field": "model_output"
        },
        {
            "__type__": "join_streams",
            "how": "inner",
            "left_stream": "questions",
            "new_stream_name": "merged_stream",
            "on": [
                "question_id"
            ],
            "right_stream": "judgment"
        },
        {
            "__type__": "rename_fields",
            "apply_to_streams": [
                "model_answer"
            ],
            "field_to_field": {
                "model_id": "model_1",
                "model_output": "model_1_output"
            }
        },
        {
            "__type__": "join_streams",
            "how": "inner",
            "left_stream": "merged_stream",
            "new_stream_name": "merged_stream",
            "on": [
                "question_id",
                "model_1"
            ],
            "right_stream": "model_answer"
        },
        {
            "__type__": "rename_fields",
            "apply_to_streams": [
                "model_answer"
            ],
            "field_to_field": {
                "model_1": "model_2",
                "model_1_output": "model_2_output"
            }
        },
        {
            "__type__": "join_streams",
            "how": "inner",
            "left_stream": "merged_stream",
            "new_stream_name": "merged_stream",
            "on": [
                "question_id",
                "model_2"
            ],
            "right_stream": "model_answer"
        },
        {
            "__type__": "delete_splits",
            "splits": [
                "questions",
                "model_answer",
                "judgment"
            ]
        },
        {
            "__type__": "rename_splits",
            "mapper": {
                "merged_stream": "test"
            }
        },
        {
            "__type__": "select_fields",
            "fields": [
                "question_id",
                "category",
                "model_input",
                "reference",
                "model_1",
                "model_2",
                "turn",
                "judge_model_id",
                "model_1_output",
                "model_2_output",
                "winner_model_1_ordered_first",
                "winner_model_2_ordered_first",
                "winner",
                "judge_input_model_1_ordered_first",
                "judge_input_model_2_ordered_first",
                "judge_output_model_1_ordered_first",
                "judge_output_model_2_ordered_first"
            ]
        }
    ]
}

Explanation about SequentialOperator

A class representing a sequential operator in the streaming system.

A sequential operator is a type of MultiStreamOperator that applies a sequence of other operators to a MultiStream. It maintains a list of StreamingOperator`s and applies them in order to the `MultiStream.

Explanation about JoinStreams

Join multiple streams into a single stream.

Args:

left_stream (str): The stream that will be considered the “left” in the join operations. right_stream (str): The stream that will be considered the “right” in the join operations. how (Literal[“left”, “right”, “inner”, “outer”, “cross”]): The type of join to be performed. on (Optional[List[str]]): Column names to join on. These must be found in both streams. left_on (Optional[List[str]]): Column names to join on in the left stream. right_on (Optional[List[str]]): Column names to join on in the right streasm. new_stream_name (str): The name of the new stream resulting from the merge.

Examples:

JoinStreams(left_stream = “questions”, right_stream = “answers”, how=”inner”, on=”question_id”, new_stream_name=”question_with_answers” ) Join the ‘question’ and ‘answer’ stream based on the ‘question_id’ field using inner join, resulting with a new stream named “question_with_answers”. JoinStreams(left_stream = “questions”, right_stream = “answers”, how=”inner”, on_left=”question_id”, on_right=”question” new_stream_name=”question_with_answers” ) Join the ‘question’ and ‘answer’ stream based on the ‘question_id’ field in the left stream and the ‘question’ field in the right stream, using inner join, resulting with a new stream named “question_with_answers”. This is suitable when the fields have different labels across the streams.

Explanation about Copy

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 Copy(field_to_field={“a”: “b”} would yield {“a”: 2, “b”: 2}, and when processed by Copy(field_to_field={“a”: “c”} would yield {“a”: 2, “b”: 3, “c”: 2}

with field names containing / , we can also copy inside the field: Copy(field=”a/0”,to_field=”a”) would process instance {“a”: [1, 3]} into {“a”: 1}

Explanation about FilterByConditionBasedOnFields

Filters a stream based on a condition between 2 fields values.

Raises an error if either of the required fields names is missing from the input instance.

Args:

values (Dict[str, str]): The fields names that the filter operation is based on. condition: the name of the desired condition operator between the specified field’s values. 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”:”b}, condition = “gt”) will yield only instances where field “a” contains a value greater then the value in field “b”. FilterByCondition(values = {“a”:”b}, condition = “le”) will yield only instances where “a”<=”b”

Explanation about DeleteSplits

Operator which delete splits in stream.

Attributes:

splits (List[str]): The splits to delete from the stream.

Explanation about MapInstanceValues

A class used to map instance values into other values.

This class is a type of InstanceOperator, it maps values of instances in a stream using predefined mappers.

Attributes:
mappers (Dict[str, Dict[str, str]]): The mappers to use for mapping instance values.

Keys are the names of the fields to be mapped, and values are dictionaries that define the mapping from old values to new values.

strict (bool): If True, the mapping is applied strictly. That means if a value

does not exist in the mapper, it will raise a KeyError. If False, values that are not present in the mapper are kept as they are.

process_every_value (bool): If True, all fields to be mapped should be lists, and the mapping

is to be applied to their individual elements. If False, mapping is only applied to a field containing a single value.

Examples:

MapInstanceValues(mappers={“a”: {“1”: “hi”, “2”: “bye”}}) replaces ‘1’ with ‘hi’ and ‘2’ with ‘bye’ in field ‘a’ in all instances of all streams: instance {“a”:”1”, “b”: 2} becomes {“a”:”hi”, “b”: 2}.

MapInstanceValues(mappers={“a”: {“1”: “hi”, “2”: “bye”}}, process_every_value=True) Assuming field ‘a’ is a list of values, potentially including “1”-s and “2”-s, this replaces each such “1” with “hi” and “2” – with “bye” in all instances of all streams: instance {“a”: [“1”, “2”], “b”: 2} becomes {“a”: [“hi”, “bye”], “b”: 2}.

MapInstanceValues(mappers={“a”: {“1”: “hi”, “2”: “bye”}}, strict=True) To ensure that all values of field ‘a’ are mapped in every instance, use strict=True. Input instance {“a”:”3”, “b”: 2} will raise an exception per the above call, because “3” is not a key in the mapper of “a”.

MapInstanceValues(mappers={“a”: {str([1,2,3,4]): ‘All’, str([]): ‘None’}}, strict=True) replaces a list [1,2,3,4] with the string ‘All’ and an empty list by string ‘None’. Note that mapped values are defined by their string representation, so mapped values must be converted to strings.

Explanation about RenameFields

Renames fields.

Move value from one field to another, potentially, if field name contains a /, from one branch into another. Remove the from field, potentially part of it in case of / in from_field.

Examples:

RenameFields(field_to_field={“b”: “c”}) will change inputs [{“a”: 1, “b”: 2}, {“a”: 2, “b”: 3}] to [{“a”: 1, “c”: 2}, {“a”: 2, “c”: 3}]

RenameFields(field_to_field={“b”: “c/d”}) will change inputs [{“a”: 1, “b”: 2}, {“a”: 2, “b”: 3}] to [{“a”: 1, “c”: {“d”: 2}}, {“a”: 2, “c”: {“d”: 3}}]

RenameFields(field_to_field={“b”: “b/d”}) will change inputs [{“a”: 1, “b”: 2}, {“a”: 2, “b”: 3}] to [{“a”: 1, “b”: {“d”: 2}}, {“a”: 2, “b”: {“d”: 3}}]

RenameFields(field_to_field={“b/c/e”: “b/d”}) will change inputs [{“a”: 1, “b”: {“c”: {“e”: 2, “f”: 20}}}] to [{“a”: 1, “b”: {“c”: {“f”: 20}, “d”: 2}}]

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 SelectFields

Keep only specified fields from each instance in a stream.

Args:

fields (List[str]): The fields to keep from each instance.

Read more about catalog usage here.