Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor hallucination score calculation in _faithfulness.py
Browse files Browse the repository at this point in the history
Yongtae723 committed Nov 20, 2023
1 parent d501dbf commit 7975ffa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ragas/metrics/_faithfulness.py
Original file line number Diff line number Diff line change
@@ -113,18 +113,18 @@ def _score_batch(
output = output[0].text.lower().strip()
if final_answer in output:
output = output[output.find(final_answer) + len(final_answer) :]
score = sum(
hallucination_score = sum(
0 if "yes" in answer else 1
for answer in output.strip().split(".")
if answer != ""
)
score = score / len(list_statements[i])
hallucination_ratio = hallucination_score / len(list_statements[i])
else:
score = max(0, output.count("verdict: no")) / len(
hallucination_ratio = max(0, output.count("verdict: no")) / len(
list_statements[i]
)

scores.append(1 - score)
scores.append(1 - hallucination_ratio)

return scores

0 comments on commit 7975ffa

Please sign in to comment.