πŸ“„ RelevanceΒΆ

cards.judge_bench.newswoom.relevance

TaskCard(
    loader=LoadJsonFile(
        files={
            "test": "https://raw.githubusercontent.com/dmg-illc/JUDGE-BENCH/refs/heads/master/data/newsroom/newsroom.json",
        },
        data_classification_policy=[
            "public",
        ],
        data_field="instances",
    ),
    preprocess_steps=[
        Rename(
            field="annotations/Relevance/mean_human",
            to_field="mean_score",
        ),
        Cast(
            field="mean_score",
            to="float",
        ),
        ExecuteExpression(
            expression="(mean_score - 1) / 4",
            to_field="mean_score",
        ),
        GroupDictWithRegex(
            field="instance",
            pattern="### Generated Summary\s+(?P<generated_summary>.*?)\s+### Source Article\s+(?P<source_article>.*)",
            flags=16,
        ),
        Rename(
            field="instance/generated_summary",
            to_field="summary",
        ),
        Rename(
            field="instance/source_article",
            to_field="article",
        ),
        Set(
            fields={
                "criteria": "metrics.llm_as_judge.direct.criteria.summarization_relevance",
            },
        ),
    ],
    task=Task(
        input_fields={
            "summary": "str",
            "article": "str",
            "criteria": "Any",
        },
        reference_fields={
            "mean_score": "float",
        },
        prediction_type="float",
        metrics=[
            "metrics.spearman",
            "metrics.pearson",
        ],
        default_template="templates.empty[postprocessors=[processors.cast_to_float_return_nan_if_failed]]",
    ),
    templates=[],
)
[source]

from unitxt.loaders import LoadJsonFile
from unitxt.operators import Cast, ExecuteExpression, Rename, Set
from unitxt.processors import GroupDictWithRegex
from unitxt.task import Task

Explanation about TaskCardΒΆ

TaskCard delineates the phases in transforming the source dataset into model input, and specifies the metrics for evaluation of model output.

Args:
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 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 GroupDictWithRegexΒΆ

Extracts named groups from a string using a regular expression pattern, returning a dictionary of group names to values.

Args:

pattern (str): A regular expression with named groups (using (?P<name>…)).

Example:
>>> op = GroupDictWithRegex(pattern=r"(?P<name>\\w+):(?P<age>\\d+)")
>>> op.process_value("alice:23")
{'name': 'alice', 'age': '23'}
>>> op.process_value("not_a_match")
{}
Returns:

dict: A dictionary mapping group names to matched values, or an empty dict if no match.

Explanation about TaskΒΆ

Task packs the different instance fields into dictionaries by their roles in the task.

Args:
input_fields (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.

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

defaults (Optional[Dict[str, Any]]):

An optional dictionary with default values for chosen input/output keys. Needs to be consistent with names and types provided in β€˜input_fields’ and/or β€˜output_fields’ arguments. Will not overwrite values if already provided in a given instance.

The output instance contains three fields:
  1. β€œinput_fields” whose value is a sub-dictionary of the input instance, consisting of all the fields listed in Arg β€˜input_fields’.

  2. β€œreference_fields” – for the fields listed in Arg β€œreference_fields”.

  3. β€œmetrics” – to contain the value of Arg β€˜metrics’

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 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 CastΒΆ

Casts specified fields to specified types.

Args:

default (object): A dictionary mapping field names to default values for cases of casting failure. process_every_value (bool): If true, all fields involved must contain lists, and each value in the list is then casted. Defaults to False.

Explanation about SetΒΆ

Sets specified fields in each instance, in a given stream or all streams (default), with specified values. If fields exist, updates them, if do not exist – adds 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:

# Set a value of a list consisting of β€œpositive” and β€œnegative” do field β€œclasses” to each and every instance of all streams Set(fields={"classes": ["positive","negatives"]})

# In each and every instance of all streams, field β€œspan” is to become a dictionary containing a field β€œstart”, in which the value 0 is to be set Set(fields={"span/start": 0}

# In all instances of stream β€œtrain” only, Set field β€œclasses” to have the value of a list consisting of β€œpositive” and β€œnegative” Set(fields={"classes": ["positive","negatives"], apply_to_stream=["train"]})

# Set field β€œclasses” to have the value of a given list, preventing modification of original list from changing the instance. Set(fields={"classes": alist}), use_deepcopy=True) if now alist is modified, still the instances remain intact.

Explanation about LoadJsonFileΒΆ

Loads data from JSON files.

Supports streaming and can handle large files by loading them in chunks.

Args:

files (Dict[str, str]): A dictionary mapping names to file paths. chunksize : Size of the chunks to load at a time. loader_limit: Optional integer to specify a limit on the number of records to load. streaming: Bool indicating if streaming should be used. lines: Bool indicate if it is json lines file structure. Otherwise, assumes a single json object in the file. data_field: optional field within the json object, that contains the list of instances.

Example:

Loading json lines

load_csv = LoadJsonFile(files={'train': 'path/to/train.jsonl'}, line=True, chunksize=100)

References: metrics.llm_as_judge.direct.criteria.summarization_relevance, processors.cast_to_float_return_nan_if_failed, metrics.spearman, metrics.pearson, templates.empty

Read more about catalog usage here.