forked from chokkan/crfsuite
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathplot_performance.py
executable file
·44 lines (37 loc) · 1.07 KB
/
plot_performance.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
#!/usr/bin/env python
import sys
import re
re_iteration = re.compile(r'^\*\*\*\*\* (Iteration|Epoch) #(\d+) \*\*\*\*\*')
patterns = {
'loss': re.compile(r'^Loss: ([\d.]+)'),
'accuracy': re.compile(r'^Item accuracy: \d+ / \d+ \(([\d.]+)\)'),
'norm': re.compile(r'^Feature [L2-]+norm: ([\d.]+)'),
}
def read(fi):
D = []
for line in fi:
line = line.strip('\n')
m = re_iteration.match(line)
if m is not None:
if len(D)+1 != int(m.group(2)):
sys.stderr.write('ERROR: sync\n')
sys.exit(1)
D.append({})
continue
if D:
for name, pattern in patterns.iteritems():
m = pattern.match(line)
if m is not None:
D[-1][name] = float(m.group(1))
return D
if __name__ == '__main__':
fi = sys.stdin
fo = sys.stdout
i = 1
D = read(fi)
for item in D:
fo.write('%d' % i)
i += 1
for name in patterns.iterkeys():
fo.write(' %f' % item[name])
fo.write('\n')