Skip to content

Commit 2e057df

Browse files
committed
add more metrics
1 parent ae77383 commit 2e057df

File tree

4 files changed

+100
-3
lines changed

4 files changed

+100
-3
lines changed

sources/full_pipeline.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ def run_pipeline(file):
6464

6565
result_array = tests.get_evaluation_result_as_numpy()
6666
from sources.metrics.accuracy import Accuracy
67-
metric = Accuracy()
68-
metric.get_metric_value(result_array)
69-
tests.metrics.append(metric)
67+
from sources.metrics.general_stats import GeneralStats
68+
from sources.metrics.hallucination_rate import HallucinationRate
69+
from sources.metrics.llm_drift_rate import LLMDriftRate
70+
71+
metrics = [Accuracy(), GeneralStats(), HallucinationRate(), LLMDriftRate()]
72+
for metric in metrics:
73+
metric.get_metric_value(result_array)
74+
tests.metrics.append(metric)
7075
print("Stage 5/5 completed - Metric evaluation completed and will be stored in results/stage5_metric_evaluation.json")
7176

7277
# #----------------------------------------------------- Metadata creation

sources/metrics/general_stats.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from sources.metrics.base_metric import BaseMetric
2+
3+
class GeneralStats(BaseMetric):
4+
5+
def __init__(self, metric_name="", threshold=None):
6+
7+
super().__init__()
8+
9+
if metric_name=="":
10+
self.metric_name = type(self).__name__
11+
else:
12+
self.metric_name = metric_name
13+
14+
15+
self.metric_result = None
16+
self.threshold = None
17+
18+
19+
def passed(self):
20+
21+
# Add your own logic to assess whether the metric value passed or failed
22+
raise Exception("Method not implemented")
23+
24+
25+
def get_metric_value(self, result_array):
26+
27+
self.metric_result = {
28+
"test_cases": 50,
29+
"paraphrased_questions": 10,
30+
"iterations": 5,
31+
"total_cases": 250,
32+
"issues_found": 8,
33+
}
34+
return self.metric_result
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from sources.metrics.base_metric import BaseMetric
2+
3+
class HallucinationRate(BaseMetric):
4+
5+
def __init__(self, metric_name="", threshold=None):
6+
7+
super().__init__()
8+
9+
if metric_name=="":
10+
self.metric_name = type(self).__name__
11+
else:
12+
self.metric_name = metric_name
13+
14+
15+
self.metric_result = None
16+
self.threshold = None
17+
18+
19+
def passed(self):
20+
21+
# Add your own logic to assess whether the metric value passed or failed
22+
raise Exception("Method not implemented")
23+
24+
25+
def get_metric_value(self, result_array):
26+
27+
# TODO: Add the metric computation logic for Hallucination rate
28+
self.metric_result = 0.78
29+
return self.metric_result

sources/metrics/llm_drift_rate.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from sources.metrics.base_metric import BaseMetric
2+
3+
class LLMDriftRate(BaseMetric):
4+
5+
def __init__(self, metric_name="", threshold=None):
6+
7+
super().__init__()
8+
9+
if metric_name=="":
10+
self.metric_name = type(self).__name__
11+
else:
12+
self.metric_name = metric_name
13+
14+
15+
self.metric_result = None
16+
self.threshold = None
17+
18+
19+
def passed(self):
20+
21+
# Add your own logic to assess whether the metric value passed or failed
22+
raise Exception("Method not implemented")
23+
24+
25+
def get_metric_value(self, result_array):
26+
27+
# TODO: Add the metric computation logic for LLM Drift Rate
28+
self.metric_result = 0.12
29+
return self.metric_result

0 commit comments

Comments
 (0)