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

Function parse_float_answer

opencompass/datasets/matbench/post_process.py:103–133  ·  view source on GitHub ↗
(sentence)

Source from the content-addressed store, hash-verified

101
102
103def parse_float_answer(sentence):
104 # Correctly apply remove_formula to the sentence
105 sentence = remove_formula(sentence)
106
107 # First, look for formatted answer:number (case-insensitive, no spaces)
108 processed_string = sentence.lower().replace(" ", "")
109 answer_matches = re.findall(r'answer:(-?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?)', processed_string)
110 if answer_matches:
111 try:
112 return verify_float(float(answer_matches[-1]))
113 except ValueError:
114 pass
115
116 # Then find all scientific notation numbers, take the last one
117 sci_matches = re.findall(r'-?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?', sentence)
118 if sci_matches:
119 try:
120 return verify_float(float(sci_matches[-1]))
121 except ValueError:
122 pass
123
124 # Lastly, find all regular floats, take the last one
125 float_matches = re.findall(r'-?\d+(?:\.\d+)?', sentence)
126 if float_matches:
127 try:
128 return verify_float(float(float_matches[-1]))
129 except ValueError:
130 pass
131
132 # If no valid number found, return 0.0
133 return 0.0
134
135
136def parse_true_false_answer(raw_string, option=''):

Callers 1

scoreMethod · 0.90

Calls 4

remove_formulaFunction · 0.85
verify_floatFunction · 0.85
replaceMethod · 0.80
lowerMethod · 0.45

Tested by

no test coverage detected