-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcampaign_data_analysis_all.py
More file actions
1356 lines (1045 loc) · 45 KB
/
campaign_data_analysis_all.py
File metadata and controls
1356 lines (1045 loc) · 45 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import glob
import math
import subprocess
import json
import os
import itertools
import numpy as np
import matplotlib.pyplot as plt
import hashlib
import checksumdir
import inspect
import scipy.stats as st
from termcolor import cprint
import argparse
# use this command to parse SVGs to PDFs
# for f in *; do DISPLAY= inkscape $f --export-pdf="${f%.*}.pdf"; done
# crop pdf images with
# sudo apt-get install texlive-extra-utils
# for f in *_Fig.pdf; do pdfcrop $f $f; done
parser = argparse.ArgumentParser()
parser.add_argument("--no-show", action="store_true")
parser.add_argument("--fig-name", type=str, default="test")
parser.add_argument("--assert-n-contexts", type=int, default=-1, help="Set to <0 for no asserts")
parser.add_argument("--all-models", action="store_true")
args = parser.parse_args()
if args.all_models:
models = sorted([m.strip(".json") for m in os.listdir("./models/configs")])
else:
models = [
"llama_2_7b",
"llama_2_13b",
"llama_2_70b",
"llama_2_7b_chat",
"llama_2_13b_chat",
"llama_2_70b_chat",
"llama_3_8b_instruct",
"llama_3_70b_instruct",
"Mistral-7B-v0.1",
"Mistral-7B-Instruct-v0.1",
"Mistral-7B-Instruct-v0.2",
"zephyr-7b-beta",
"Mixtral-8x7B-v0.1-4b",
"Mixtral-8x7B-Instruct-v0.1-4b",
"Mixtral-8x7B-v0.1",
"Mixtral-8x7B-Instruct-v0.1",
"Mixtral-8x22B-Instruct-v0.1-4b",
"phi-1",
"phi-2",
"phi-3",
"Qwen-7B",
"Qwen-14B",
"Qwen-72B",
"Qwen1.5-72B-Chat",
"gpt-3.5-turbo-1106",
"gpt-3.5-turbo-0125",
"command_r_plus-4b",
# "dummy"
]
# models = ["dummy"]
# models = [
# "llama_2_7b",
# "llama_2_13b",
# "llama_2_70b",
# "llama_2_7b_chat",
# "llama_2_13b_chat",
# "llama_2_70b_chat",
# "Mistral-7B-v0.1",
# "Mistral-7B-Instruct-v0.1",
# "Mistral-7B-Instruct-v0.2",
# "zephyr-7b-beta",
# "Mixtral-8x7B-v0.1-4b",
# "Mixtral-8x7B-Instruct-v0.1-4b",
# "Mixtral-8x7B-v0.1",
# "Mixtral-8x7B-Instruct-v0.1",
# "phi-1",
# "phi-2",
# "Qwen-7B",
# "Qwen-14B",
# "Qwen-72B",
# "gpt-3.5-turbo-1106",
# "gpt-3.5-turbo-0125",
# ]
assert len(set(models)) == len(models)
def model_2_family(model):
model_lower = model.lower()
if "llama_2" in model_lower:
return "LLaMa-2"
if "llama_3" in model_lower:
return "LLaMa-3"
elif "mixtral" in model_lower:
return "Mixtral"
elif "mistral" in model_lower or "zephyr" in model_lower:
return "Mistral"
elif "phi" in model_lower:
return "Phi"
elif "qwen" in model_lower:
return "Qwen"
elif "gpt" in model_lower:
return "GPT"
elif "command" in model_lower:
return "command"
elif "dummy" == model_lower:
return "dummy"
elif "random" == model_lower:
return "random"
else:
return model
family_2_color = {
"LLaMa-2": "blue",
"LLaMa-3": "cornflowerblue",
"Mixtral": "orange",
"Mistral": "green",
"Phi": "red",
"Qwen": "purple",
"GPT": "black",
"command": "gold",
"dummy": "brown",
"random": "brown"
}
family_2_linestyle = {
"LLaMa-2": ":",
"Mixtral": "-",
"Mistral": "dashdot",
"Phi": (0, (3, 5, 1, 5, 1, 5)),
"Qwen": "--",
# "GPT": "-",
# "dummy": "-"
}
def FDR(scores):
from scipy.stats import ttest_ind
from statsmodels.stats.multitest import multipletests
# Compute pairwise t-tests
n_models = scores.shape[0]
p_values = np.ones((n_models, n_models)) # Initialize a matrix of p-values
for i in range(n_models):
for j in range(i + 1, n_models): # No need to test against itself or repeat comparisons
stat, p_value = ttest_ind(scores[i], scores[j])
p_values[i, j] = p_value
p_values[j, i] = p_value # Symmetric matrix
# Flatten the p-value matrix and remove ones to prepare for FDR correction
p_values_flat = p_values[np.tril_indices(n_models)]
# Apply FDR correction
reject, p_values_corrected, _, _ = multipletests(p_values_flat, alpha=0.05, method='fdr_bh')
# Reshape the corrected p-values back into a matrix
p_values_corrected_matrix = np.zeros((n_models, n_models))
p_values_corrected_matrix[np.tril_indices(n_models)] = p_values_corrected
p_values_corrected_matrix += p_values_corrected_matrix.T # Make symmetric
return p_values_corrected_matrix
def plot_comparison_matrix(models, p_values_matrix, figure_name, title="Model Comparison"):
fig, ax = plt.subplots(figsize=(8, 6))
cax = ax.matshow(p_values_matrix, cmap='gray_r')
# Setting axes labels
ax.set_xticks(range(len(models)))
ax.set_yticks(range(len(models)))
ax.set_xticklabels(models, rotation=90)
ax.set_yticklabels(models)
# Title and color bar
plt.title(title)
# fig.colorbar(cax)
plt.tight_layout()
fig_path = f'visualizations/{figure_name}_comparison.pdf'
print(f"save to: {fig_path}")
plt.savefig(fig_path)
if not args.no_show:
plt.show() # Sh
plt.close()
def legend_without_duplicate_labels(ax, loc="best", title=None, legend_loc=None):
handles, labels = ax.get_legend_handles_labels()
unique = [(h, l) for i, (h, l) in enumerate(zip(handles, labels)) if l not in labels[:i]]
# axs[plt_i].legend(bbox_to_anchor=legend_loc, loc="best")
if legend_loc:
loc="upper left"
else:
loc="best"
ax.legend(*zip(*unique), loc=loc, title=title, fontsize=legend_fontsize, title_fontsize=legend_fontsize, bbox_to_anchor=legend_loc)
def get_all_ipsative_corrs_str(default_profile):
if default_profile is None:
return "All_Ipsative_corrs"
else:
return "All_Ipsative_corrs_default_profile"
def get_all_ro_corrs_str(RO_neutral, paired_data_dir):
assert RO_neutral != paired_data_dir
if RO_neutral:
return "All_Neutral_Rank-Order_stabilities"
elif paired_data_dir:
return "All_Proxy_stabilities"
else:
return "All_Rank-Order_stabilities"
def run_analysis(eval_script_path, data_dir, assert_n_contexts=None, default_profile=None, paired_data_dir=None, RO_neutral=False, RO_neutral_data_dir=None, no_ips=False):
# run evaluation script
command = f"python {eval_script_path} --result-json-stdout {'--assert-n-dirs ' + str(assert_n_contexts) if assert_n_contexts else ''} {f'--default-profile {default_profile}' if default_profile is not None else ''} {data_dir}/* {f'--paired-dirs {paired_data_dir}/*/*' if paired_data_dir is not None else ''} {f'--neutral-ranks --neutral-dir {RO_neutral_data_dir}' if RO_neutral else ''} {'--no-ips' if no_ips else ''}"
print("Command: ", command)
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if stderr:
command = f"python {eval_script_path} --result-json-stdout {'--assert-n-dirs ' + str(assert_n_contexts) if assert_n_contexts else ''} {f'--default-profile {default_profile}' if default_profile is not None else ''} {data_dir}/*/* {f'--paired-dirs {paired_data_dir}/*/*' if paired_data_dir is not None else ''} {f'--neutral-ranks --neutral-dir {RO_neutral_data_dir}' if RO_neutral else ''} {'--no-ips' if no_ips else ''}"
print("(old savedir detected runing Command: ", command)
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
# parse json outputs
results = json.loads(stdout)
all_ipsative_corrs_str = get_all_ipsative_corrs_str(default_profile)
results[all_ipsative_corrs_str] = np.array(results[all_ipsative_corrs_str])
return results
all_data_dirs = []
x_label_map = {
"dummy": "random",
"llama_2_7b": "LLaMa_2_7b",
"llama_2_13b": "LLaMa_2_13b",
"llama_2_70b": "LLaMa_2_70b",
"llama_2_7b_chat": "LLaMa_2_7b_chat",
"llama_2_13b_chat": "LLaMa_2_13b_chat",
"llama_2_70b_chat": "LLaMa_2_70b_chat",
"phi-2": "Phi-2",
"phi-1": "Phi-1",
}
x_label_map = {**x_label_map, **{k: k.replace("_msgs", "") for k in ["1_msgs", "3_msgs", "5_msgs", "7_msgs", "9_msgs", "43_msgs"]}}
x_label_map = {**x_label_map, **{
"gpt-3.5-turbo-1106": "GPT-3.5-1106",
"gpt-3.5-turbo-0125": "GPT-3.5-0125",
}}
# Define the results directory
# sim conv
add_legend = False
bars_as_plot = False
label_ = None
results_dir = "results"
# experiment_dirs = [
# "sim_conv_pvq_tolkien_characters_seeds",
# # "sim_conv_pvq_famous_people_seeds",
# # "sim_conv_pvq_tolkien_characters_seeds_NO_SYSTEM",
# # "sim_conv_tolkien_donation_tolkien_characters_seeds",
# ]
# if "permutations_msgs" in experiment_dirs[0]:
# seed_strings = [f"{i}_msgs/_seed" for i in range(1, 10, 2)] # msgs (show trends
# # seed_strings = ["3_msgs/_seed"] # ips (only n=3)
# else:
# seed_strings = [f"{i}_seed" for i in range(1, 10, 2)]
# # seed_strings = [f"{i}_seed" for i in range(3, 10, 2)]
add_tolkien_ipsative_curve = True
bar_plots = False
metric = "Rank-Order"
# metric = "Ipsative"
ci_ticks = True
figure_name = args.fig_name
# list of options
# figure_name = "tolk_ro_t"
# figure_name = "fam_ro_t"
# figure_name = "no_pop_ips"
# figure_name = "no_pop_msgs"
# figure_name = "tolk_ro_msgs"
# figure_name = "religion_t"
# figure_name = "don_t"
# figure_name = "bag_t"
# figure_name = "paired_tolk_ro_uni"
# figure_name = "paired_tolk_ro_ben"
# figure_name = "paired_tolk_ro_pow"
# figure_name = "paired_tolk_ro_ach"
# app
# figure_name = "tolk_ips_msgs"
# figure_name = "tolk_ips_msgs_default_prof"
# figure_name = "tolk_ro_msgs_neutral"
# figure_name = "llama_sys_no_sys"
rotatation_x_labels = 0
legend_fontsize = 18
human_data_fontsize = 12
xticks_fontsize = 15
yticks_fontsize = 15
y_label_fontsize = 25
x_label_fontsize = 20
title_fontsize = 18
interval_figsize_x = 8
interval_figsize_y = 7
round_y_lab = 1
show_human_change = False
legend_loc = None
legend_title = "LLM families"
title=None
default_profile = None
add_tolkien_ro_curve = False
add_tolkien_ipsative_curve = False
left_adjust = None
paired_dir = None
y_label = None
x_label = None
RO_neutral = False
# FDR rest
FDR_test = False
# Families legend
families_plot = False
fam_min_y, fam_max_y = -0.1, 0.8
if figure_name == "leaderboard":
models = [
"dummy",
"phi-3",
"llama_3_8b_instruct"
]
experiment_dirs = ["leaderboard_pvq_real_world_people"]
seed_strings = [f""]
add_tolkien_ipsative_curve = False
bar_plots = True
add_legend = True
legend_fontsize = 20
legend_loc = (0.001, 0.59)
metric = "Rank-Order"
human_change_xloc = -0.5
msgs_ro_tolk = False
show_human_change = True
rotatation_x_labels = 90
xticks_fontsize = 15
yticks_fontsize = 18
min_y, max_y = -0.1, 0.85 # RO
elif figure_name == "tolk_ro_t":
experiment_dirs = ["stability_default_params_pvq_tolkien_characters"]
seed_strings = [f"seed_{i}" for i in range(0, 9, 2)]
add_tolkien_ipsative_curve = False
bar_plots = True
add_legend = True
legend_fontsize = 20
legend_loc = (0.001, 0.99)
metric = "Rank-Order"
human_change_xloc = 6.8
msgs_ro_tolk = False
show_human_change = True
rotatation_x_labels = 45
xticks_fontsize = 15
yticks_fontsize = 15
min_y, max_y = -0.1, 0.85 # RO
elif figure_name == "fam_ro_t":
experiment_dirs = ["stability_default_params_pvq_famous_people"]
seed_strings = [f"seed_{i}" for i in range(0, 9, 2)]
add_tolkien_ipsative_curve = False
bar_plots = True
add_legend = True
metric = "Rank-Order"
human_change_xloc = 6.8
msgs_ro_tolk = False
show_human_change = True
rotatation_x_labels = 45
xticks_fontsize = 15
yticks_fontsize = 15
min_y, max_y = -0.1, 1.0 # RO
elif figure_name.startswith("religion_t"):
rotatation_x_labels = 90
# title = "Religion stability of real world persons"
# title = "(C)"
# experiment_dirs = ["sim_conv_religion_famous_people_seeds"]
# seed_strings = [f"{i}_seed" for i in range(1, 10, 2)]
#
# experiment_dirs = ["RERUN_sim_conv_religion_famous_people_seeds"]
# seed_strings = [f"{i}_seed" for i in range(0, 9, 2)]
# models = [
# "llama_2_7b",
# "llama_2_13b",
# "llama_2_70b", # 2 gpu
# "llama_2_7b_chat",
# "llama_2_13b_chat",
# # "llama_2_70b_chat", # 2 gpu
# "Mistral-7B-v0.1",
# "Mistral-7B-Instruct-v0.1",
# "Mistral-7B-Instruct-v0.2",
# "zephyr-7b-beta",
# "Mixtral-8x7B-v0.1-4b", # 6h
# "Mixtral-8x7B-Instruct-v0.1-4b", # 6h
# "Mixtral-8x7B-v0.1",
# "Mixtral-8x7B-Instruct-v0.1",
# "phi-1",
# "phi-2",
# "Qwen-7B",
# "Qwen-14B",
# "Qwen-72B",
# "gpt-3.5-turbo-1106",
# "gpt-3.5-turbo-0125",
#
# ]
#
# experiment_dirs = ["stability_religion_famous_people"]
# seed_strings = [f"seed_{i}" for i in range(0, 9, 2)]
experiment_dirs = ["stability_default_params_religion_famous_people"]
seed_strings = [f"seed_{i}" for i in range(0, 9, 2)]
add_tolkien_ipsative_curve = False
bar_plots = True
add_legend = False
metric = "Rank-Order"
msgs_ro_tolk = False
show_human_change = False
legend_fontsize = 22
xticks_fontsize = 15
yticks_fontsize = 18
min_y, max_y = -0.1, 0.8 # RO
elif figure_name == "don_t":
experiment_dirs = ["stability_default_params_tolkien_donation_tolkien_characters"]
seed_strings = [f"seed_{i}" for i in range(0, 9, 2)]
add_tolkien_ipsative_curve = False
bar_plots = True
metric = "Rank-Order"
human_change_xloc = 6.8
msgs_ro_tolk = False
rotatation_x_labels = 45
xticks_fontsize = 15
yticks_fontsize = 18
min_y, max_y = -0.1, 0.8 # RO
elif figure_name.startswith("bag_t"):
experiment_dirs = ["stability_default_params_tolkien_bag_tolkien_characters"]
seed_strings = [f"seed_{i}" for i in range(0, 9, 2)]
add_tolkien_ipsative_curve = False
bar_plots = True
add_legend = True
metric = "Rank-Order"
human_change_xloc = 6.8
msgs_ro_tolk = False
rotatation_x_labels = 90
xticks_fontsize = 15
yticks_fontsize = 15
min_y, max_y = -0.1, 0.8 # RO
elif figure_name == "no_pop_msgs":
experiment_dirs = ["stability_default_params_pvq_permutations_msgs"]
seed_strings = [f"{i}_msgs/_seed" for i in range(1, 10, 2)] + ["43_msgs/_seed"] # msgs (show trends)
FDR_test = False
add_tolkien_ipsative_curve = True
bar_plots = False
models = [
"phi-1",
"Mixtral-8x7B-Instruct-v0.1",
"Mixtral-8x7B-Instruct-v0.1-4b", # 6h
"zephyr-7b-beta",
"Mistral-7B-Instruct-v0.2",
"Mistral-7B-Instruct-v0.1",
"Qwen-72B",
"Qwen-14B",
"Qwen-7B",
"llama_2_70b_chat", # 2 gpu
"llama_2_70b", # 2 gpu
"phi-2",
"gpt-3.5-turbo-0125",
]
metric = "Ipsative"
human_change_xloc = -1.0
msgs_ro_tolk = False
add_legend = True
min_y, max_y = -0.1, 1.0 # IPS
legend_fontsize = 22
xticks_fontsize = 20
yticks_fontsize = 20
y_label_fontsize = 40
x_label_fontsize = 20
interval_figsize_x = 14
interval_figsize_y = 7
x_label = "Simulated conversation length (n)"
elif figure_name == "tolk_ips_msgs_default_prof":
# Messages on Ips Tolkien
models = ["1_msgs", "3_msgs", "5_msgs", "7_msgs", "9_msgs"]
experiment_dirs = ["sim_conv_pvq_tolkien_characters_msgs/Mixtral-8x7B-Instruct-v0.1"]
seed_strings = [f"{i}_seed" for i in range(1, 10, 2)]
y_label = "Stability"
bar_plots = True
bars_as_plot = True
add_tolkien_ro_curve = True
add_tolkien_ipsative_curve = False
msgs_ro_tolk = True
legend_title = None
legend_fontsize = 14
label_ = "Ipsative stability (with\n the default profile)"
metric = "Ipsative_default_profile"
default_profile = "results/sim_conv_pvq_permutations_msgs/Mixtral-8x7B-Instruct-v0.1/9_msgs/_seed/results_sim_conv_permutations_Mixtral-8x7B-Instruct-v0.1/pvq_test_Mixtral-8x7B-Instruct-v0.1_data_pvq_pvq_auto__permutations_50_permute_options_5_no_profile_True_format_chat___2024_02_14_20_47_27"
add_legend = True
human_change_xloc = 6.8
show_human_change = False
min_y, max_y = 0.3, 0.8 # IPS
round_y_lab = 2
left_adjust = 0.15
interval_figsize_x = 6
interval_figsize_y = 6
# PLOSONE
interval_figsize_x = 6
interval_figsize_y = 4
elif figure_name == "no_pop_ips":
experiment_dirs = ["stability_default_params_pvq_permutations_msgs"]
seed_strings = ["3_msgs/_seed"] # ips (only n=3)
add_tolkien_ipsative_curve = False
bar_plots = True
add_legend = True
metric = "Ipsative"
human_change_xloc = -1.0
msgs_ro_tolk = False
show_human_change = True
human_data_fontsize = 8
xticks_fontsize = 17
yticks_fontsize = 20
legend_fontsize = 25
rotatation_x_labels = 45
y_label_fontsize = 30
# legend_loc = (0.2, 0.45)
legend_loc = (1, 1)
interval_figsize_x = 14
interval_figsize_y = 7
human_data_fontsize = 14
min_y, max_y = -0.1, 1.0 # IPS
elif figure_name.startswith("paired_tolk_ro"):
if figure_name.endswith("uni"):
value_to_pair = "Universalism"
letter = "(A)"
elif figure_name.endswith("ben"):
value_to_pair = "Benevolence"
letter = "(B)"
elif figure_name.endswith("pow"):
value_to_pair = "Power"
letter = "(C)"
elif figure_name.endswith("ach"):
value_to_pair = "Achievement"
letter = "(D)"
else:
raise ValueError(f"Undefined figure name: {figure_name}")
# title = f"{letter} {value_to_pair}"
# y_label = f"Rank-Order stability\n{value_to_pair}-Donation"
y_label = f"Rank-Order stability\nwith donation"
# experiment_dirs = ["RERUN_sim_conv_pvq_tolkien_characters_seeds"]
# paired_dir = "RERUN_sim_conv_tolkien_donation_tolkien_characters_seeds"
# seed_strings = [f"{i}_seed" for i in range(0, 9, 2)]
experiment_dirs = ["stability_default_params_pvq_tolkien_characters"]
paried_dir = ["stability_default_params_tolkien_donation_tolkien_characters"]
seed_strings = [f"seed_{i}" for i in range(0, 9, 2)]
add_tolkien_ipsative_curve = False
bar_plots = True
if value_to_pair == "Universalism":
add_legend = True
legend_fontsize = 20
else:
add_legend = False
metric = "Rank-Order"
msgs_ro_tolk = False
show_human_change = False
human_change_xloc = 6.8
rotatation_x_labels = 90
xticks_fontsize = 15
yticks_fontsize = 18
left_adjust = 0.2
if value_to_pair in ["Power", "Achievement"]:
min_y, max_y = -0.5, 0.1
else:
min_y, max_y = -0.1, 0.5
elif figure_name == "fam_ro_t_29":
experiment_dirs = [""]
seed_strings = [f"seed_{i}" for i in range(0, 9, 2)]
models = [
"stability_default_params_pvq_famous_people/llama_3_70b_instruct",
"stability_default_params_pvq_famous_people_29_msgs/llama_3_70b_instruct",
"stability_default_params_pvq_famous_people/llama_3_8b_instruct",
"stability_default_params_pvq_famous_people_9_msgs/llama_3_8b_instruct",
"stability_default_params_pvq_famous_people_19_msgs/llama_3_8b_instruct",
"stability_default_params_pvq_famous_people_29_msgs/llama_3_8b_instruct",
]
x_label_map.update({
"stability_default_params_pvq_famous_people/llama_3_70b_instruct": "70b-inst (3 msgs)",
"stability_default_params_pvq_famous_people_29_msgs/llama_3_70b_instruct": "70b-inst (29 msgs)",
"stability_default_params_pvq_famous_people/llama_3_8b_instruct": "8b-instr (3 msgs)",
"stability_default_params_pvq_famous_people_9_msgs/llama_3_8b_instruct": "8b-isnt (9 msgs)",
"stability_default_params_pvq_famous_people_19_msgs/llama_3_8b_instruct": "8b-isnt (19 msgs)",
"stability_default_params_pvq_famous_people_29_msgs/llama_3_8b_instruct": "8b-isnt (29 msgs)",
})
model_2_family = lambda model: "LLaMa-3-70b-instruct" if "70b" in model else "LLaMa-3-8b-instruct"
family_2_color = {"LLaMa-3-70b-instruct": "blue", "LLaMa-3-8b-instruct": "green"}
title = "LLaMa-3 simulating famous people (PVQ)"
# x_label = "Simulated conversation length"
add_tolkien_ipsative_curve = False
bar_plots = True
add_legend = True
legend_title = "Model"
metric = "Rank-Order"
human_change_xloc = 1.8
msgs_ro_tolk = False
show_human_change = True
rotatation_x_labels = 90
xticks_fontsize = 15
yticks_fontsize = 18
min_y, max_y = -0.1, 1.0 # RO
elif figure_name == "tolk_ro_msgs":
# Messages on Rank-Order Tolkien
models = ["1_msgs", "3_msgs", "5_msgs", "7_msgs", "9_msgs"]
experiment_dirs = ["sim_conv_pvq_tolkien_characters_msgs/Mixtral-8x7B-Instruct-v0.1"]
seed_strings = [f"{i}_seed" for i in range(1, 10, 2)]
add_legend = False
bar_plots = True
bars_as_plot = False
add_tolkien_ipsative_curve = False
msgs_ro_tolk = True
metric = "Rank-Order"
human_change_xloc = 6.8
interval_figsize_x = 14
interval_figsize_y = 7
xticks_fontsize = 25
yticks_fontsize = 25
y_label_fontsize = 35
x_label_fontsize = 30
round_y_lab = 2
min_y, max_y = 0.25, 0.5 # RO
x_label = "Simulated conversation length (n)"
elif figure_name == "tolk_ro_msgs_neutral":
# Messages on Rank-Order Tolkien
models = ["1_msgs", "3_msgs", "5_msgs", "7_msgs", "9_msgs"]
experiment_dirs = ["sim_conv_pvq_tolkien_characters_msgs/Mixtral-8x7B-Instruct-v0.1"]
seed_strings = [f"{i}_seed" for i in range(1, 10, 2)]
RO_neutral_dir = "sim_conv_pvq_tolkien_characters_seeds/Mixtral-8x7B-Instruct-v0.1"
RO_neutral = True
bar_plots = True
bars_as_plot = True
add_tolkien_ipsative_curve = False
add_tolkien_ro_curve = True
msgs_ro_tolk = True
add_legend = True
legend_title=None
label_ = "Rank-Order stability\n (with the neutral order)"
metric = "Rank-Order"
human_change_xloc = 6.8
interval_figsize_x = 14
interval_figsize_y = 7
xticks_fontsize = 25
yticks_fontsize = 25
y_label_fontsize = 35
x_label_fontsize = 30
round_y_lab = 2
min_y, max_y = 0.30, 0.58 # RO
elif figure_name == "tolk_ips_msgs":
# Messages on Ips Tolkien
models = ["1_msgs", "3_msgs", "5_msgs", "7_msgs", "9_msgs", "43_msgs"]
experiment_dirs = ["sim_conv_pvq_tolkien_characters_msgs/Mixtral-8x7B-Instruct-v0.1"]
seed_strings = [f"{i}_seed" for i in range(1, 10, 2)]
# models = ["1_msgs", "3_msgs", "5_msgs", "7_msgs", "9_msgs"]
# experiment_dirs = ["stability_default_params_pvq_tolkien_characters_more_msgs/Mixtral-8x7B-Instruct-v0.1"]
seed_strings = ["1_seed"]
bar_plots = True
bars_as_plot = True
add_tolkien_ipsative_curve = False
msgs_ro_tolk = True
metric = "Ipsative"
human_change_xloc = 6.8
min_y, max_y = -0.1, 1 # IPS
elif figure_name == "llama_sys_no_sys":
families_plot = False
# title = "Personal value stability of fictional characters with PVQ"
experiment_dirs = [
# "sim_conv_pvq_tolkien_characters_seeds",
# "sim_conv_pvq_tolkien_characters_seeds_NO_SYSTEM",
""
]
seed_strings = [f"{i}_seed" for i in range(1, 10, 2)]
models = [
"sim_conv_pvq_tolkien_characters_seeds/llama_2_7b_chat",
"sim_conv_pvq_tolkien_characters_seeds/llama_2_13b_chat",
"sim_conv_pvq_tolkien_characters_seeds/llama_2_70b_chat", # 2 gpu
"sim_conv_pvq_tolkien_characters_seeds_NO_SYSTEM/llama_2_7b_chat",
"sim_conv_pvq_tolkien_characters_seeds_NO_SYSTEM/llama_2_13b_chat",
"sim_conv_pvq_tolkien_characters_seeds_NO_SYSTEM/llama_2_70b_chat", # 2 gpu
]
x_label_map = {
"sim_conv_pvq_tolkien_characters_seeds/llama_2_7b_chat": "llama_2_7b_chat_sys",
"sim_conv_pvq_tolkien_characters_seeds/llama_2_13b_chat": "llama_2_13b_chat_sys",
"sim_conv_pvq_tolkien_characters_seeds/llama_2_70b_chat": "llama_2_70b_chat_sys", # 2 gpu
"sim_conv_pvq_tolkien_characters_seeds_NO_SYSTEM/llama_2_7b_chat": "llama_2_7b_chat_no_sys",
"sim_conv_pvq_tolkien_characters_seeds_NO_SYSTEM/llama_2_13b_chat": "llama_2_13b_chat_no_sys",
"sim_conv_pvq_tolkien_characters_seeds_NO_SYSTEM/llama_2_70b_chat": "llama_2_70b_chat_no_sys", # 2 gpu
}
add_tolkien_ipsative_curve = False
bar_plots = True
add_legend = False
metric = "Rank-Order"
human_change_xloc = -0.5
msgs_ro_tolk = False
show_human_change = True
legend_fontsize = 22
rotatation_x_labels = 90
show_human_changea = False
xticks_fontsize = 15
yticks_fontsize = 18
min_y, max_y = -0.1, 0.8 # RO
else:
raise ValueError("Unknown figure name")
if y_label is None:
y_label = metric + " stability (r)"
if add_tolkien_ipsative_curve:
with open("tolkien_ipsative_curve_cache.json", "r") as f:
tolkien_ipsative_curve = json.load(f)
if add_tolkien_ro_curve:
with open("tolkien_ro_curve_cache.json", "r") as f:
tolkien_ro_curve = json.load(f)
n_comp = math.comb(len(models), 2) # n comparisons
print("N_comp:", n_comp)
confidence = 0.95
if args.assert_n_contexts < 0:
args.assert_n_contexts = None
else:
cprint(f"Asserting {args.assert_n_contexts} contexts.", "green")
# prefix = "results_pvq_sim_conv_famous_people"
# prefix = "results_ult_sim_conv_famous_people"
data = {}
for experiment_dir in experiment_dirs:
print(f"{experiment_dir}")
data[experiment_dir] = {}
for model in models:
print(f"\t{model}")
data[experiment_dir][model] = {}
for seed_str in seed_strings:
data[experiment_dir][model][seed_str] = {}
# data_dir = os.path.join("results", experiment_dir, model, seed_str)
data_dir = os.path.join(results_dir, experiment_dir, model, seed_str)
if paired_dir:
paired_data_dir = os.path.join("results", paired_dir, model, seed_str)
else:
paired_data_dir = None
if RO_neutral:
RO_neutral_data_dir = os.path.join("results", RO_neutral_dir, seed_str)
else:
RO_neutral_data_dir = None
n_evals_found = max(len(glob.glob(data_dir+"/*/*.json")), len(glob.glob(data_dir + "/*/*/*.json")))
if n_evals_found < 3:
print(f"{n_evals_found} < 3 evaluations found at {data_dir}.")
# no evaluations
eval_data = dict(zip(["Mean-Level", "Rank-Order", "Ipsative"], [np.nan, np.nan, np.nan]))
# elif args.assert_n_contexts and args.assert_n_contexts != n_evals_found:
# raise AssertionError(f"{n_evals_found} evaluations found, {args.assert_n_contexts} was asserted.")
else:
no_ips = metric != "Ipsative"
# compute hash
eval_script_path = "./visualization_scripts/data_analysis.py"
with open(eval_script_path, 'rb') as file_obj: eval_script = str(file_obj.read())
hash = hashlib.sha256("-".join(
[eval_script, inspect.getsource(run_analysis), checksumdir.dirhash(data_dir),
str(args.assert_n_contexts), str(False),
str(default_profile), str(paired_data_dir),
str(RO_neutral), str(RO_neutral_data_dir),
str(no_ips)
]).encode()).hexdigest()
cache_path = f".cache/{hash}.json"
# check for cache
if os.path.isfile(cache_path):
with open(cache_path) as f:
print("\t\tLoading from cache")
eval_data = json.load(f)
else:
print("\t\tEvaluating")
eval_data = run_analysis(
eval_script_path=eval_script_path, data_dir=data_dir, assert_n_contexts=args.assert_n_contexts,
default_profile=default_profile,
paired_data_dir=paired_data_dir, RO_neutral=RO_neutral, RO_neutral_data_dir=RO_neutral_data_dir,
no_ips=no_ips,
)
with open(cache_path, 'w') as fp:
class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
return json.JSONEncoder.default(self, obj)
json.dump(eval_data, fp, cls=NumpyEncoder)
data[experiment_dir][model][seed_str] = eval_data.copy()
keys_to_print = ["Mean-Level", "Rank-Order", "Ipsative"]
metrs_str = {k: np.round(v, 2) for k, v in data[experiment_dir][model][seed_str].items() if k in keys_to_print}
print(f"\t\t- {seed_str} : {metrs_str}")
human_data_color = "black"
# # ips
# legend_fontsize = 8
# human_data_fontsize = 5.5
human_change_10_12 = {"Rank-Order": 0.569, "Ipsative": 0.66}
human_change_20_28 = {"Rank-Order": 0.657, "Ipsative": 0.59}
human_change_20_24 = {"Rank-Order": 0.69, "Ipsative": 0.59}
human_change_24_28 = {"Rank-Order": 0.77, "Ipsative": 0.65}
num_plots = len(experiment_dirs)
num_cols = min(len(experiment_dirs), 3) # Adjust this as needed for a better layout
num_rows = num_plots // num_cols + (num_plots % num_cols > 0)
print(f"Metric: {metric}")
fig, axs = plt.subplots(num_rows, num_cols, figsize=(interval_figsize_x * num_cols, interval_figsize_y * num_rows))
if num_cols == 1:
axs=[axs]
else:
axs = axs.flatten()
all_ipsative_corrs_str = get_all_ipsative_corrs_str(default_profile)
all_ro_corrs_str = get_all_ro_corrs_str(RO_neutral, paired_data_dir)
from collections import defaultdict
family_data = defaultdict(list)
for plt_i, experiment_dir in enumerate(experiment_dirs):
if show_human_change:
if default_profile: