-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze_results.py
81 lines (64 loc) · 2.02 KB
/
analyze_results.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
import argparse
import json
from pathlib import Path
import typing
from lm_survey.survey import SurveyResults
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-e",
"--experiment",
type=str,
help="The name of the experiment to run.",
default="default",
)
parser.add_argument(
"-m",
"--model",
type=str,
help="The name of the model to run.",
default="llama-65b-hf",
)
parser.add_argument(
"-s",
"--survey",
type=str,
default="roper",
help="The name of the survey to run.",
)
args = parser.parse_args()
experiment_dir = Path("experiments", args.experiment, args.survey)
results_filename = Path("results.json")
paths: typing.Dict[str, Path] = {
"center": experiment_dir / args.model / results_filename,
# "left": experiment_dir / f"{args.model}-left" / results_filename,
# "right": experiment_dir / f"{args.model}-right" / results_filename,
}
results = {}
for ideology, path in paths.items():
if not path.exists():
raise ValueError(f"Path {path} does not exist.")
with open(path, "r") as file:
ideology_results = json.load(file)
results[ideology] = ideology_results
survey_results = {
ideology: SurveyResults(question_samples=ideology_results)
for ideology, ideology_results in results.items()
}
slices = []
# for ideology, ideology_survey_results in survey_results.items():
# print(ideology)
# print(
# ideology_survey_results.get_mean_score(slice_by=slices).nlargest(
# 3, "95%_lower_bound_gain"
# ),
# sep="\n",
# end="\n\n",
# )
analysis_path = experiment_dir / args.model / "analysis.json"
summary_df = (
survey_results["center"]
.summarize(slice_by=slices)
.round(2)
.to_json(analysis_path, indent=4)
)