π ContradictionΒΆ
cards.judge_bench.roscoe.overall.esnli.contradiction
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/Contradiction/majority_human": "label",
},
),
MapInstanceValues(
mappers={
"label": {
"no": "No",
"yes": "Yes",
},
},
),
Copy(
field="label",
to_field="label_value",
),
MapInstanceValues(
mappers={
"label_value": {
"Yes": 0.0,
"No": 1.0,
},
},
),
Set(
fields={
"criteria": "metrics.llm_as_judge.direct.criteria.step_by_step_reasoning_contradiction",
"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={
"label_value": "float",
},
prediction_type="float",
metrics=[
"metrics.accuracy",
"metrics.f1_macro",
],
default_template="templates.empty[postprocessors=[processors.cast_to_float_return_nan_if_failed]]",
),
templates=[],
)
[source]from unitxt.loaders import LoadJsonFile
from unitxt.operators import Copy, MapInstanceValues, 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 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 that1was 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, usestrict=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 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 byCopy(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 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_contradiction, processors.cast_to_float_return_nan_if_failed, metrics.f1_macro, metrics.accuracy, templates.empty
Read more about catalog usage here.