π CoherenceΒΆ
cards.judge_bench.roscoe.overall.esnli.coherence
TaskCard(
loader=LoadJsonFile(
files={
"test": "https://raw.githubusercontent.com/dmg-illc/JUDGE-BENCH/refs/heads/master/data/roscoe/roscoe-esnli-overall.json",
},
data_classification_policy=[
"public",
],
data_field="instances",
),
preprocess_steps=[
GroupDictWithRegex(
field="instance",
pattern=".*?Situation \(Premise\):\s+(?P<premise>.*?)\s+Claim \(Hypothesis\):\s+(?P<hypothesis>.*?)\s+Is the Claim supported by the Situation\?\s+Correct Relationship \(Yes or No\):\s(?P<correct_answer>.*?)\s+GENERATED RESPONSE:\s+(?P<model_reasoning>.*?)\s+Judge the generated response:",
flags=16,
),
Rename(
field_to_field={
"instance/premise": "premise",
"instance/hypothesis": "hypothesis",
"instance/model_reasoning": "generated response",
"instance/correct_answer": "correct answer",
"annotations/Coherency/mean_human": "mean_score",
},
),
Cast(
field="mean_score",
to="float",
),
ExecuteExpression(
expression="(mean_score - 1) / 4",
to_field="mean_score",
),
Set(
fields={
"criteria": "metrics.llm_as_judge.direct.criteria.step_by_step_reasoning_coherency",
"question": "Is the Hypothesis supported by the Premise?",
},
),
],
task=Task(
input_fields={
"premise": "str",
"hypothesis": "str",
"question": "str",
"generated response": "str",
"correct answer": "str",
"criteria": "Any",
},
reference_fields={
"mean_score": "float",
},
prediction_type="float",
metrics=[
"metrics.pearson",
"metrics.spearman",
],
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:
βinput_fieldsβ whose value is a sub-dictionary of the input instance, consisting of all the fields listed in Arg βinput_fieldsβ.
βreference_fieldsβ β for the fields listed in Arg βreference_fieldsβ.
β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.step_by_step_reasoning_coherency, processors.cast_to_float_return_nan_if_failed, metrics.spearman, metrics.pearson, templates.empty
Read more about catalog usage here.