17 lines
633 B
Python
17 lines
633 B
Python
|
|
import os
|
||
|
|
|
||
|
|
class Log:
|
||
|
|
def __init__(self, path):
|
||
|
|
self.path = path
|
||
|
|
header = ["avg_txt","avg_enc","avg_dec","txt_loss","masking_loss","prediction_loss"]
|
||
|
|
|
||
|
|
with open(self.path, "w", encoding="utf-8", newline="") as f:
|
||
|
|
f.write(",".join(header) + "\n")
|
||
|
|
|
||
|
|
def write(self, loss: list[float]):
|
||
|
|
line = ",".join(str(float(x)) for x in loss) + "\n"
|
||
|
|
with open(self.path, "a", encoding="utf-8", newline="") as f:
|
||
|
|
f.write(line)
|
||
|
|
f.flush()
|
||
|
|
os.fsync(f.fileno()) # extra durability per write # suggested against sudden crashes since it will be done
|