-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotter.py
58 lines (48 loc) · 1.59 KB
/
plotter.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
import argparse
import matplotlib.pyplot as plt
plt.style.use("ggplot")
parser = argparse.ArgumentParser(description="Run the plotter")
parser.add_argument("-ws", "--window-size", type=int, default=1, help="window size for averaging")
args = parser.parse_args()
def sliding_window_average(wsize, data):
avg_data = []
i, j = 0, wsize
temp = sum(data[i:j])
while j < len(data):
avg_data.append(temp/wsize)
temp += (data[j] - data[i])
i, j = i+1, j+1
return avg_data
wsize = args.window_size
losses, bscore, mscore = [], [], []
with open("cleaned_logfile.txt", 'r') as the_file:
for line in the_file.readlines():
if line.startswith("[INFO] Step"):
_, loss, = line.split('|')
_, loss = loss.split(':')
loss = float(loss.strip())
losses.append(loss)
elif line.startswith("Cumulative BLEU4"):
_, score = line.split(':')
bscore.append(float(score.strip()))
elif line.startswith("Cumulative METEOR"):
_, score = line.split(':')
mscore.append(float(score.strip()))
# take a moving window avg of the loss, bscore and mscore
if wsize > 1:
losses = sliding_window_average(wsize, losses)
bscore = sliding_window_average(wsize, bscore)
mscore = sliding_window_average(wsize, mscore)
batches = range(1, len(losses)+1)
plt.plot(batches, losses)
plt.xlabel("steps")
plt.ylabel("loss")
plt.show()
plt.plot(batches, bscore)
plt.xlabel("steps")
plt.ylabel("BLEU4")
plt.show()
plt.plot(batches, mscore)
plt.xlabel("steps")
plt.ylabel("METEOR")
plt.show()