File size: 3,788 Bytes
b81a0d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json,re,collections,statistics as st
from hard import H
from writing import W
IN,OUTP=0.40/1e6,1.20/1e6
D={chr(0x0BE6+i):str(i) for i in range(10)}
R=[json.loads(l) for l in open('all_raw.jsonl')]
# dedupe
seen={};
for r in R: seen[(r["split"],r["id"],str(r["cond"]))]=r
R=list(seen.values())
def norm(s): s=(s or "").strip(); s="".join(D.get(c,c) for c in s); return re.sub(r"[\s'\"`.,:;!*()\[\]“”‘’]","",s)
G={h["id"]:h for h in H}
out={}
# belebele
bb=collections.defaultdict(list)
for r in R:
    if r["split"]!="belebele": continue
    o=norm(r["output"]); m=re.findall(r"[1-4]",o)
    r["pred"]=m[0] if len(set(m))==1 or (m and len(o)<=3) else (m[-1] if m else None)
    r["correct"]=r["pred"]==r["gold"]; bb[r["cond"]].append(r)
B={}
for cd,L in bb.items():
    n=len(L); B[cd]=dict(n=n,acc=round(100*sum(r["correct"] for r in L)/n,1),prompt=round(st.mean(r["prompt_tokens"] for r in L),1),
      reasoning=round(st.mean(r["reasoning_tokens"] or 0 for r in L),1),completion=round(st.mean(r["completion_tokens"] for r in L),1),
      latency=round(st.median(r["latency"] for r in L),2),cost_per_1k=round(1000*st.mean(r["prompt_tokens"]*IN+r["completion_tokens"]*OUTP for r in L),3))
# paired: questions present in all conds
ids={cd:{r["id"]:r["correct"] for r in L} for cd,L in bb.items()}
common=set.intersection(*map(set,ids.values())) if ids else set()
B["_paired_n"]=len(common)
for cd in ids: B[cd]["acc_paired"]=round(100*sum(ids[cd][i] for i in common)/max(1,len(common)),1)
out["belebele"]=B
# hard
hc=collections.defaultdict(list); hard=[]
for r in R:
    if r["split"]!="hard": continue
    h=G[r["id"]]; o=norm(r["output"]); golds=[norm(h["answer"])]+[norm(a) for a in h.get("aliases",[])]
    ok= o in golds or (h["answer"].isdigit() and re.findall(r"\d+",o)[-1:]==[h["answer"]])
    hc[h["cat"]].append(ok); hard.append(dict(id=r["id"],cat=h["cat"],sample=r["cond"],gold=h["answer"],output=r["output"],correct=ok,reasoning_tokens=r["reasoning_tokens"]))
out["hard"]={k:dict(correct=sum(v),n=len(v),acc=round(100*sum(v)/len(v),1)) for k,v in hc.items()}
out["hard_total"]=dict(correct=sum(sum(v) for v in hc.values()),n=sum(len(v) for v in hc.values()))
# writing
J=json.load(open("judge.json"))
wr=[]
for r in R:
    if r["split"]!="write": continue
    o=r["output"] or ""; L=[c for c in o if c.isalpha()]; tam=sum('\u0b80'<=c<='\u0bff' for c in L)
    w=[x for x in W if x["id"]==r["id"]][0]
    js=[d for d in J if d["id"]==r["id"] and "fluency" in d]
    wr.append(dict(id=r["id"],style=w["style"],prompt=w["prompt"],output=o,tamil_script_pct=round(100*tam/max(1,len(L))),completion_tokens=r["completion_tokens"],reasoning_tokens=r["reasoning_tokens"],
        judge_correctness=round(st.mean(d["correctness"] for d in js),1),judge_fluency=round(st.mean(d["fluency"] for d in js),1),judge_instruction=round(st.mean(d["instruction"] for d in js),1)))
out["writing"]=dict(n=len(wr),correctness=round(st.mean(x["judge_correctness"] for x in wr),2),fluency=round(st.mean(x["judge_fluency"] for x in wr),2),instruction=round(st.mean(x["judge_instruction"] for x in wr),2),
   tanglish_register_kept=sum(1 for x in wr if x["style"]=="tl" and x["tamil_script_pct"]<20),tanglish_n=sum(1 for x in wr if x["style"]=="tl"),
   tamil_output_vs_tanglish_tokens=2.36)
out["tokenizer_league"]=json.load(open("tokenizer_league.json"))
json.dump(out,open("summary_v2.json","w"),ensure_ascii=False,indent=1)
json.dump(dict(belebele=[{k:r[k] for k in("id","cond","gold","pred","correct","output","prompt_tokens","completion_tokens","reasoning_tokens","latency")} for r in R if r["split"]=="belebele"],hard=hard,writing=wr),open("runs_v2.json","w"),ensure_ascii=False)
print(json.dumps({k:v for k,v in out.items() if k!="tokenizer_league"},ensure_ascii=False,indent=1))