File size: 2,444 Bytes
cdb159e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
import numpy as np
import pandas as pd

import sys

file_path = sys.argv[1] 

metric = {}
stastics = {}

with open(file_path) as input_file:
    current_epoch=None
    for line in input_file:
        line= line.strip()

        if line.find("Bert Model") >-1:
            stastics["Bert Model"] =line
        if line.find("Current date and time") >-1:
            stastics["Current date and time"] =line
        if line.find("Train file") >-1:
            stastics["Train file"] =line
        if line.find("Valid file") >-1:
            stastics["Valid file"] =line
        if line.find("Test file") >-1:
            stastics["Test file"] =line
        if line.find("Train size") >-1:
            stastics["Train size"] =line
        if line.find("Valid size") >-1:
            stastics["Valid size"] =line
        if line.find("Test size") >-1:
            stastics["Test size"] =line
        tokens = line.split()
        for token in tokens:
            if  token.find("epoch")==0:
                metric[token]=[]
                current_epoch=token
                continue
            if  token.find("train_loss")>-1:
                metric[current_epoch].append(token)
            if  token.find("val_loss")>-1:
                metric[current_epoch].append(token)
            if  token.find("test_loss")>-1:
                metric[current_epoch].append(token)
            if  token.find("train_acc")>-1:
                metric[current_epoch].append(token)
            if  token.find("val_acc")>-1:
                metric[current_epoch].append(token)
            if  token.find("test_acc")>-1:
                metric[current_epoch].append(token)
results =[]
for item in metric.items():
    result=[]
    result.append(item[0].replace('epoch=',""))
    for fig in item[1]:
        result.append(fig.split("=")[-1].replace(",",""))
    results.append(result)

for item in stastics.items():
    print(item[0],item[1].split()[-1])

#lets convert that to numpy array as np.array
num = np.array(results)

#now construct a beautiful table
df = pd.DataFrame(num, columns=["EPOCH","Trn loss","Val Acc" ,"Tst loss","Trn Acc","Val loss","Tst Acc"]) #
dash = 62
print("-"*dash)
print("| ".join(df.columns), "|")
for index,row in df.iterrows():
    print("-"*dash)
    print("|",row["EPOCH"]," |", row["Trn loss"]," |", row["Val loss"]," |",row["Tst loss"], " |", row["Trn Acc"]," |",row["Val Acc"],"  |",row["Tst Acc"]," |")
    
print("-"*dash)


#