π Granite Guardian GroundednessΒΆ
metrics.rag.granite_guardian_groundedness
MetricPipeline(
main_score="granite_guardian_groundedness",
metric=GraniteGuardianRagRisk(
main_score="granite_guardian_groundedness",
risk_name="groundedness",
user_message_field="question",
assistant_message_field="answer",
),
preprocess_steps=[
Join(
field="contexts",
by="
",
),
Copy(
field_to_field={
"ground_truths": "task_data/ground_truths",
"answer": "task_data/answer",
"contexts": "task_data/context",
"question": "task_data/question",
},
not_exist_do_nothing=True,
),
Copy(
field_to_field={
"prediction": "task_data/answer",
},
not_exist_do_nothing=True,
),
Set(
fields={
"prediction": 0.0,
"references": [
0.0,
],
},
),
],
)
[source]from unitxt.metrics import GraniteGuardianRagRisk
from unitxt.operators import Copy, Set
from unitxt.string_operators import Join
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.
Read more about catalog usage here.