Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ragas/metrics/_answer_correctness.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def _score_batch(
prediction = (
prediction if isinstance(prediction, list) else [prediction]
)

if prediction:
prediction = [
item.get(key_map[k], np.nan)
Expand All @@ -152,7 +153,11 @@ def _score_batch(
len(item) if isinstance(item, list) else np.nan
for item in prediction
]
score = tp / (tp + 0.5 * (fp + fn))

if any([np.isnan(i) for i in [tp, fp, fn]]):
score = np.nan
else:
score = tp / (tp + 0.5 * (fp + fn)) if tp > 0 else 0
else:
score = np.nan

Expand Down