-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretrieve_vs_not_in_pl.py
More file actions
120 lines (103 loc) · 3.71 KB
/
Copy pathretrieve_vs_not_in_pl.py
File metadata and controls
120 lines (103 loc) · 3.71 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
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams.update({"font.size": 16})
# --- Twoje dane (bez routing) ---
retrieve_not_skipped = {
"aggregation": {
"total_input_tokens": 11399,
"total_output_tokens": 1660,
"execution_time_seconds": 34.6043,
},
"average_completeness": 8.8,
"average_faithfulness": 8.6,
}
retrieve_skipped = {
"aggregation": {
"total_input_tokens": 699,
"total_output_tokens": 974,
"execution_time_seconds": 18.9273,
},
"average_completeness": 10.0,
"average_faithfulness": 10.0,
}
def extract_metrics(name, data):
aggr = data.get("aggregation", {})
return {
"scenario": name,
"łączna ilość tokenów wejściowych": aggr.get("total_input_tokens"),
"łączna ilość tokenów wyjściowych": aggr.get("total_output_tokens"),
"czas przetwarzania [s]": aggr.get("execution_time_seconds"),
"średnia wartość metryki completeness": data.get("average_completeness"),
"średnia wartość metryki faithfulness": data.get("average_faithfulness"),
}
# --- Tabela zbiorcza ---
df = pd.DataFrame(
[
extract_metrics("brak pominięcia poboru kontekstu", retrieve_not_skipped),
extract_metrics("pominięcie poboru kontekstu", retrieve_skipped),
]
)
# --- Konfiguracja osi i grupowania ---
scenarios = df["scenario"].values
x = np.arange(len(scenarios)) # 0..N-1
fig, ax1 = plt.subplots(figsize=(18, 8))
# Rozmiary / pozycje słupków w grupie
bar_w = 0.12
tok_offsets = [-0.30, -0.15] # tokeny
oth_offsets = [0.05, 0.20, 0.35] # czas i metryki
# --- Słupki tokenów (lewa oś Y) ---
bars_tokens = []
vals_tokens = [
("Łączne tokeny wejściowe", df["łączna ilość tokenów wejściowych"].values),
("Łączne tokeny wyjściowe", df["łączna ilość tokenów wyjściowych"].values),
]
for (label, vals), dx in zip(vals_tokens, tok_offsets):
b = ax1.bar(x + dx, vals, width=bar_w, label=label)
bars_tokens.append(b)
ax1.set_ylabel("Tokeny")
ax1.tick_params(axis="y")
# --- Słupki metryk jakości/czasu (prawa oś Y) ---
ax2 = ax1.twinx()
bars_other = []
vals_other = [
("Czas przetwarzania [s]", df["czas przetwarzania [s]"].values),
("Średnia wartość metryki completeness", df["średnia wartość metryki completeness"].values),
("Średnia wartość metryki faithfulness", df["średnia wartość metryki faithfulness"].values),
]
for (label, vals), dx in zip(vals_other, oth_offsets):
b = ax2.bar(x + dx, vals, width=bar_w, label=label, alpha=0.8)
bars_other.append(b)
ax2.set_ylabel("Czas (s) / Oceny")
# --- Opisy wartości na słupkach ---
def annotate_bars(ax, bars, fmt_big=False):
for barc in bars:
for bar in barc:
v = bar.get_height()
if np.isfinite(v):
if fmt_big and v >= 1000:
txt = f"{int(round(v))}"
else:
txt = f"{v:.1f}"
ax.text(
bar.get_x() + bar.get_width() / 2,
v,
txt,
ha="center",
va="bottom",
fontsize=13,
rotation=0, # poziomo
)
annotate_bars(ax1, bars_tokens, fmt_big=True)
annotate_bars(ax2, bars_other, fmt_big=False)
# --- Oś X, tytuł ---
plt.xticks(x, scenarios, rotation=15)
plt.title("")
# --- Legenda w prawym górnym rogu ---
handles1, labels1 = ax1.get_legend_handles_labels()
handles2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(handles1 + handles2, labels1 + labels2, loc="upper right", frameon=True)
plt.tight_layout()
# --- Zapis wykresu ---
plt.savefig("retrieve_vs_not_in_pl.png", dpi=300)
plt.show()