| 93 | return model |
| 94 | |
| 95 | def extract_ans(ans, mode): |
| 96 | ans_line = re.split("Q:", ans, flags=re.IGNORECASE)[0] |
| 97 | ans_line = re.split('answer is ', ans_line, flags=re.IGNORECASE) |
| 98 | # Expect to see 'answer is'. If not return whole string |
| 99 | if len(ans_line) == 1: |
| 100 | return ans |
| 101 | else: |
| 102 | ans = ans_line[-1].strip() |
| 103 | |
| 104 | if mode == 'multiple_choice': |
| 105 | match = re.search(r'\(([A-Z])\)*', ans) |
| 106 | if match: |
| 107 | return match.group(1) |
| 108 | match = re.search(r'([A-Z])', ans) |
| 109 | if match: |
| 110 | return match.group(1) |
| 111 | return ans |
| 112 | elif mode == 'free_form': |
| 113 | ans = re.split(r'[.#]', ans)[0] |
| 114 | return ans |
| 115 | |
| 116 | def batch_data(prompts, batch_size=1): |
| 117 | batch_data = [] |