-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualisation.py
84 lines (71 loc) · 2.54 KB
/
visualisation.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
82
83
84
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
class ResultVisualizer:
def __init__(self, results_df: pd.DataFrame):
self.results_df = results_df
def plot_performance_by_model(self, metric: str = 'response_length'):
"""
Create a box plot comparing a metric across different models
:param metric: Metric to visualize
"""
plt.figure(figsize=(12, 6))
sns.boxplot(x='model', y=metric, data=self.results_df)
plt.title(f'{metric.replace("_", " ").title()} by Model')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
def plot_parameter_impact(self,
parameter: str = 'temperature',
metric: str = 'response_length'):
"""
Visualize the impact of a parameter on a specific metric
:param parameter: Model parameter to analyze
:param metric: Metric to compare
"""
plt.figure(figsize=(12, 6))
sns.scatterplot(
x=parameter,
y=metric,
hue='model',
data=self.results_df
)
plt.title(f'Impact of {parameter} on {metric}')
plt.tight_layout()
plt.show()
def generate_comprehensive_report(self):
"""
Generate a multi-plot report of key metrics
"""
fig, axs = plt.subplots(2, 2, figsize=(20, 15))
# Metrics to visualize
metrics = [
'response_length',
'flesch_reading_ease',
'lexical_diversity',
'prompt_response_similarity'
]
for i, metric in enumerate(metrics):
row = i // 2
col = i % 2
sns.boxplot(
x='model',
y=metric,
data=self.results_df,
ax=axs[row, col]
)
axs[row, col].set_title(f'{metric.replace("_", " ").title()} by Model')
axs[row, col].tick_params(axis='x', rotation=45)
plt.tight_layout()
plt.show()
def save_report(self, filename: str = 'llm_test_report.pdf'):
"""
Save the visualization report as a PDF
:param filename: Output filename
"""
from matplotlib.backends.backend_pdf import PdfPages
with PdfPages(filename) as pdf:
# Generate comprehensive report
self.generate_comprehensive_report()
pdf.savefig()
plt.close()