-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtable_to_html.py
66 lines (59 loc) · 2.43 KB
/
table_to_html.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
import pandas as pd
import json
import os
models = {
"gptj": "GPT-J 6B",
"gpt2_large": "GPT2 Large",
"gpt_neo_2_7": "GPT Neo Large",
"opt_6_7b": "OPT 6.7B",
"bloomz": "BLOOMZ 3B",
"bloom": "BLOOM 3B",
"bloom_560m": "BLOOM 560M",
"bloom_7b": "BLOOM 7B",
"opt_125m": "OPT 125M",
}
def make_tables(questions_file, prompt_names, for_models=[]):
f = open(questions_file)
list_of_qs = json.load(f)
html_templates = []
big_df = pd.DataFrame()
for prompt_name in prompt_names:
html_template = ""
for filename in os.listdir(f"models_outputs/{prompt_name}"):
model_name = "_".join(filename.split("_")[: len(filename.split("_")) - 1])
if for_models:
if model_name not in for_models:
continue
df = pd.read_csv(
os.path.join(f"models_outputs/{prompt_name}", filename), sep="\t"
)
df["model"] = model_name
big_df = pd.concat([big_df, df], ignore_index=True)
dict_for_table = {}
for question in list_of_qs[prompt_name]:
if question not in dict_for_table:
dict_for_table[question] = {}
dict_for_table[question]["replies"] = {}
for _, row in big_df.iterrows():
if question in row["result"]:
dict_for_table[question]["question_type"] = row["utterances group"]
dict_for_table[question]["replies"][row["model"]] = {}
dict_for_table[question]["replies"][row["model"]]["reply"] = (
row["result"]
.split(question)[1]
.split("\n\n")[0]
.replace("\n", "")
.replace("AI: ", "")
)
for question in dict_for_table.keys():
html_template += (
f"""<tr><td colspan=3 style="text-align: center">{question}</td></tr>"""
)
for model in dict_for_table[question]["replies"].keys():
html_template += f"""<tr><td>{models[model]}</td><td>{dict_for_table[question]['replies'][model]['reply']}</td><td>{dict_for_table[question]["question_type"]}</td></tr>"""
html_templates.append(html_template)
return html_templates
all_tables = make_tables(
"list_of_qs.json", ["pizza", "spacex", "dreambot"], for_models=["gptj", "bloom"]
)
print(all_tables)