Datasets:
File size: 1,778 Bytes
5c45e6a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import json,re,collections,statistics as st
d=json.load(open("raw_results.json"))
TA_DIG=str.maketrans("௦௧௨௩௪௫௬௭௮௯","0123456789")
def norm(x): return re.sub(r"[\s\.\,\!\?\:\"'`*()\[\]₹]|rs|rupees|ரூபாய்","",(x or "").lower().translate(TA_DIG))
def correct(r):
o=norm(r["output"]); golds=[norm(r["answer"])]+[norm(a) for a in r["aliases"]]
if r["answer"].isdigit():
nums=re.findall(r"\d+(?:\.\d+)?", (r["output"] or "").translate(TA_DIG).replace(",",""))
return bool(nums) and float(nums[-1])==float(r["answer"])
return any(g and (o==g or o.startswith(g) or g in o) for g in golds)
PIN,POUT=0.40,1.20
for r in d: r["correct"]=correct(r); r["cost_usd"]=(r["prompt_tokens"]*PIN+r["completion_tokens"]*POUT)/1e6
json.dump(d,open("scored_results.json","w"),ensure_ascii=False,indent=1)
def summ(rows):
return dict(n=len(rows),acc=round(100*sum(r["correct"] for r in rows)/len(rows),1),
prompt=round(st.mean(r["prompt_tokens"] for r in rows),1),
reasoning=round(st.mean(r["reasoning_tokens"] or 0 for r in rows),1),
completion=round(st.mean(r["completion_tokens"] for r in rows),1),
cost_per_1k=round(1000*st.mean(r["cost_usd"] for r in rows),4),
latency=round(st.mean(r["latency"] for r in rows),2))
S={}
for l in("en","ta","tl"):
S[l]=summ([r for r in d if r["lang"]==l])
for c in("math","logic","knowledge","everyday"):
S[f"{l}/{c}"]=summ([r for r in d if r["lang"]==l and r["cat"]==c])
print(json.dumps(S,indent=0))
wrong=[(r["id"],r["lang"],r["answer"],(r["output"] or "")[:40]) for r in d if not r["correct"]]
print(len(wrong)); [print(w) for w in sorted(wrong)]
print("total cost $",round(sum(r["cost_usd"] for r in d),4))
json.dump(S,open("summary.json","w"),indent=1)
|