Update metrics.py
Browse files- metrics.py +1 -38
metrics.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
# metrics.py
|
2 |
from model_loader import metrics_models
|
3 |
-
from classifier import classify_toxic_comment
|
4 |
import re
|
5 |
|
6 |
def compute_semantic_similarity(original, paraphrased):
|
@@ -66,40 +65,4 @@ def compute_hallucination_score(original, paraphrased):
|
|
66 |
return round(score, 2)
|
67 |
except Exception as e:
|
68 |
print(f"Error computing hallucination score: {str(e)}")
|
69 |
-
return None
|
70 |
-
|
71 |
-
def compute_reward_scores(original, paraphrased):
|
72 |
-
"""
|
73 |
-
Compute all reward scores for a paraphrase.
|
74 |
-
Returns a dictionary with empathy, toxicity, bias, hallucination, and overall reward.
|
75 |
-
"""
|
76 |
-
try:
|
77 |
-
# Get toxicity from classifier
|
78 |
-
_, _, _, toxicity_score, bias_score, _, _, _, _, paraphrased_toxicity_score, paraphrased_bias_score, _, _ = classify_toxic_comment(paraphrased)
|
79 |
-
toxicity = paraphrased_toxicity_score if paraphrased_toxicity_score is not None else 0.5
|
80 |
-
|
81 |
-
# Compute other metrics
|
82 |
-
empathy = compute_empathy_score(paraphrased) or 0.5
|
83 |
-
bias = compute_bias_score(paraphrased) or 0.5
|
84 |
-
hallucination = compute_hallucination_score(original, paraphrased) or 0.5
|
85 |
-
|
86 |
-
# Overall reward: Weighted combination (adjust weights as needed)
|
87 |
-
reward = (0.4 * empathy) - (0.2 * toxicity) - (0.2 * bias) - (0.2 * hallucination)
|
88 |
-
reward = max(0.0, min(1.0, round(reward, 2)))
|
89 |
-
|
90 |
-
return {
|
91 |
-
"empathy": empathy,
|
92 |
-
"toxicity": toxicity,
|
93 |
-
"bias": bias,
|
94 |
-
"hallucination": hallucination,
|
95 |
-
"reward": reward
|
96 |
-
}
|
97 |
-
except Exception as e:
|
98 |
-
print(f"Error computing reward scores: {str(e)}")
|
99 |
-
return {
|
100 |
-
"empathy": 0.5,
|
101 |
-
"toxicity": 0.5,
|
102 |
-
"bias": 0.5,
|
103 |
-
"hallucination": 0.5,
|
104 |
-
"reward": 0.5
|
105 |
-
}
|
|
|
1 |
# metrics.py
|
2 |
from model_loader import metrics_models
|
|
|
3 |
import re
|
4 |
|
5 |
def compute_semantic_similarity(original, paraphrased):
|
|
|
65 |
return round(score, 2)
|
66 |
except Exception as e:
|
67 |
print(f"Error computing hallucination score: {str(e)}")
|
68 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|