Skip to content

Commit

Permalink
Adapt rag granite guardian prepare file and catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
martinscooper committed Feb 7, 2025
1 parent 760575c commit a5cc196
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
9 changes: 8 additions & 1 deletion prepare/metrics/rag_granite_guardian.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unitxt import add_to_catalog
from unitxt.metrics import GraniteGuardianWMLMetric, MetricPipeline
from unitxt.operators import Copy, Set
from unitxt.string_operators import Join

rag_fields = ["ground_truths", "answer", "contexts", "question"]

Expand All @@ -24,14 +25,20 @@
metric = GraniteGuardianWMLMetric(
main_score=metric_name,
risk_name=granite_risk_name,
user_message_field="question",
assistant_message_field="answer",
)

metric_pipeline = MetricPipeline(
main_score=metric_name,
metric=metric,
preprocess_steps=[
Join(
field="contexts",
by="\n"
),
Copy(
field_to_field={field: f"task_data/{field}" for field in rag_fields},
field_to_field={field: f"task_data/{field if field != 'contexts' else 'context'}" for field in rag_fields},
not_exist_do_nothing=True,
),
Copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
"metric": {
"__type__": "granite_guardian_wml_metric",
"main_score": "granite_guardian_answer_relevance",
"risk_name": "answer_relevance"
"risk_name": "answer_relevance",
"user_message_field": "question",
"assistant_message_field": "answer"
},
"preprocess_steps": [
{
"__type__": "join",
"field": "contexts",
"by": "\n"
},
{
"__type__": "copy",
"field_to_field": {
"ground_truths": "task_data/ground_truths",
"answer": "task_data/answer",
"contexts": "task_data/contexts",
"contexts": "task_data/context",
"question": "task_data/question"
},
"not_exist_do_nothing": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
"metric": {
"__type__": "granite_guardian_wml_metric",
"main_score": "granite_guardian_context_relevance",
"risk_name": "context_relevance"
"risk_name": "context_relevance",
"user_message_field": "question",
"assistant_message_field": "answer"
},
"preprocess_steps": [
{
"__type__": "join",
"field": "contexts",
"by": "\n"
},
{
"__type__": "copy",
"field_to_field": {
"ground_truths": "task_data/ground_truths",
"answer": "task_data/answer",
"contexts": "task_data/contexts",
"contexts": "task_data/context",
"question": "task_data/question"
},
"not_exist_do_nothing": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
"metric": {
"__type__": "granite_guardian_wml_metric",
"main_score": "granite_guardian_groundedness",
"risk_name": "groundedness"
"risk_name": "groundedness",
"user_message_field": "question",
"assistant_message_field": "answer"
},
"preprocess_steps": [
{
"__type__": "join",
"field": "contexts",
"by": "\n"
},
{
"__type__": "copy",
"field_to_field": {
"ground_truths": "task_data/ground_truths",
"answer": "task_data/answer",
"contexts": "task_data/contexts",
"contexts": "task_data/context",
"question": "task_data/question"
},
"not_exist_do_nothing": true
Expand Down

0 comments on commit a5cc196

Please sign in to comment.