perrylink commited on
Commit
159e2d9
·
verified ·
1 Parent(s): 88c9f71

v1.1: upgraded weights (b6472511…), re-measured metrics, refreshed docs/figures/gifs, bundled calib/, leaderboard results

Browse files
Files changed (1) hide show
  1. calib/calibrate.py +23 -0
calib/calibrate.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """apply_gamma — per-decision power calibration for Phocinae-Largha-150M-v1.
2
+
3
+ q ∝ p ** gamma (per decision, normalized). Monotone; argmax and the 0.5
4
+ threshold of noul answers are unchanged, so accuracy is invariant.
5
+ Recommended: gamma=4.33 (en face), gamma=2.51 (zh face). gamma=1 = raw.
6
+ """
7
+ from __future__ import annotations
8
+
9
+
10
+ def apply_gamma(probs: dict, gamma: float = 1.0) -> dict:
11
+ """probs: {option_id: probability}. Returns calibrated dict (same keys)."""
12
+ if gamma == 1.0:
13
+ return dict(probs)
14
+ powered = {k: (max(float(v), 0.0) ** gamma) for k, v in probs.items()}
15
+ s = sum(powered.values())
16
+ if s <= 0:
17
+ raise ValueError("apply_gamma: all probabilities are zero")
18
+ return {k: v / s for k, v in powered.items()}
19
+
20
+
21
+ def calibrate_response(probabilities: dict, gamma: float = 4.33) -> dict:
22
+ """Calibrate a full response: {qid: {option: prob}} -> {qid: {option: prob}}."""
23
+ return {qid: apply_gamma(p, gamma) for qid, p in probabilities.items()}