Skip to content

Commit

Permalink
chore: refactor evaluate function, same comlexity, better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
honghanhh committed Oct 17, 2024
1 parent 1006f98 commit 93d37f9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/questions_eval/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hydra
import pandas as pd
import wandb
import itertools
from datasets import load_dataset
from dotenv import load_dotenv
from langchain.output_parsers import OutputFixingParser
Expand Down Expand Up @@ -164,11 +165,12 @@ def evaluate(row, evaluation_chain) -> dict:
The evaluation results, including conformity, consistency and coverage
"""
results = {}
for i in ["synthetic_transcription", "transcription"]:
for j in ["synthetic_question", "question"]:
results[f"{i}/{j}"] = evaluation_chain.invoke(
{"transcription": row[i], "question": row[j]}
)
# Same time complexity as the nested loop O(1) but better readability and maintainability
for i, j in itertools.product(["synthetic_transcription", "transcription"], ["synthetic_question", "question"]):
results[f"{i}/{j}"] = evaluation_chain.invoke(
{"transcription": row[i], "question": row[j]}
)

# Compute conformity, consistency and coverage
coverage = 1 if is_idk(results["synthetic_transcription/question"]) else 0
consistency = 1 if not is_idk(results["transcription/synthetic_question"]) else 0
Expand Down

0 comments on commit 93d37f9

Please sign in to comment.