MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / evaluate

Function evaluate

eval/Coding/mbpp/evaluate_mbpp.py:102–146  ·  view source on GitHub ↗
(dataset)

Source from the content-addressed store, hash-verified

100 exec(compile(code, filename="mbpp", mode='exec'), globals())
101
102def evaluate(dataset):
103 correct = 0
104 format_error = 0
105 exec_error = 0
106
107 for example in dataset.to_dict(orient="records"):
108 completion = example["completion"]
109 # remove texts
110 code = completion.split("\n")
111 code_ = []
112 for c in code:
113 if len(c.lstrip()) == len(c) and not c.startswith("def"):
114 continue
115 code_.append(c)
116 code = "\n".join(code_)
117
118 function = code
119 test_cases = "\n".join(example["test_list"]).replace("\/", "/")
120 test_run = "\n".join([
121 function,
122 test_cases,
123 ])
124
125 # define function
126 try:
127 exec_helper(function)
128 except Exception as e:
129 print(function)
130 print("Error",e)
131 format_error += 1
132 continue
133
134 try:
135 # run test case
136 exec_helper(test_cases)
137 exec_helper(test_run)
138 except:
139 exec_error += 1
140 continue
141 else:
142 correct += 1
143 print("correct: ", correct)
144 print("exec_error: ", exec_error)
145 print("format_error: ", format_error)
146 return 100 * (correct / len(dataset)), 100 * (exec_error / len(dataset)), 100 * (format_error / len(dataset))
147
148
149if __name__ == "__main__":

Callers 1

evaluate_mbpp.pyFile · 0.70

Calls 2

exec_helperFunction · 0.85
to_dictMethod · 0.80

Tested by

no test coverage detected