| 93 | return False |
| 94 | |
| 95 | def extract_ans(completion): |
| 96 | |
| 97 | text = re.split("Question:", completion, flags=re.IGNORECASE)[0] |
| 98 | text = re.split("answer is ", text, flags=re.IGNORECASE) |
| 99 | |
| 100 | if len(text) > 1: |
| 101 | extract_ans = text[-1].strip() |
| 102 | match = re.search(r'[\-+]?\d*[\.,/]?\d+', extract_ans) |
| 103 | if match: |
| 104 | if '/' in match.group(): |
| 105 | denominator = match.group().split('/')[1] |
| 106 | numerator = match.group().split('/')[0] |
| 107 | if is_number(denominator) == True and is_number(numerator) == True: |
| 108 | if denominator == '0': |
| 109 | return round(float(numerator.replace(',', ''))) |
| 110 | else: |
| 111 | frac = Fraction(match.group().replace(',', '')) |
| 112 | num_numerator = frac.numerator |
| 113 | num_denominator = frac.denominator |
| 114 | return round(float(num_numerator / num_denominator)) |
| 115 | else: |
| 116 | return None |
| 117 | else: |
| 118 | if float(match.group().replace(',', '')) == float('inf'): |
| 119 | return None |
| 120 | return round(float(match.group().replace(',', ''))) |
| 121 | else: |
| 122 | return None |
| 123 | else: |
| 124 | return None |
| 125 | |
| 126 | def batch_data(prompts, batch_size=1): |
| 127 | batch_data = [] |