-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
112 lines (92 loc) · 3.41 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import os, argparse
import pandas as pd
from insightbench.utils import agent_utils as au
from insightbench import agents, benchmarks
from insightbench.utils import exp_utils as eu
from insightbench.utils.exp_utils import hash_dict, save_json
def main(exp_dict, savedir, args):
# Hyperparameters:
# ----------------
# Print Exp dict as hyperparamters and savedir
print("\nExperiment Dict:")
eu.print(exp_dict)
print(f"\nSavedir: {savedir}\n")
# Reset savedir if reset flag is set
if args.reset and os.path.exists(savedir) and not args.eval_only:
# assert savedir has exp_dict.json for safety
assert os.path.exists(os.path.join(savedir, "exp_dict.json"))
os.system(f"rm -rf {savedir}")
save_json(os.path.join(savedir, "exp_dict.json"), exp_dict)
# Get Benchmark:
# ----------------
dataset_list = benchmarks.get_benchmark(
exp_dict["benchmark_type"], datadir=args.datadir
)
# load agent
agent = agents.Agent(
model_name=exp_dict["model_name"],
max_questions=exp_dict["max_questions"],
branch_depth=exp_dict["branch_depth"],
n_retries=2,
savedir=savedir,
)
# load dataset
score_list = []
for dataset_json_path in dataset_list:
# Load Dataset
dataset_dict = benchmarks.load_dataset_dict(dataset_json_path=dataset_json_path)
# Predict Insights
pred_insights, pred_summary = agent.get_insights(
dataset_csv_path=dataset_dict["dataset_csv_path"],
user_dataset_csv_path=dataset_dict["user_dataset_csv_path"],
)
# Evaluate Agent
# --------------
# Evaluate
score_insights = benchmarks.evaluate_insights(
pred_insights=pred_insights,
gt_insights=dataset_dict["insights"],
score_name="rouge1",
)
score_summary = benchmarks.evaluate_summary(
pred=pred_summary, gt=dataset_dict["summary"], score_name="rouge1"
)
score_list.append(
{
"score_insights": score_insights,
"score_summary": score_summary,
}
)
# Print Scores
print(pd.DataFrame(score_list).tail())
# save score_list
save_json(os.path.join(savedir, "score_list.json"), score_list)
print("Experiment Done!")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-sb", "--savedir_base", type=str, default="results")
parser.add_argument("-r", "--reset", type=int, default=0)
# add openai api key
parser.add_argument("-o", "--openai_api_key", type=str, default=None)
# dataset path
parser.add_argument("-d", "--datadir", type=str, default="data/notebooks")
args, unknown = parser.parse_known_args()
# exp_list
exp_list = []
for benchmark_type in ["toy"]:
for model_name in ["gpt-4o-mini"]:
exp_list.append(
{
"benchmark_type": benchmark_type,
"model_name": model_name,
"max_questions": 2,
"branch_depth": 1,
}
)
# set open ai env
os.environ["OPENAI_API_KEY"] = args.openai_api_key
# Loop through experiments
for exp_dict in exp_list:
hash_id = hash_dict(exp_dict)
savedir = os.path.join(args.savedir_base, hash_id)
main(exp_dict, savedir, args)