-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_experiments-explainer-base.py
More file actions
131 lines (101 loc) · 4.31 KB
/
Copy pathrun_experiments-explainer-base.py
File metadata and controls
131 lines (101 loc) · 4.31 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os
import shutil
import json
import datetime
from time import sleep
SUBMISSIONS_DIR = "Data/Submissions/explainer-base"
GENERATIONS_DIR = "Data/Generations/explainer-base"
COMPETITIONS_DIR = "Data/Competitions"
WORKSPACE_DIR = "MetaGPT-DataExplainer/workspace"
CURRENT_MODEL = "<model name>"
OLLAMA_MODEL_NAME = "<ollama model name; empty if not using ollama>"
SEED_LIST = ["baseline-0", "baseline-1", "baseline-2", "baseline-3"]
LANGUAGES = ["en"]
# load competitions checkpoint
try:
with open("solved_competitions.json") as in_json:
solved_competitions = json.load(in_json)
except FileNotFoundError:
solved_competitions = []
# skip checkpinted competitions
def check_solved(language, competition, seed):
return [language, competition, seed] in solved_competitions
def add_solved(language, competition, seed):
solved_competitions.append((language, competition, seed))
with open("solved_competitions.json", "w") as out_json:
json.dump(solved_competitions, out_json)
# script to run framework in order to solve the competition
def solve_comp(language, competition, competition_info, baseline_prompt, seed, submissions_dir, gen_dir):
if check_solved(language, competition, seed):
return None
# clear workspace
for file_in_dir in os.listdir(WORKSPACE_DIR):
if file_in_dir not in ["train.csv", "test.csv"]:
os.system(f"rm -r {WORKSPACE_DIR}/{file_in_dir}")
# clean model
os.system(f"ollama stop {OLLAMA_MODEL_NAME}")
os.system(f"ollama run {OLLAMA_MODEL_NAME} \"\" --keepalive 1h30m")
# set objective and dir to save the solution notebook
comp_prompt = baseline_prompt.format(**competition_info)
output_dir = f"{gen_dir}/{CURRENT_MODEL}/{competition}/{seed}"
with open("current-comp.json", "w") as out_file:
json.dump(
{
"request": comp_prompt,
"output_dir": output_dir
},
out_file)
# run framework
os.system("bash run_wrapper.sh")
# copy solutions to the correct directory
submission_dir = f"{submissions_dir}/{CURRENT_MODEL}/{competition}"
os.makedirs(submission_dir, exist_ok=True)
try:
shutil.copyfile(
f"{WORKSPACE_DIR}/submission.csv",
f"{submission_dir}/submission_{seed}_"
+ datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
+ ".csv")
os.system(f"rm {WORKSPACE_DIR}/submission.csv")
except Exception:
pass
add_solved(language, competition, seed)
# solve competiton (prompts and data may change depending on language)
def solve_per_language(language):
# set save dirs and trai/test files
submissions_dir = f"{SUBMISSIONS_DIR}/{language}"
gen_dir = f"{GENERATIONS_DIR}/{language}"
baseline_prompt_file = f"Prompts/base_prompt_{language}.md"
if language == "en":
train_file = "train.csv"
test_file = "test.csv"
else:
train_file = f"train_{language}.csv"
test_file = f"test_{language}.csv"
with open(baseline_prompt_file) as in_md:
baseline_prompt = in_md.read()
competitions = []
for competition in os.listdir(COMPETITIONS_DIR):
if competition[0:19] == "playground-series-s":
competitions.append(competition)
# solve each competition
for competition in competitions:
os.system(f"rm -r {WORKSPACE_DIR}/*")
with open(f"{COMPETITIONS_DIR}/{competition}/{language}_info.json") as in_json:
competition_info = json.load(in_json)
del competition_info['columns']
shutil.copyfile(
f"{COMPETITIONS_DIR}/{competition}/{train_file}",
f"{WORKSPACE_DIR}/train.csv")
shutil.copyfile(
f"{COMPETITIONS_DIR}/{competition}/{test_file}",
f"{WORKSPACE_DIR}/test.csv")
print("=========STARTING COMP===========")
print(baseline_prompt.format(**competition_info))
print("=================================")
for seed in SEED_LIST:
solve_comp(language, competition, competition_info, baseline_prompt, seed, submissions_dir, gen_dir)
print("============FINISHED=============")
for language in LANGUAGES:
solve_per_language(language)
os.system(f"ollama stop {OLLAMA_MODEL_NAME}")