Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use iloc when computing faithfulness metric #11117

Merged
merged 3 commits into from Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion mlflow/metrics/genai/genai_metric.py
Expand Up @@ -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())}."
Expand Down
8 changes: 8 additions & 0 deletions tests/metrics/genai/test_genai_metrics.py
Expand Up @@ -769,6 +769,14 @@ def test_faithfulness_metric():
examples=[mlflow_example],
)

faithfulness_metric.eval_fn(
# Inputs with different indices
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the error is rather because of index not starting from 0 I guess?

for indx, (input, output) in enumerate(zip(inputs, outputs)):
            try:
                arg_string = _format_args_string(grading_context_columns, eval_values, indx)

The indx always starts from 0 (cuz we do enumerate) and eval_values[0] will raise KeyError if it doesn't have index 0.

Copy link
Member Author

@harupy harupy Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, reset_index(drop=True) should also work as @ai-learner-00 explained in #11108

Copy link
Collaborator

@B-Step62 B-Step62 Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup I think the current solution is fine, plz feel free to merge. Just wanted to make sure the ^comment is accurate:)

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()
Expand Down