navaneethkrishnan commited on
Commit
3440c99
·
verified ·
1 Parent(s): b4d93ed

Create fusion.py

Browse files
Files changed (1) hide show
  1. core/fusion.py +22 -0
core/fusion.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict
2
+
3
+ # judge_score is 1..5 (int). nlp_subscore is 0..1. alpha in [0,1]
4
+
5
+ def fuse_metric(judge_score, nlp_subscore: float, alpha: float) -> float:
6
+ js = 0.0
7
+ if judge_score is not None:
8
+ try:
9
+ js = max(0.0, min(1.0, float(judge_score) / 5.0))
10
+ except Exception:
11
+ js = 0.0
12
+ ns = max(0.0, min(1.0, float(nlp_subscore)))
13
+ fused_0_1 = alpha * js + (1 - alpha) * ns
14
+ return round(fused_0_1 * 10.0, 2)
15
+
16
+
17
+ def weighted_total(metric_scores_0_10: Dict[str, float], weights: Dict[str, float]) -> float:
18
+ tot = 0.0
19
+ for k, v in metric_scores_0_10.items():
20
+ w = weights.get(k, 0.0)
21
+ tot += (v or 0.0) * w
22
+ return round(tot, 2)