1+ from datetime import date
2+
13import matplotlib .pyplot as plt
24import numpy as np
35
68
79def create_box_plot (all_results : dict [str , list [EvaluationMetrics ]]) -> None :
810 """Create box plot of R² scores by model."""
9- models = list (all_results .keys ())
11+ # Sort models by median R² score in ascending order (lowest bottom, highest top)
12+ models = sorted (
13+ all_results .keys (),
14+ key = lambda x : np .median ([metrics .r2 for metrics in all_results [x ]]),
15+ )
1016 r2_scores = []
1117
1218 for model in models :
1319 model_r2_scores = [metrics .r2 for metrics in all_results [model ]]
1420 r2_scores .append (model_r2_scores )
1521
1622 plt .style .use ("grayscale" )
17- plt .figure (figsize = (10 , 6 ))
18- plt .boxplot (r2_scores , tick_labels = models , patch_artist = False )
19-
20- plt .title ("How Well Embedding Models Understand Companies" )
21- plt .xlabel ("Embedding Model (applied to company name)" )
22- plt .ylabel ("R² Score (based on embedded company name only)" )
23- plt .grid (True , alpha = 0.3 )
24- plt .xticks (rotation = 45 )
23+ plt .figure (figsize = (8 , 8 ))
24+ plt .tight_layout ()
25+ plt .boxplot (r2_scores , tick_labels = models , patch_artist = False , vert = False )
26+
27+ today = get_date_str ()
28+ plt .suptitle (f"LLM Company Knowledge: Predictive Power of Embeddings ({ today } )" )
29+ plt .xlabel ("R² Score" )
30+ plt .ylabel ("LLM Embedding" )
31+ plt .grid (True , alpha = 0.3 , axis = "x" )
32+ plt .yticks (rotation = 0 )
33+
34+ # Add watermark
35+ add_watermark ()
36+
2537 plt .tight_layout ()
2638
2739 # Save the plot
@@ -41,8 +53,8 @@ def create_box_plot(all_results: dict[str, list[EvaluationMetrics]]) -> None:
4153
4254def create_r2_plot (results : dict [str , EvaluationMetrics ]) -> None :
4355 """Create bar plot of R² scores by LLM model."""
44- # Sort models by R² score in descending order
45- models = sorted (results .keys (), key = lambda x : results [x ].r2 , reverse = True )
56+ # Sort models by R² score in ascending order (lowest at bottom, highest at top)
57+ models = sorted (results .keys (), key = lambda x : results [x ].r2 )
4658 r2_scores = [results [model ].r2 for model in models ]
4759
4860 # Clean up model names for display
@@ -55,40 +67,41 @@ def create_r2_plot(results: dict[str, EvaluationMetrics]) -> None:
5567 display_names .append (model )
5668
5769 plt .style .use ("grayscale" )
58- plt .figure (figsize = (12 , 6 ))
59- bars = plt .bar (range (len (models )), r2_scores )
70+ plt .figure (figsize = (8 , 8 ))
71+ bars = plt .barh (range (len (models )), r2_scores )
6072
61- plt .title ("LLM Performance on Competitiveness Rating Task" )
62- plt .xlabel ("LLM Model" )
63- plt .ylabel ("R² Score" )
64- plt .xticks (range (len (models )), display_names , rotation = 45 , ha = "right" )
65- plt .grid (True , alpha = 0.3 , axis = "y" )
66- plt .ylim (- 1.0 , 1.0 )
73+ today = get_date_str ()
74+ plt .suptitle (f"LLM Company Knowledge: Accuracy vs Human Experts ({ today } )" )
75+ plt .xlabel ("R² Score" )
76+ plt .ylabel ("LLM" )
77+ plt .yticks (range (len (models )), display_names )
78+ plt .grid (True , alpha = 0.3 , axis = "x" )
79+ plt .xlim (- 1.0 , 1.0 )
6780
6881 # Add value labels on bars
6982 for bar , score in zip (bars , r2_scores ):
70- y_pos = bar .get_height () + 0.01 if score >= 0 else bar .get_height () - 0.01
71- va = "bottom " if score >= 0 else "top "
83+ x_pos = bar .get_width () + 0.01 if score >= 0 else bar .get_width () - 0.01
84+ ha = "left " if score >= 0 else "right "
7285 plt .text (
73- bar . get_x () + bar . get_width () / 2 ,
74- y_pos ,
86+ x_pos ,
87+ bar . get_y () + bar . get_height () / 2 ,
7588 f"{ score :.3f} " ,
76- ha = "center" ,
77- va = va ,
89+ ha = ha ,
90+ va = "center" ,
7891 )
7992
80- plt .tight_layout ()
93+ # Add watermark
94+ add_watermark ()
8195
8296 # Save the plot
97+ plt .tight_layout ()
8398 plt .savefig (".data/plots/r2-scores-barplot.png" , dpi = 300 , bbox_inches = "tight" )
8499
85100
86101def create_spearman_plot (results : dict [str , EvaluationMetrics ]) -> None :
87102 """Create bar plot of Spearman correlations by LLM model."""
88- # Sort models by Spearman correlation in descending order
89- models = sorted (
90- results .keys (), key = lambda x : results [x ].spearman_corr , reverse = True
91- )
103+ # Sort models by Spearman correlation ascending (lowest bottom, highest top)
104+ models = sorted (results .keys (), key = lambda x : results [x ].spearman_corr )
92105 spearman_corrs = [results [model ].spearman_corr for model in models ]
93106
94107 # Clean up model names for display
@@ -101,29 +114,32 @@ def create_spearman_plot(results: dict[str, EvaluationMetrics]) -> None:
101114 display_names .append (model )
102115
103116 plt .style .use ("grayscale" )
104- plt .figure (figsize = (12 , 6 ))
105- bars = plt .bar (range (len (models )), spearman_corrs )
117+ plt .figure (figsize = (8 , 8 ))
118+ bars = plt .barh (range (len (models )), spearman_corrs )
106119
107- plt .title ("LLM Performance on Competitiveness Rating Task" )
108- plt .xlabel ("LLM Model" )
109- plt .ylabel ("Spearman Correlation" )
110- plt .xticks (range (len (models )), display_names , rotation = 45 , ha = "right" )
111- plt .grid (True , alpha = 0.3 , axis = "y" )
112- plt .ylim (0 , 1.0 )
120+ today = get_date_str ()
121+ plt .suptitle (f"LLM Company Knowledge: Ranking Correlation with Experts ({ today } )" )
122+ plt .xlabel ("Spearman Correlation" )
123+ plt .ylabel ("LLM" )
124+ plt .yticks (range (len (models )), display_names )
125+ plt .grid (True , alpha = 0.3 , axis = "x" )
126+ plt .xlim (0 , 1.0 )
113127
114128 # Add value labels on bars
115129 for bar , corr in zip (bars , spearman_corrs ):
116130 plt .text (
117- bar .get_x () + bar . get_width () / 2 ,
118- bar .get_height () + 0.01 ,
131+ bar .get_width () + 0.01 ,
132+ bar .get_y () + bar . get_height () / 2 ,
119133 f"{ corr :.3f} " ,
120- ha = "center " ,
121- va = "bottom " ,
134+ ha = "left " ,
135+ va = "center " ,
122136 )
123137
124- plt .tight_layout ()
138+ # Add watermark
139+ add_watermark ()
125140
126141 # Save the plot
142+ plt .tight_layout ()
127143 plt .savefig (
128144 ".data/plots/spearman-correlations-barplot.png" , dpi = 300 , bbox_inches = "tight"
129145 )
@@ -137,3 +153,23 @@ def create_spearman_plot(results: dict[str, EvaluationMetrics]) -> None:
137153 print (f" Spearman ρ: { metrics .spearman_corr :.4f} (p={ metrics .spearman_p :.4f} )" )
138154 print (f" R²: { metrics .r2 :.4f} " )
139155 print (f" RMSE: { metrics .rmse :.4f} " )
156+
157+
158+ def get_date_str () -> str :
159+ """Get current date formatted as 'Month Year'."""
160+ return date .today ().strftime ("%B %Y" )
161+
162+
163+ def add_watermark () -> None :
164+ """Add Apistemic watermark to current plot."""
165+ plt .text (
166+ 0.98 ,
167+ 0.02 ,
168+ "© Apistemic GmbH, apistemic.com" ,
169+ transform = plt .gca ().transAxes ,
170+ fontsize = 10 ,
171+ alpha = 0.6 ,
172+ ha = "right" ,
173+ va = "bottom" ,
174+ color = "gray" ,
175+ )
0 commit comments