v2.0: Force function renaming before test execution
Browse files- scripts/eval_mbpp_hf.py +16 -2
scripts/eval_mbpp_hf.py
CHANGED
|
@@ -6,7 +6,8 @@
|
|
| 6 |
MBPP Evaluation: Base Devstral vs Fine-tuned Alizee-Coder
|
| 7 |
Runs on HF Jobs with GPU support
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
"""
|
| 11 |
|
| 12 |
import os
|
|
@@ -232,8 +233,21 @@ def evaluate_model(model, tokenizer, dataset, model_name, is_finetuned=False):
|
|
| 232 |
return samples
|
| 233 |
|
| 234 |
def run_tests(code, test_list):
|
| 235 |
-
"""Run test cases on generated code"""
|
| 236 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
# Create execution environment
|
| 238 |
exec_globals = {}
|
| 239 |
exec(code, exec_globals)
|
|
|
|
| 6 |
MBPP Evaluation: Base Devstral vs Fine-tuned Alizee-Coder
|
| 7 |
Runs on HF Jobs with GPU support
|
| 8 |
|
| 9 |
+
VERSION: 2.0 - Force function renaming before test execution
|
| 10 |
+
FIXED: Extract expected function name and rename generated function to match
|
| 11 |
"""
|
| 12 |
|
| 13 |
import os
|
|
|
|
| 233 |
return samples
|
| 234 |
|
| 235 |
def run_tests(code, test_list):
|
| 236 |
+
"""Run test cases on generated code with automatic function renaming"""
|
| 237 |
try:
|
| 238 |
+
# Extract expected function name from first test
|
| 239 |
+
expected_func = extract_function_name(test_list)
|
| 240 |
+
|
| 241 |
+
# If we found an expected name, rename the function in code
|
| 242 |
+
if expected_func and code:
|
| 243 |
+
# Find the actual function name in generated code
|
| 244 |
+
match = re.search(r'def\s+(\w+)\s*\(', code)
|
| 245 |
+
if match:
|
| 246 |
+
actual_func = match.group(1)
|
| 247 |
+
if actual_func != expected_func:
|
| 248 |
+
# Rename the function to match expected name
|
| 249 |
+
code = re.sub(r'\b' + re.escape(actual_func) + r'\b', expected_func, code)
|
| 250 |
+
|
| 251 |
# Create execution environment
|
| 252 |
exec_globals = {}
|
| 253 |
exec(code, exec_globals)
|