(direct_answer_trigger_for_fewshot: tuple, pred: str)
| 54 | return pred |
| 55 | |
| 56 | def 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 |
nothing calls this directly
no test coverage detected