-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding generic inference binary+idk judges (#1316)
* generic llm as a judge for binary and idk Signed-off-by: Roni Friedman-Melamed <[email protected]> * unify generic inference label Signed-off-by: Roni Friedman-Melamed <[email protected]> * ruff Signed-off-by: Roni Friedman-Melamed <[email protected]> * fix processor bug Signed-off-by: lilacheden <[email protected]> --------- Signed-off-by: Roni Friedman-Melamed <[email protected]> Co-authored-by: lilacheden <[email protected]> Co-authored-by: Yotam Perlitz <[email protected]>
- Loading branch information
1 parent
582d96f
commit e5b8355
Showing
12 changed files
with
163 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,46 @@ | ||
from unitxt import add_to_catalog | ||
from unitxt.inference import ( | ||
GenericInferenceEngine, | ||
IbmGenAiInferenceEngine, | ||
IbmGenAiInferenceEngineParams, | ||
) | ||
from unitxt.llm_as_judge import LLMAsJudge | ||
|
||
platform = "ibm_gen_ai" | ||
gen_params = IbmGenAiInferenceEngineParams(max_new_tokens=256) | ||
|
||
model_name = "meta-llama/llama-3-70b-instruct" | ||
template_name = "templates.response_assessment.judges.idk.v1" | ||
|
||
inference_model = IbmGenAiInferenceEngine(model_name=model_name, parameters=gen_params) | ||
|
||
model_label = model_name.split("/")[1].replace("-", "") | ||
template_label = template_name.split(".")[-1] | ||
|
||
metric_label = ( | ||
"metrics.llm_as_judge.rating." + model_label + "_template_" + template_label | ||
) | ||
|
||
cur_metric = LLMAsJudge( | ||
inference_model=inference_model, | ||
template=template_name, | ||
task="rating.single_turn", | ||
main_score=metric_label, | ||
prediction_type="str", | ||
) | ||
|
||
# _description__= "Does the model response say I don't know?" | ||
|
||
add_to_catalog( | ||
cur_metric, | ||
"metrics.llm_as_judge.conversation_answer_idk.llama3_v1_ibmgenai_judges", | ||
overwrite=True, | ||
) | ||
inference_models = { | ||
"llama3_v1_ibmgenai": { | ||
"model_name": "llama370binstruct", | ||
"inference_model": IbmGenAiInferenceEngine( | ||
model_name="meta-llama/llama-3-70b-instruct", | ||
parameters=IbmGenAiInferenceEngineParams(max_new_tokens=256), | ||
), | ||
}, | ||
"generic_inference_engine": { | ||
"model_name": "generic", | ||
"inference_model": (GenericInferenceEngine()), | ||
}, | ||
} | ||
|
||
for label, inference_model in inference_models.items(): | ||
model_label = inference_model["model_name"] | ||
template_label = template_name.split(".")[-1] | ||
metric_label = ( | ||
"metrics.llm_as_judge.rating." + model_label + "_template_" + template_label | ||
) | ||
|
||
cur_metric = LLMAsJudge( | ||
inference_model=inference_model["inference_model"], | ||
template=template_name, | ||
task="rating.single_turn", | ||
main_score=metric_label, | ||
prediction_type="str", | ||
) | ||
|
||
# _description__= "Does the model response say I don't know?" | ||
|
||
add_to_catalog( | ||
cur_metric, | ||
f"metrics.llm_as_judge.conversation_answer_idk.{label}_judges", | ||
overwrite=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...metrics/llm_as_judge/binary/generic_inference_engine_answer_correctness_q_a_gt_loose.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"__type__": "task_based_ll_mas_judge", | ||
"inference_model": { | ||
"__type__": "generic_inference_engine" | ||
}, | ||
"template": "templates.rag_eval.answer_correctness.judge_loose_match_no_context", | ||
"task": "tasks.rag_eval.answer_correctness.binary", | ||
"format": "formats.empty", | ||
"main_score": "answer_correctness_q_a_gt_loose", | ||
"prediction_field": "answer", | ||
"infer_log_probs": false | ||
} |
12 changes: 12 additions & 0 deletions
12
...etrics/llm_as_judge/binary/generic_inference_engine_answer_correctness_q_a_gt_strict.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"__type__": "task_based_ll_mas_judge", | ||
"inference_model": { | ||
"__type__": "generic_inference_engine" | ||
}, | ||
"template": "templates.rag_eval.answer_correctness.judge_simplified_format", | ||
"task": "tasks.rag_eval.answer_correctness.binary", | ||
"format": "formats.empty", | ||
"main_score": "answer_correctness_q_a_gt_strict", | ||
"prediction_field": "answer", | ||
"infer_log_probs": false | ||
} |
12 changes: 12 additions & 0 deletions
12
...xt/catalog/metrics/llm_as_judge/binary/generic_inference_engine_answer_relevance_q_a.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"__type__": "task_based_ll_mas_judge", | ||
"inference_model": { | ||
"__type__": "generic_inference_engine" | ||
}, | ||
"template": "templates.rag_eval.answer_relevance.judge_answer_relevance", | ||
"task": "tasks.rag_eval.answer_relevance.binary", | ||
"format": "formats.empty", | ||
"main_score": "answer_relevance_q_a", | ||
"prediction_field": "answer", | ||
"infer_log_probs": false | ||
} |
12 changes: 12 additions & 0 deletions
12
...alog/metrics/llm_as_judge/binary/generic_inference_engine_context_relevance_q_c_ares.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"__type__": "task_based_ll_mas_judge", | ||
"inference_model": { | ||
"__type__": "generic_inference_engine" | ||
}, | ||
"template": "templates.rag_eval.context_relevance.judge_context_relevance_ares", | ||
"task": "tasks.rag_eval.context_relevance.binary", | ||
"format": "formats.empty", | ||
"main_score": "context_relevance_q_c_ares", | ||
"prediction_field": null, | ||
"infer_log_probs": false | ||
} |
12 changes: 12 additions & 0 deletions
12
...alog/metrics/llm_as_judge/binary/generic_inference_engine_correctness_holistic_q_c_a.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"__type__": "task_based_ll_mas_judge", | ||
"inference_model": { | ||
"__type__": "generic_inference_engine" | ||
}, | ||
"template": "templates.rag_eval.correctness_holistic.judge_correctness_simple", | ||
"task": "tasks.rag_eval.correctness_holistic.binary", | ||
"format": "formats.empty", | ||
"main_score": "correctness_holistic_q_c_a", | ||
"prediction_field": "answer", | ||
"infer_log_probs": false | ||
} |
12 changes: 12 additions & 0 deletions
12
...unitxt/catalog/metrics/llm_as_judge/binary/generic_inference_engine_faithfulness_c_a.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"__type__": "task_based_ll_mas_judge", | ||
"inference_model": { | ||
"__type__": "generic_inference_engine" | ||
}, | ||
"template": "templates.rag_eval.faithfulness.judge_no_question_simplified", | ||
"task": "tasks.rag_eval.faithfulness.binary", | ||
"format": "formats.empty", | ||
"main_score": "faithfulness_c_a", | ||
"prediction_field": "answer", | ||
"infer_log_probs": false | ||
} |
12 changes: 12 additions & 0 deletions
12
...itxt/catalog/metrics/llm_as_judge/binary/generic_inference_engine_faithfulness_q_c_a.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"__type__": "task_based_ll_mas_judge", | ||
"inference_model": { | ||
"__type__": "generic_inference_engine" | ||
}, | ||
"template": "templates.rag_eval.faithfulness.judge_with_question_simplified", | ||
"task": "tasks.rag_eval.faithfulness.binary", | ||
"format": "formats.empty", | ||
"main_score": "faithfulness_q_c_a", | ||
"prediction_field": "answer", | ||
"infer_log_probs": false | ||
} |
10 changes: 10 additions & 0 deletions
10
...catalog/metrics/llm_as_judge/conversation_answer_idk/generic_inference_engine_judges.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"__type__": "llm_as_judge", | ||
"inference_model": { | ||
"__type__": "generic_inference_engine" | ||
}, | ||
"template": "templates.response_assessment.judges.idk.v1", | ||
"task": "rating.single_turn", | ||
"main_score": "metrics.llm_as_judge.rating.generic_template_v1", | ||
"prediction_type": "str" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ | |
"operator": { | ||
"__type__": "cast", | ||
"to": "float", | ||
"failure_default": { | ||
"float": 0.5 | ||
} | ||
"failure_default": 0.5 | ||
} | ||
} |