-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_valid_status.py
66 lines (54 loc) · 1.84 KB
/
get_valid_status.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
59
60
61
62
63
64
65
66
import os
import sys
import cPickle
import operator
import matplotlib.pyplot as plt
model_dir = 'models/'
BLEU = 'validation_bleu'
COST = 'validation_cost'
PLOT_BLEU = True
PLOT_COST = False
def get_log(path):
filenames = os.listdir(path)
logs = [f for f in filenames if f.startswith('log')]
if len(logs) == 0:
return None
iterations = [int(l.split('.')[-1]) for l in logs if '.' in l]
if len(iterations) == 0:
return cPickle.load(open(os.path.join(path, logs[0]), 'rb'))
x = max(iterations)
return cPickle.load(open(os.path.join(path, 'log.' + str(x)), 'rb'))
lines = []
names = []
def main():
for model_name in os.listdir(model_dir):
if model_name.endswith('bk'):
continue
model_path = os.path.join(model_dir, model_name)
if not os.path.isdir(model_path):
continue
log = get_log(model_path)
if log is None:
continue
log = sorted(log.items(), key=operator.itemgetter(0))
bleus = [(x, y[BLEU]) for x, y in log if BLEU in y]
costs = [(x, y[COST]) for x, y in log if COST in y]
if len(bleus) == 0:
continue
if PLOT_BLEU:
line, = plt.plot(*zip(*bleus),
linewidth=2.0,
label=model_name + ' bleu',
marker='+')
names.append(model_name + ' bleu')
if PLOT_COST:
line, = plt.plot(*zip(*costs),
linewidth=2.0,
label=model_name + 'cost',
marker='+')
names.append(model_name + ' cost')
lines.append(line)
plt.legend(lines, names, loc=4)
plt.show()
if __name__ == '__main__':
main()