-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathvisualization.py
More file actions
64 lines (51 loc) · 1.8 KB
/
visualization.py
File metadata and controls
64 lines (51 loc) · 1.8 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
import matplotlib.pyplot as plt
from pathlib import Path
from matplotlib.ticker import MaxNLocator, MultipleLocator
def plot_metrics(
train_energies,
val_energies=None,
train_perplexities=None,
val_perplexities=None
):
"""
Plot training and validation metrics.
"""
assets_dir = Path("assets")
assets_dir.mkdir(exist_ok=True)
# Energy Plot
plt.figure(figsize=(10, 5))
epochs = range(1, len(train_energies) + 1)
plt.plot(epochs, train_energies, 'b-', label='Training')
if val_energies:
plt.plot(epochs, val_energies, 'r-', label='Validation')
plt.title('Training/Validation Energy vs. Epochs')
plt.xlabel('Epoch')
plt.ylabel('Energy')
plt.legend()
plt.grid(True)
ax = plt.gca()
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
save_path = assets_dir / 'energy_plot.png'
plt.savefig(save_path)
plt.close()
print(f"Energy plot saved to: {save_path}")
# Perplexity Plot
if train_perplexities is not None:
plt.figure(figsize=(10, 5))
epochs = range(1, len(train_perplexities) + 1)
plt.plot(epochs, train_perplexities, 'b-', label='Training')
if val_perplexities:
plt.plot(epochs, val_perplexities, 'r-', label='Validation')
plt.title('Training/Validation Perplexity vs. Epochs')
plt.xlabel('Epoch')
plt.ylabel('Perplexity')
plt.legend()
plt.grid(True)
ax = plt.gca()
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
if max(train_perplexities) > 100:
ax.yaxis.set_major_locator(MultipleLocator(100))
save_path_ppl = assets_dir / 'perplexity_plot.png'
plt.savefig(save_path_ppl)
plt.close()
print(f"Perplexity plot saved to: {save_path_ppl}")