38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
import re
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
|
|
text = r"""
|
|
"""
|
|
|
|
pattern = re.compile(r"step=\s*(\d+)\s+loss=([0-9.]+)\s+acc=([0-9.]+)")
|
|
rows = [(int(s), float(l), float(a)) for s, l, a in pattern.findall(text)]
|
|
df = pd.DataFrame(rows, columns=["step", "loss", "acc"]).sort_values("step").reset_index(drop=True)
|
|
|
|
# Avoid log(0) issues for loss plot by clamping at a tiny positive value
|
|
eps = 1e-10
|
|
df["loss_clamped"] = df["loss"].clip(lower=eps)
|
|
|
|
# Plot 1: Loss
|
|
plt.figure(figsize=(9, 4.8))
|
|
plt.plot(df["step"], df["loss_clamped"])
|
|
plt.yscale("log")
|
|
plt.xlabel("Step")
|
|
plt.ylabel("Loss (log scale)")
|
|
plt.title("Training Loss vs Step")
|
|
plt.tight_layout()
|
|
plt.savefig('./files/training_loss_v_step.png')
|
|
plt.show()
|
|
|
|
# Plot 2: Accuracy
|
|
df["err"] = (1.0 - df["acc"]).clip(lower=eps)
|
|
plt.figure(figsize=(9, 4.8))
|
|
plt.plot(df["step"], df["err"])
|
|
plt.yscale("log")
|
|
plt.xlabel("Step")
|
|
plt.ylabel("Error rate (1 - accuracy) (log scale)")
|
|
plt.title("Training Error Rate vs Step")
|
|
plt.tight_layout()
|
|
plt.savefig('./files/training_error_v_step.png')
|
|
plt.show()
|