-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_to_traininfo.py
58 lines (46 loc) · 1.66 KB
/
log_to_traininfo.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 sys
from docopt import docopt
def main():
args = docopt("""Create a .traininfo for visualizing learning from the logs.
Usage:
log_to_traininfo.py <logfile> <trainfile>
<logfile> = output from training
<trainfile> = resulting .traininfo file
""")
# after seeing 32 samples:
# Accuracy on train data: 0.3326810674831215
# Accuracy on dev data: 0.3286933550091445
# mean loss 1.098198413848877
key_number_samples = 'after seeing'
key_train_data = 'Accuracy on train data'
key_dev_data = 'Accuracy on dev data'
key_loss = 'mean loss'
file = args['<logfile>']
file_out = args['<trainfile>']
amounts = []
acc_train = []
acc_dev = []
mean_loss = []
with open(file) as f_in:
for line in f_in:
if line.startswith(key_number_samples):
amounts.append(line.split(' ')[2].strip())
elif line.startswith(key_train_data):
acc_train.append(line.split(' ')[-1].strip())
elif line.startswith(key_dev_data):
acc_dev.append(line.split(' ')[-1].strip())
elif line.startswith(key_loss):
mean_loss.append(line.split(' ')[-1].strip())
# else ignore
if not file_out.endswith('.traininfo'):
file_out += '.traininfo'
with open(file_out, 'w') as f_out:
f_out.write(file.split('.')[0] + '\n')
f_out.write('\n')
f_out.write(' '.join(amounts) + '\n')
f_out.write(' '.join(acc_train) + '\n')
f_out.write(' '.join(acc_dev) + '\n')
f_out.write(' '.join(mean_loss) + '\n')
print('Done.')
if __name__ == '__main__':
main()