๐Ÿ“„ Rating Hf Space Processing Stepsยถ

operators.mt_bench.rating_hf_space_processing_steps

SequentialOperator(
    steps=[
        Rename(
            field_to_field={
                "turns": "model_input",
            },
            apply_to_streams=[
                "questions",
            ],
        ),
        Rename(
            field_to_field={
                "model": "model_id",
                "user_prompt": "judge_input",
                "judgment": "judge_output",
            },
            apply_to_streams=[
                "judgment",
            ],
        ),
        Copy(
            field="judge/0",
            to_field="judge_model_id",
            apply_to_streams=[
                "judgment",
            ],
        ),
        Rename(
            field_to_field={
                "choices": "model_output",
            },
            apply_to_streams=[
                "model_answer",
            ],
        ),
        Apply(
            function="str.lower",
            to_field="model_id",
            apply_to_streams=[
                "judgment",
                "model_answer",
            ],
            _argv=[
                "model_id",
            ],
        ),
        MapInstanceValues(
            mappers={
                "model_id": {
                    "vicuna-13b-hao-0515": "vicuna-13b-v1.3",
                    "vicuna-30b-gpt4": "vicuna-33b-v1.3",
                },
            },
            strict=False,
            apply_to_streams=[
                "judgment",
                "model_answer",
            ],
        ),
        Copy(
            field="model_output/0/turns",
            to_field="model_output",
            apply_to_streams=[
                "model_answer",
            ],
        ),
        JoinStreams(
            left_stream="questions",
            right_stream="judgment",
            how="inner",
            on=[
                "question_id",
            ],
            new_stream_name="merged_stream",
        ),
        JoinStreams(
            left_stream="merged_stream",
            right_stream="model_answer",
            how="inner",
            on=[
                "question_id",
                "model_id",
            ],
            new_stream_name="merged_stream",
        ),
        DeleteSplits(
            splits=[
                "questions",
                "model_answer",
                "judgment",
            ],
        ),
        RenameSplits(
            mapper={
                "merged_stream": "test",
            },
        ),
        SelectFields(
            fields=[
                "question_id",
                "category",
                "model_input",
                "reference",
                "turn",
                "model_id",
                "judge_model_id",
                "score",
                "model_output",
                "judge_input",
                "judge_output",
            ],
        ),
    ],
)
[source]

from unitxt.operators import Apply, Copy, MapInstanceValues, Rename, SelectFields
from unitxt.splitters import RenameSplits
from unitxt.stream_operators import DeleteSplits, JoinStreams

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 SelectFieldsยถ

Keep only specified fields from each instance in a stream.

Args:

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

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.

Args:
mappers (Dict[str, Dict[str, Any]]):

The mappers to use for mapping instance values. Keys are the names of the fields to undergo mapping, and values are dictionaries that define the mapping from old values to new values. Note that mapped values are defined by their string representation, so mapped values are converted to strings before being looked up in the mappers.

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}. Note that the value of "b" remained intact, since field-name "b" does not participate in the mappers, and that 1 was casted to "1" before looked up in the mapper of "a".

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

Explanation about DeleteSplitsยถ

Operator which delete splits in stream.

Attributes:

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

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

any additional arguments are field names whose values will be passed directly to the function specified

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 Renameยถ

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:

Rename(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}]

Rename(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}}]

Rename(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}}]

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

Read more about catalog usage here.