MCPcopy Create free account
hub / github.com/Alpha-VLLM/LLaMA2-Accessory / extract_ans

Function extract_ans

light-eval/src/eval_gsm8k.py:95–124  ·  view source on GitHub ↗
(completion)

Source from the content-addressed store, hash-verified

93 return False
94
95def 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
126def batch_data(prompts, batch_size=1):
127 batch_data = []

Callers 1

run_evalFunction · 0.70

Calls 1

is_numberFunction · 0.85

Tested by

no test coverage detected