πŸ“„ Token Overlap With ContextΒΆ

metrics.token_overlap_with_context

MetricPipeline(
    main_score="f1",
    preprocess_steps=[
        Copy(
            field="task_data/context",
            to_field="references",
        ),
        ListFieldValues(
            fields=[
                "references",
            ],
            to_field="references",
        ),
    ],
    metric=TokenOverlap(),
    postprocess_steps=[
        Copy(
            field_to_field=[
                [
                "score/global/f1",
                "score/global/f1_overlap_with_context",
                ],
                [
                "score/global/recall",
                "score/global/recall_overlap_with_context",
                ],
                [
                "score/global/precision",
                "score/global/precision_overlap_with_context",
                ],
            ],
        ),
    ],
)
[source]

from unitxt.metrics import TokenOverlap
from unitxt.operators import Copy, ListFieldValues

Explanation about ListFieldValuesΒΆ

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

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}

Read more about catalog usage here.