Skip to content

Commit

Permalink
Fixes in LLMJudge (#1498)
Browse files Browse the repository at this point in the history
* bugfix in LLMJudge - allow changing main_score and score_prefix
Signed-off-by: lilacheden <[email protected]>

* Support embedded task data fields in LLMJudge template
Signed-off-by: lilacheden <[email protected]>

* add main_score to results
Signed-off-by: lilacheden <[email protected]>

* support dict llmjudge contexts_fields
Signed-off-by: lilacheden <[email protected]>

* Revert "bugfix in LLMJudge - allow changing main_score and score_prefix"

This reverts commit c94bfc5.

* Revert "add main_score to results"

This reverts commit 9754a63.

---------

Co-authored-by: Elron Bandel <[email protected]>
  • Loading branch information
lilacheden and elronbandel authored Jan 16, 2025
1 parent 347f6e1 commit 5506f9c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/unitxt/llm_as_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from .api import infer
from .artifact import fetch_artifact
from .dict_utils import dict_get
from .error_utils import UnitxtError
from .inference import (
InferenceEngine,
Expand Down Expand Up @@ -59,7 +60,7 @@ class LLMJudge(BulkInstanceMetric):
# )
evaluator_name: EvaluatorNameEnum = None
check_positional_bias: bool = True
context_fields: str = ["context"]
context_fields: Union[str, List[str], Dict[str, str]] = ["context"]
generate_summaries: bool = True
format = "formats.chat_api"
include_prompts_in_result: bool = False
Expand All @@ -71,6 +72,10 @@ def prepare(self):
super().prepare()
if isinstance(self.context_fields, str):
self.context_fields = [self.context_fields]
if isinstance(self.context_fields, List):
self.context_fields = {
context_field: context_field for context_field in self.context_fields
}

# if not isinstance(self.option_selection_strategy, OptionSelectionStrategyEnum):
# self.option_selection_strategy = OptionSelectionStrategyEnum[
Expand Down Expand Up @@ -149,8 +154,8 @@ def get_contexts(self, task_data: List[Dict[str, Any]]) -> List[Dict[str, str]]:
return [
get_parsed_context(
{
context_field: td[context_field]
for context_field in self.context_fields
context_field_name: dict_get(td, context_field)
for context_field_name, context_field in self.context_fields.items()
}
)
for td in task_data
Expand Down

0 comments on commit 5506f9c

Please sign in to comment.