File size: 1,848 Bytes
a2bd61d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Plot every saved epoch and temperature candidate without opening a GUI."""

import json
from pathlib import Path
import matplotlib

matplotlib.use("Agg")
import matplotlib.pyplot as plt

r = Path(__file__).resolve().parent
trace = json.loads((r / "run-001/trace.json").read_text())
cal = json.loads((r / "run-001/calibration.json").read_text())
fig, axes = plt.subplots(1, 2, figsize=(11, 4.4), layout="constrained")
axes[0].plot(
    [x["epoch"] for x in trace],
    [x["train_epoch_end_nll"] for x in trace],
    label="Train, epoch end",
    color="#335f9c",
)
axes[0].plot(
    [x["epoch"] for x in trace],
    [x["validation_nll"] for x in trace],
    label="Validation",
    color="#ad5b26",
)
axes[0].axvline(
    cal["selected_epoch"],
    color="#566358",
    ls="--",
    label=f"Selected epoch {cal['selected_epoch']}",
)
axes[0].set(
    xlabel="Epoch (all 30 retained)",
    ylabel="Uncalibrated cross-entropy / NLL",
    ylim=(0, None),
    title="One CPU fit, fixed configuration",
)
axes[0].legend(fontsize=9)
grid = cal["temperature_grid"]
axes[1].plot(
    [x["temperature"] for x in grid],
    [x["validation_nll"] for x in grid],
    marker="o",
    color="#335f9c",
)
selected = next(x for x in grid if x["temperature"] == cal["selected_temperature"])
axes[1].scatter(
    [selected["temperature"]],
    [selected["validation_nll"]],
    s=80,
    color="#ad5b26",
    label=f"Selected T={selected['temperature']}",
    zorder=4,
)
axes[1].set(
    xlabel="Temperature (fixed finite grid)",
    ylabel="Validation NLL",
    ylim=(0, None),
    title="Selected float model, validation only",
)
axes[1].legend(fontsize=9)
for ax in axes:
    ax.grid(alpha=0.2)
fig.suptitle(
    "Tiny Hash Intent · BANKING77 · 8,998 fit / 1,005 validation rows", fontsize=12
)
fig.savefig(r / "training-curves.png", dpi=170)
plt.close(fig)