MCPcopy Create free account
hub / github.com/InternScience/SciReason / answer_clean

Function answer_clean

opencompass/datasets/TheoremQA/utils.py:56–92  ·  view source on GitHub ↗
(direct_answer_trigger_for_fewshot: tuple, pred: str)

Source from the content-addressed store, hash-verified

54 return pred
55
56def answer_clean(direct_answer_trigger_for_fewshot: tuple, pred: str):
57 pred = pred.strip('\n')
58
59 # Determine if this is ICL, if so, use \n\n to split the first chunk.
60 ICL = False
61 for trigger in direct_answer_trigger_for_fewshot:
62 if pred.count(trigger) > 1:
63 ICL = True
64 if ICL:
65 pred = pred.split('\n\n')[0]
66
67 # Split the trigger to find the answer.
68 preds = re.split('|'.join(direct_answer_trigger_for_fewshot), pred)
69 if len(preds) > 1:
70 answer_flag = True
71 pred = preds[-1]
72 else:
73 answer_flag = False
74
75 pred = pred.strip('\n').rstrip('.').rstrip('/').strip(' ')
76
77 pred = [extract_theoremqa_answer(pred, answer_flag)]
78
79 # If there is no candidate in list, null is set.
80 if len(pred) == 0:
81 pred = ""
82 else:
83 if answer_flag:
84 # choose the first element in list ...
85 pred = pred[0]
86 else:
87 # choose the last e
88 pred = pred[-1]
89
90 # Remove the period at the end, again!
91 pred = pred.rstrip('.').rstrip('/')
92 return pred
93
94
95

Callers

nothing calls this directly

Calls 1

extract_theoremqa_answerFunction · 0.85

Tested by

no test coverage detected