Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
csv
Languages:
English
Size:
< 1K
Tags:
clarus
clinical-trials
narrative-integrity
section-transition
evidence-reporting
clinical-audit
License:
Create scorer.py
Browse files
scorer.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# scorer.py
|
| 2 |
+
import csv, json, re, sys
|
| 3 |
+
|
| 4 |
+
ALLOWED = {"A","B"}
|
| 5 |
+
|
| 6 |
+
def norm(t):
|
| 7 |
+
return re.sub(r"\s+"," ",(t or "").lower().strip())
|
| 8 |
+
|
| 9 |
+
def kws(s):
|
| 10 |
+
return [k.strip().lower() for k in (s or "").split("|") if k.strip()]
|
| 11 |
+
|
| 12 |
+
def load_gold(p):
|
| 13 |
+
g={}
|
| 14 |
+
with open(p, newline="", encoding="utf-8") as f:
|
| 15 |
+
r=csv.DictReader(f)
|
| 16 |
+
for d in r:
|
| 17 |
+
g[d["sample_id"]] = {
|
| 18 |
+
"opt": d["correct_option"].strip().upper(),
|
| 19 |
+
"kws": kws(d.get("required_keywords","")),
|
| 20 |
+
"axis": d.get("axis","unknown") or "unknown"
|
| 21 |
+
}
|
| 22 |
+
return g
|
| 23 |
+
|
| 24 |
+
def load_pred(p):
|
| 25 |
+
o={}
|
| 26 |
+
with open(p, newline="", encoding="utf-8") as f:
|
| 27 |
+
r=csv.DictReader(f)
|
| 28 |
+
for d in r:
|
| 29 |
+
o[d["sample_id"]] = {
|
| 30 |
+
"opt": d.get("predicted_option","").strip().upper(),
|
| 31 |
+
"note": d.get("predicted_note","")
|
| 32 |
+
}
|
| 33 |
+
return o
|
| 34 |
+
|
| 35 |
+
def cov(note, ks):
|
| 36 |
+
if not ks: return 1.0
|
| 37 |
+
n=norm(note)
|
| 38 |
+
return sum(1 for k in ks if k in n)/len(ks)
|
| 39 |
+
|
| 40 |
+
def main():
|
| 41 |
+
g=load_gold(sys.argv[1])
|
| 42 |
+
p=load_pred(sys.argv[2])
|
| 43 |
+
|
| 44 |
+
tot=len(g)
|
| 45 |
+
ok=0; miss=0; bad=0
|
| 46 |
+
covs=[]
|
| 47 |
+
|
| 48 |
+
for sid,gd in g.items():
|
| 49 |
+
pr=p.get(sid)
|
| 50 |
+
if not pr:
|
| 51 |
+
miss+=1; covs.append(0); continue
|
| 52 |
+
if pr["opt"] not in ALLOWED:
|
| 53 |
+
bad+=1
|
| 54 |
+
elif pr["opt"]==gd["opt"]:
|
| 55 |
+
ok+=1
|
| 56 |
+
covs.append(cov(pr["note"], gd["kws"]))
|
| 57 |
+
|
| 58 |
+
out={
|
| 59 |
+
"option_accuracy": ok/max(1,tot),
|
| 60 |
+
"note_mean_keyword_coverage": sum(covs)/max(1,tot),
|
| 61 |
+
"joint_success_rate": (ok/max(1,tot))*(sum(1 for c in covs if c>=0.6)/max(1,tot)),
|
| 62 |
+
"total": tot,
|
| 63 |
+
"missing": miss,
|
| 64 |
+
"invalid": bad
|
| 65 |
+
}
|
| 66 |
+
print(json.dumps(out, indent=2))
|
| 67 |
+
|
| 68 |
+
if __name__=="__main__":
|
| 69 |
+
main()
|