(res_file: str, react: bool = False)
| 16 | |
| 17 | |
| 18 | def eval_jsonl(res_file: str, react: bool = False) -> float: |
| 19 | cnt, total = 0, 0 |
| 20 | with open(res_file, "r") as f: |
| 21 | for line in tqdm(f): |
| 22 | d = json.loads(line.strip()) |
| 23 | answer = d["answer"] |
| 24 | if react: |
| 25 | # react is the only one solution. |
| 26 | last_tag = sorted(d["react"].keys(), key=lambda x: len(x), reverse=True)[0] |
| 27 | prediction = d["react"][last_tag]["final_answer"] |
| 28 | else: |
| 29 | if d["react"]["solutions"]: |
| 30 | # get top-1 |
| 31 | prediction = d["react"]["solutions"][0]["final_answer"] |
| 32 | else: |
| 33 | prediction = "" |
| 34 | if math_is_equiv(answer, prediction): |
| 35 | cnt += 1 |
| 36 | total += 1 |
| 37 | return cnt / total |
| 38 | |
| 39 | |
| 40 | if __name__ == '__main__': |
no test coverage detected