- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplotter.py
More file actions
Latest commit
58 lines (48 loc) · 1.59 KB
/
Copy pathplotter.py
File metadata and controls
58 lines (48 loc) · 1.59 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
importargparse
importmatplotlib.pyplotasplt
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()
defsliding_window_average(wsize, data):
avg_data= []
i, j=0, wsize
temp=sum(data[i:j])
whilej<len(data):
avg_data.append(temp/wsize)
temp+= (data[j] -data[i])
i, j=i+1, j+1
returnavg_data
wsize=args.window_size
losses, bscore, mscore= [], [], []
withopen("cleaned_logfile.txt", 'r') asthe_file:
forlineinthe_file.readlines():
ifline.startswith("[INFO] Step"):
_, loss, =line.split('|')
_, loss=loss.split(':')
loss=float(loss.strip())
losses.append(loss)
elifline.startswith("Cumulative BLEU4"):
_, score=line.split(':')
bscore.append(float(score.strip()))
elifline.startswith("Cumulative METEOR"):
_, score=line.split(':')
mscore.append(float(score.strip()))
# take a moving window avg of the loss, bscore and mscore
ifwsize>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()