Zekun Wu
commited on
Commit
·
90c9f9c
1
Parent(s):
8a0a737
add
Browse files- util/evaluator.py +16 -2
util/evaluator.py
CHANGED
@@ -9,9 +9,23 @@ class evaluator:
|
|
9 |
|
10 |
def validate_scores(self, scores):
|
11 |
required_keys = ["Factually Correct", "Useful", "Context Specific", "User Specific", "Provides Pluralism"]
|
|
|
12 |
for key in required_keys:
|
13 |
-
if key not in scores
|
14 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
return scores
|
17 |
|
|
|
9 |
|
10 |
def validate_scores(self, scores):
|
11 |
required_keys = ["Factually Correct", "Useful", "Context Specific", "User Specific", "Provides Pluralism"]
|
12 |
+
|
13 |
for key in required_keys:
|
14 |
+
if key not in scores:
|
15 |
+
return {k: {"Score": -1, "Justification": "Invalid input"} for k in required_keys}
|
16 |
+
|
17 |
+
score_data = scores[key]
|
18 |
+
|
19 |
+
if not isinstance(score_data, dict):
|
20 |
+
return {k: {"Score": -1, "Justification": "Invalid input format"} for k in required_keys}
|
21 |
+
|
22 |
+
if "Score" not in score_data or not isinstance(score_data["Score"], (int, float)) or not (
|
23 |
+
0 <= score_data["Score"] <= 1):
|
24 |
+
return {k: {"Score": -1, "Justification": "Invalid score value"} for k in required_keys}
|
25 |
+
|
26 |
+
if "Justification" not in score_data or not isinstance(score_data["Justification"], str) or not score_data[
|
27 |
+
"Justification"].strip():
|
28 |
+
return {k: {"Score": -1, "Justification": "Invalid or missing justification"} for k in required_keys}
|
29 |
|
30 |
return scores
|
31 |
|