-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluation_tester.py
43 lines (34 loc) · 1.08 KB
/
evaluation_tester.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import json
import os
import fire
from eval.correlation import CorrelationCalculator
from eval.evaluator import Evaluator
def run(
dataset_path: str,
prompt_path: str,
output_path: str,
model: str,
dimension: str,
temperature: float = 0.0,
n: int = 1,
api_key: str = None,
):
# Evaluation
print("Evaluating... ")
test_evaluator = Evaluator(model=model, api_key=api_key)
eval_results = test_evaluator.eval_output(
dataset_path, prompt_path, temperature=temperature, n=n
)
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with open(output_path, "w") as f:
json.dump(eval_results, f)
# Correlation calculation
print(f"Calculating Correlation...")
corr_calculator = CorrelationCalculator(dimension=dimension)
corr_results = corr_calculator.correlation_output(output_path)
# save the correlation results into file
save_corr_path = output_path.replace(".json", "_corr.json")
with open(save_corr_path, "w") as f:
json.dump(corr_results, f)
if __name__ == "__main__":
fire.Fire(run)