Skip to content

Commit f736c37

Browse files
committed
add metric to pipeline
1 parent e5e220f commit f736c37

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

config/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ apis:
4646

4747
local_api:
4848
name: LocalAPI
49-
endpoint: http://127.0.0.1:8025/answer
49+
endpoint: http://127.0.0.1:8000/answer
5050
auth_required: false # Authentication not required
5151
headers:
5252
accept: application/json

sources/full_pipeline.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def run_pipeline(file):
3333

3434
#-----------------------------------------------------
3535

36-
# tests.execute(LLMExecutor())
36+
tests.execute(LLMExecutor())
3737
print("Stage 3/5 completed - LLM queries executed and will be stored in results/stage3_execution_result.json")
3838

3939
execution_result_json = tests.to_dict()
@@ -43,20 +43,34 @@ def run_pipeline(file):
4343

4444
#-----------------------------------------------------
4545

46-
# tests.evaluate_responses()
46+
tests.evaluate_responses()
4747
print("Stage 4/5 completed - Paraphrases generated and will be stored in results/stage4_response_evaluation.json")
4848

4949
response_evaluation_result_json = tests.to_dict()
5050

5151
with open("results/stage4_response_evaluation.json", 'w') as json_file:
5252
json.dump(response_evaluation_result_json, json_file, indent=4)
5353

54+
55+
56+
# file_path = "results/stage5_metric_evaluation.json"
57+
# with open(file_path, "r") as json_file:
58+
# test_data = json.load(json_file)
59+
# from sources.models.unit_tests import UnitTests
60+
# tests = UnitTests.from_json(test_data)
61+
# print(tests[0].question)
62+
5463
#----------------------------------------------------- Stage 5
5564

56-
# tests.evaluate_responses()
65+
result_array = tests.get_evaluation_result_as_numpy()
66+
print(result_array)
67+
from sources.metrics.accuracy import Accuracy
68+
metric = Accuracy()
69+
metric.get_metric_value(result_array)
70+
tests.metrics.append(metric)
5771
print("Stage 5/5 completed - Metric evaluation completed and will be stored in results/stage5_metric_evaluation.json")
5872

59-
#----------------------------------------------------- Metadata creation
73+
# #----------------------------------------------------- Metadata creation
6074

6175
end_time = time.time()
6276
execution_time = end_time - start_time
@@ -93,7 +107,7 @@ def run_pipeline(file):
93107
return tests
94108

95109
# Below is the the code to load the object from JSON. Adapt it according to the stage you want to load the object from.
96-
# file_path = "results/tests.json"
110+
# file_path = "results/stage5_metric_evaluation.json"
97111
# with open(file_path, "r") as json_file:
98112
# test_data = json.load(json_file)
99113
# from sources.models.unit_tests import UnitTests

sources/metrics/accuracy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def passed(self):
2222
raise Exception("Method not implemented")
2323

2424

25-
def to_json(self):
25+
def get_metric_value(self, result_array):
2626

27-
pass
27+
self.metric_result = result_array.mean()
28+
return self.metric_result

sources/metrics/base_metric.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
class BaseMetric:
1+
from sources.models.common_interface import BaseTest
2+
3+
class BaseMetric(BaseTest):
24

35
def __init__(self, metric_name="", threshold=None):
46

@@ -20,9 +22,9 @@ def passed(self):
2022
raise Exception("Method not implemented")
2123

2224

23-
def to_json(self):
25+
# def to_json(self):
2426

25-
pass
27+
# pass
2628

2729
"""
2830
Dimensions guide to accessing numpy results array:

sources/models/unit_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sources.helpers.paraphrase_helper import paraphrase_question
77
from sources.models.unit_tests_result import ParaphrasedQuestion
88
from sources.models.metadata import MetaData
9+
from sources.metrics.base_metric import BaseMetric
910
import numpy as np
1011

1112
import os
@@ -111,6 +112,7 @@ def __init__(self, file=None):
111112
self.file = file
112113
self.unit_tests: List[UnitTest] = []
113114
self.metadata: MetaData = None
115+
self.metrics: List[BaseMetric] = []
114116

115117
def read_file(self):
116118
df = pd.read_csv(self.file)

sources/models/unit_tests_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def evaluate_responses(self, tests):
2424
for test in tests:
2525
# evaluate whether the answer follows the given test
2626
passed, reason = evaluate_answer_for_test(self.answer, test.test_case)
27-
self.test_cases.append(AtomicTestCaseExecutionResult(test, passed, reason))
27+
self.test_cases.append(AtomicTestCaseExecutionResult(test.test_case, passed, reason))
2828

2929
def get_evaluation_result_as_numpy(self):
3030
results = []

0 commit comments

Comments
 (0)