-
Notifications
You must be signed in to change notification settings - Fork 10
/
parse_t2t_log.py
29 lines (24 loc) · 990 Bytes
/
parse_t2t_log.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
import re
train_loss = {}
validation_loss = {}
number_regex = r'(-?[0-9]+.?[0-9]*e?E?.?[0-9]*)'
with open('transformer-training-logs.txt') as f:
lines = f.readlines()
for line in lines:
if "loss" in line:
if "global_step" in line:
# evaluation
found = re.search('global_step = {}, loss = {},'.format(number_regex, number_regex), line)
if found:
step = int(found.group(1))
loss = float(found.group(2))
validation_loss[step] = loss
else:
# training
found = re.search('loss = {}, step = {} '.format(number_regex, number_regex), line)
if found:
loss = float(found.group(1))
step = int(found.group(2))
train_loss[step] = loss
print("train_loss:", sorted(train_loss.items()))
print("validation_loss:", sorted(validation_loss.items()))