VALID = {"coherent","incoherent"} def score(predictions, references): ref = {r["uid"]: r for r in references} total = 0 correct = 0 invalid = 0 for p in predictions: uid = p["uid"] if uid not in ref: continue gt = ref[uid]["ground_truth_label"] if not gt: continue total += 1 pred = str(p.get("model_response","")).strip().lower() if pred not in VALID: invalid += 1 continue if pred == gt: correct += 1 return { "accuracy": correct/total if total else 0, "n_scored": total, "invalid_rate": invalid/total if total else 0 }