Skip to content

Commit

Permalink
Improve robustness of prediction extraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
waleedkadous committed Apr 1, 2024
1 parent f44e09f commit e9c1462
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tests/test_answer_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ def answer_question(question, q_temp, cache):


def extract_prediction(row):
raw = row["json_prediction"]
raw = raw.replace("```", "")
raw = raw.replace("json", "")
raw = "{" + raw.split("{")[1]
raw = raw.split("}")[0] + "}"
raw = raw.strip()
LOGGER.info(f"raw is: {raw}")
raw_dict = json.loads(raw)
return str(raw_dict["answer"])
try:
raw = row["json_prediction"]
raw = raw.replace("```", "")
raw = raw.replace("json", "")
raw = "{" + raw.split("{")[1]
raw = raw.split("}")[0] + "}"
raw = raw.strip()
LOGGER.info(f"raw is: {raw}")
raw_dict = json.loads(raw)
return str(raw_dict["answer"])
except IndexError:
return "OUTPUT_PARSE_ERROR"


def is_correct(row):
Expand Down

0 comments on commit e9c1462

Please sign in to comment.