Upload eval/eval_bert_router.py
Browse files- eval/eval_bert_router.py +61 -0
eval/eval_bert_router.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Evaluate BERT router on SWE-Router and compare with v11 XGBoost."""
|
| 2 |
+
import json, os, sys, random, pickle, math
|
| 3 |
+
import numpy as np
|
| 4 |
+
from collections import defaultdict
|
| 5 |
+
|
| 6 |
+
# ── Constants ──
|
| 7 |
+
MODELS = ['claude-opus-4.7','gpt-5-mini','gpt-5-nano','gpt-5.2',
|
| 8 |
+
'gemini-2.5-pro','gemini-3-pro','deepseek-v3.2','deepseek-v4-flash']
|
| 9 |
+
|
| 10 |
+
MODEL_TIER = {
|
| 11 |
+
'deepseek-v4-flash': 1, 'gpt-5-nano': 1,
|
| 12 |
+
'gpt-5-mini': 2, 'deepseek-v3.2': 2,
|
| 13 |
+
'gemini-2.5-pro': 3,
|
| 14 |
+
'claude-opus-4.7': 4, 'gpt-5.2': 4,
|
| 15 |
+
'gemini-3-pro': 5,
|
| 16 |
+
}
|
| 17 |
+
TIER_COST = {1:0.01, 2:0.05, 3:0.15, 4:0.30, 5:0.50}
|
| 18 |
+
TIER_TO_SWE = {
|
| 19 |
+
1: 'deepseek-v4-flash', 2: 'gpt-5-mini',
|
| 20 |
+
3: 'gemini-2.5-pro', 4: 'claude-opus-4.7', 5: 'gemini-3-pro',
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# ── Feature extraction (same as training) ──
|
| 24 |
+
CODE_KW = ["python","javascript","code","function","bug","debug","refactor","implement","test",
|
| 25 |
+
"compile","runtime","segfault","thread","async","class","module","import","error","traceback"]
|
| 26 |
+
LEGAL_KW = ["contract","legal","compliance","gdpr","privacy","policy","regulatory","liability"]
|
| 27 |
+
RESEARCH_KW = ["research","investigate","compare","analyze","survey","paper"]
|
| 28 |
+
TOOL_KW = ["search","fetch","retrieve","query","api","database","scrape","aggregate"]
|
| 29 |
+
CRITICAL_KW = ["critical","production","urgent","emergency","live","deployed","safety","security"]
|
| 30 |
+
SIMPLE_KW = ["typo","simple","quick","brief","minor","small","easy","trivial","just"]
|
| 31 |
+
LONG_KW = ["plan","project","roadmap","orchestrate","migrate","pipeline","deploy","architecture"]
|
| 32 |
+
MATH_KW = ["calculate","compute","solve","equation","formula","optimize","probability"]
|
| 33 |
+
|
| 34 |
+
def extract_features(problem_text):
|
| 35 |
+
r = problem_text.lower()
|
| 36 |
+
feats = {
|
| 37 |
+
'req_len': len(problem_text), 'num_words': len(problem_text.split()),
|
| 38 |
+
'has_code': int(any(k in r for k in CODE_KW)),
|
| 39 |
+
'n_code': sum(1 for k in CODE_KW if k in r),
|
| 40 |
+
'has_legal': int(any(k in r for k in LEGAL_KW)),
|
| 41 |
+
'has_research': int(any(k in r for k in RESEARCH_KW)),
|
| 42 |
+
'has_tool': int(any(k in r for k in TOOL_KW)),
|
| 43 |
+
'has_critical': int(any(k in r for k in CRITICAL_KW)),
|
| 44 |
+
'has_simple': int(any(k in r for k in SIMPLE_KW)),
|
| 45 |
+
'has_long': int(any(k in r for k in LONG_KW)),
|
| 46 |
+
'has_math': int(any(k in r for k in MATH_KW)),
|
| 47 |
+
'has_error_msg': int('error' in r or 'traceback' in r or 'exception' in r),
|
| 48 |
+
'has_file_path': int('/' in r),
|
| 49 |
+
'n_lines': problem_text.count('\n') + 1,
|
| 50 |
+
'has_version': int('version' in r or 'update' in r or 'upgrade' in r),
|
| 51 |
+
'has_add': int('add' in r or 'new' in r or 'create' in r),
|
| 52 |
+
'has_fix': int('fix' in r or 'bug' in r or 'issue' in r or 'broken' in r),
|
| 53 |
+
'has_change': int('change' in r or 'modify' in r or 'update' in r),
|
| 54 |
+
'has_remove': int('remove' in r or 'delete' in r or 'drop' in r),
|
| 55 |
+
'has_test': int('test' in r or 'spec' in r or 'assert' in r),
|
| 56 |
+
'has_doc': int('doc' in r or 'readme' in r or 'comment' in r),
|
| 57 |
+
}
|
| 58 |
+
return feats
|
| 59 |
+
|
| 60 |
+
print("BERT Router Evaluation on SWE-Router")
|
| 61 |
+
print("="*60)
|