Upload eval/run_bert_eval_full.py
Browse files- eval/run_bert_eval_full.py +66 -0
eval/run_bert_eval_full.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
MODELS = ['claude-opus-4.7','gpt-5-mini','gpt-5-nano','gpt-5.2',
|
| 7 |
+
'gemini-2.5-pro','gemini-3-pro','deepseek-v3.2','deepseek-v4-flash']
|
| 8 |
+
MODEL_TIER = {'deepseek-v4-flash':1,'gpt-5-nano':1,'gpt-5-mini':2,'deepseek-v3.2':2,
|
| 9 |
+
'gemini-2.5-pro':3,'claude-opus-4.7':4,'gpt-5.2':4,'gemini-3-pro':5}
|
| 10 |
+
TIER_COST = {1:0.01,2:0.05,3:0.15,4:0.30,5:0.50}
|
| 11 |
+
TIER_TO_SWE = {1:'deepseek-v4-flash',2:'gpt-5-mini',3:'gemini-2.5-pro',4:'claude-opus-4.7',5:'gemini-3-pro'}
|
| 12 |
+
TASK_FLOOR = {"quick_answer":1,"coding":3,"research":3,"document_drafting":2,
|
| 13 |
+
"legal_regulated":4,"tool_heavy":2,"retrieval_heavy":2,"long_horizon":3,"unknown_ambiguous":3}
|
| 14 |
+
CODE_KW = ["python","javascript","code","function","bug","debug","refactor","implement","test",
|
| 15 |
+
"compile","runtime","segfault","thread","async","class","module","import","error","traceback"]
|
| 16 |
+
LEGAL_KW = ["contract","legal","compliance","gdpr","privacy","policy","regulatory","liability"]
|
| 17 |
+
RESEARCH_KW = ["research","investigate","compare","analyze","survey","paper"]
|
| 18 |
+
TOOL_KW = ["search","fetch","retrieve","query","api","database","scrape","aggregate"]
|
| 19 |
+
CRITICAL_KW = ["critical","production","urgent","emergency","live","deployed","safety","security"]
|
| 20 |
+
SIMPLE_KW = ["typo","simple","quick","brief","minor","small","easy","trivial","just"]
|
| 21 |
+
LONG_KW = ["plan","project","roadmap","orchestrate","migrate","pipeline","deploy","architecture"]
|
| 22 |
+
MATH_KW = ["calculate","compute","solve","equation","formula","optimize","probability"]
|
| 23 |
+
|
| 24 |
+
def extract_features(pt):
|
| 25 |
+
r = pt.lower()
|
| 26 |
+
return {'req_len':len(pt),'num_words':len(pt.split()),
|
| 27 |
+
'has_code':int(any(k in r for k in CODE_KW)),'n_code':sum(1 for k in CODE_KW if k in r),
|
| 28 |
+
'has_legal':int(any(k in r for k in LEGAL_KW)),'has_research':int(any(k in r for k in RESEARCH_KW)),
|
| 29 |
+
'has_tool':int(any(k in r for k in TOOL_KW)),'has_critical':int(any(k in r for k in CRITICAL_KW)),
|
| 30 |
+
'has_simple':int(any(k in r for k in SIMPLE_KW)),'has_long':int(any(k in r for k in LONG_KW)),
|
| 31 |
+
'has_math':int(any(k in r for k in MATH_KW)),'has_error_msg':int('error' in r or 'traceback' in r),
|
| 32 |
+
'has_file_path':int('/' in r),'n_lines':pt.count('\n')+1,
|
| 33 |
+
'has_version':int('version' in r or 'update' in r),'has_add':int('add' in r or 'new' in r),
|
| 34 |
+
'has_fix':int('fix' in r or 'bug' in r),'has_change':int('change' in r or 'modify' in r),
|
| 35 |
+
'has_remove':int('remove' in r),'has_test':int('test' in r or 'spec' in r),
|
| 36 |
+
'has_doc':int('doc' in r or 'readme' in r)}
|
| 37 |
+
|
| 38 |
+
def classify_task(text):
|
| 39 |
+
r = text.lower()
|
| 40 |
+
if any(k in r for k in ["contract","legal","compliance","gdpr","privacy"]): return "legal_regulated"
|
| 41 |
+
if any(k in r for k in ["debug","fix","bug","implement","refactor","code","function"]): return "coding"
|
| 42 |
+
if any(k in r for k in ["research","find sources","literature","investigate"]): return "research"
|
| 43 |
+
if any(k in r for k in ["search","fetch","api","query","database"]): return "tool_heavy"
|
| 44 |
+
if any(k in r for k in ["plan","roadmap","orchestrate","migrate","deploy"]): return "long_horizon"
|
| 45 |
+
if any(k in r for k in ["draft","write","compose","document"]): return "document_drafting"
|
| 46 |
+
if any(k in r for k in ["what is","explain","define","briefly"]): return "quick_answer"
|
| 47 |
+
return "unknown_ambiguous"
|
| 48 |
+
|
| 49 |
+
print("BERT Router Evaluation on SWE-Router")
|
| 50 |
+
print("="*60)
|
| 51 |
+
|
| 52 |
+
# ── Load SWE-Router data ──
|
| 53 |
+
print("\n[1] Loading SWE-Router data...")
|
| 54 |
+
from datasets import load_dataset
|
| 55 |
+
traces = defaultdict(dict)
|
| 56 |
+
for model in MODELS:
|
| 57 |
+
try:
|
| 58 |
+
ds = load_dataset(f'SWE-Router/swebench-verified-{model}', split='test')
|
| 59 |
+
for row in ds:
|
| 60 |
+
iid = row['instance_id']
|
| 61 |
+
traces[iid][model] = {'resolved': row['resolved'], 'cost': float(row['instance_cost']),
|
| 62 |
+
'problem': row['problem_statement']}
|
| 63 |
+
print(f" {model}: loaded")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
print(f" {model}: FAILED - {e}")
|
| 66 |
+
print(f" Total tasks: {len(traces)}")
|