From 054ae647e11fe870271338f527d141ea2e885908 Mon Sep 17 00:00:00 2001 From: Harutaka Kawamura Date: Wed, 14 Feb 2024 19:42:37 +0900 Subject: [PATCH] Use `iloc` when computing faithfulness metric (#11117) Signed-off-by: harupy <17039389+harupy@users.noreply.github.com> Signed-off-by: Arthur Jenoudet --- mlflow/metrics/genai/genai_metric.py | 8 +++++++- tests/metrics/genai/test_genai_metrics.py | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mlflow/metrics/genai/genai_metric.py b/mlflow/metrics/genai/genai_metric.py index 8feb2e35cf0d2..b77b53b9dcc94 100644 --- a/mlflow/metrics/genai/genai_metric.py +++ b/mlflow/metrics/genai/genai_metric.py @@ -28,10 +28,16 @@ def _format_args_string(grading_context_columns: Optional[List[str]], eval_values, indx) -> str: + import pandas as pd + args_dict = {} for arg in grading_context_columns: if arg in eval_values: - args_dict[arg] = eval_values[arg][indx] + args_dict[arg] = ( + eval_values[arg].iloc[indx] + if isinstance(eval_values[arg], pd.Series) + else eval_values[arg][indx] + ) else: raise MlflowException( f"{arg} does not exist in the eval function {list(eval_values.keys())}." diff --git a/tests/metrics/genai/test_genai_metrics.py b/tests/metrics/genai/test_genai_metrics.py index aa8e7bc45e4ed..8d5615160f539 100644 --- a/tests/metrics/genai/test_genai_metrics.py +++ b/tests/metrics/genai/test_genai_metrics.py @@ -769,6 +769,14 @@ def test_faithfulness_metric(): examples=[mlflow_example], ) + faithfulness_metric.eval_fn( + # Inputs with different indices + pd.Series([mlflow_prediction], index=[0]), + {}, + pd.Series([input], index=[1]), + pd.Series([mlflow_ground_truth], index=[2]), + ) + def test_answer_correctness_metric(): answer_correctness_metric = answer_correctness()