Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: elronbandel <[email protected]>
  • Loading branch information
elronbandel committed Dec 23, 2024
1 parent 4d9737a commit dfd2178
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/unitxt/llm_as_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ def perform_evaluation_step(
return_data=True,
previous_messages=previous_messages,
)
prompts: list[str] = [instance["source"] for instance in outputs_dataset]
raw_predictions: list[str] = [
prompts: List[str] = [instance["source"] for instance in outputs_dataset]
raw_predictions: List[str] = [
instance["raw_prediction"] for instance in outputs_dataset
]
predictions: list[str] = [
predictions: List[str] = [
instance["prediction"] for instance in outputs_dataset
]
return (prompts, raw_predictions, predictions)
Expand Down Expand Up @@ -274,7 +274,7 @@ def get_criterias(self, task_data, eval_count):
raise Exception(
f"The type of the criteria must be 'CriteriaWithOptions', instead it is of type '{type(self.criteria)}'"
)
criterias: list[CriteriaWithOptions] = [self.criteria] * eval_count
criterias: List[CriteriaWithOptions] = [self.criteria] * eval_count
unique_criterias = list({criteria.name for criteria in criterias})
self.logger.info(f"Criteria names are '{', '.join(unique_criterias)}'")
return criterias
Expand All @@ -289,7 +289,7 @@ def get_results(
option_selection_outputs,
selections,
evaluations_count,
criterias: list[CriteriaWithOptions],
criterias: List[CriteriaWithOptions],
) -> list[dict[str, any]]:
positional_bias = None
if self.check_positional_bias:
Expand Down Expand Up @@ -545,7 +545,7 @@ def get_criterias(self, task_data, eval_count):
f"The type of the criteria must be 'Criteria', instead it is of type '{type(self.criteria)}'"
)

criterias: list[Criteria] = [self.criteria] * eval_count
criterias: List[Criteria] = [self.criteria] * eval_count

unique_criterias = list({criteria.name for criteria in criterias})
self.logger.info(f"Criteria names are '{', '.join(unique_criterias)}'")
Expand Down Expand Up @@ -728,7 +728,7 @@ def get_instance_results(
all_results["criteria"] = criteria.to_json()
return self.clean_results(all_results)

def parse_prediction_to_dict(self, prediction: Union[Dict[str, str], list[str]]):
def parse_prediction_to_dict(self, prediction: Union[Dict[str, str], List[str]]):
if isinstance(prediction, list):
return {f"{key + 1}": value for key, value in enumerate(prediction)}

Expand All @@ -740,15 +740,15 @@ def parse_prediction_to_dict(self, prediction: Union[Dict[str, str], list[str]])
)

def convert_predictions_to_dicts(
self, predictions: Union[list[Dict[str, str], list[str]]]
self, predictions: Union[List[Dict[str, str], List[str]]]
):
return [self.parse_prediction_to_dict(prediction) for prediction in predictions]

def compute(
self,
references: list[list[str]],
predictions: Union[list[Dict[str, str], list[str]]],
task_data: list[Dict[str, str]],
references: List[List[str]],
predictions: Union[List[Dict[str, str], List[str]]],
task_data: List[Dict[str, str]],
) -> dict:
self.logger.info(
f'Starting evaluation with evaluator "{self.evaluator_name}" and provider {self.inference_engine.get_pretty_print_name()}'
Expand All @@ -775,8 +775,8 @@ def compute(
f"The evaluation will perform {sum(contests_count_list) * [1,2][self.check_positional_bias]} ({' + '.join([f'{c * [1,2][self.check_positional_bias]}' for c in contests_count_list])}) pairwise comparisons"
)

response_pairs_list: list[list[list[str]]] = []
option_pairs_list: list[list[list[str]]] = []
response_pairs_list: List[List[List[str]]] = []
option_pairs_list: List[List[List[str]]] = []
predictions_names = set(predictions[0].keys())
for i, combination_indexes in enumerate(combination_indexes_list):
instance_predictions = predictions[i]
Expand All @@ -786,8 +786,8 @@ def compute(
f"The set of prediction names is different between instance 0 and instance {i}. In prediction 0, it is {sorted(predictions_names)}. In prediction {i}, it is {sorted(instance_predictions_names)}. Make sure the same number of predictions is passed for all instances."
)

response_pairs: list[list[str]] = []
option_pairs: list[list[str]] = []
response_pairs: List[List[str]] = []
option_pairs: List[List[str]] = []
for combination in combination_indexes:
(idx_1, idx_2) = combination
response_name_1 = instance_predictions_names[idx_1]
Expand Down

0 comments on commit dfd2178

Please sign in to comment.