<commit_before>import datetime
import random

import numpy
import time

from keras.callbacks import Callback


def get_file_name():
    """
    :return: Create a filename with current timestamp.
    """
    d = datetime.datetime.now()
    return 'logs/log_%04d-%02d-%02d_%02d-%02d_%d.txt' % (d.year, d.month, d.day, d.hour, d.minute, random.randint(0, 10000))


class LearnLog(Callback):
    """
    Record loss history.
    """
    def __init__(self, name):
        super(LearnLog, self).__init__()
        self.log_file = get_file_name()
        open(self.log_file, 'w').write("# Learn Log: %s Model\n" % name)
        self.loss = 0.0
        self.epoch = 1

    def on_dataset_epoch_begin(self, epoch, logs={}):
        self.loss = 0.0
        self.epoch = epoch

    def on_dataset_epoch_end(self, epoch, logs={}):
        numpy.savetxt(open(self.log_file, 'a'), [[self.epoch, self.loss]], fmt="%g")

    def on_batch_end(self, batch, logs={}):
        self.loss += logs.get('loss')
<commit_msg>Small change in log.txt format<commit_after>import datetime
import random

import numpy
import time

from keras.callbacks import Callback


def get_file_name():
    """
    :return: Create a filename with current timestamp.
    """
    d = datetime.datetime.now()
    return 'logs/log_%04d-%02d-%02d_%02d-%02d_%d.txt' % (d.year, d.month, d.day, d.hour, d.minute, random.randint(0, 10000))


class LearnLog(Callback):
    """
    Record loss history.
    """
    def __init__(self, name):
        super(LearnLog, self).__init__()
        self.log_file = 'logs/' + name.replace(' ', '-') + '.txt'
        d = datetime.datetime.now()
        with open(self.log_file, 'a') as fd:
            fd.write("# Learn Log: %s Model\n" % name)
            fd.write("# Timestamp: %04d-%02d-%02d %02d:%02d\n" % (d.year, d.month, d.day, d.hour, d.minute))
        self.loss = 0.0
        self.epoch = 1

    def on_dataset_epoch_begin(self, epoch, logs={}):
        self.loss = 0.0
        self.epoch = epoch

    def on_dataset_epoch_end(self, epoch, logs={}):
        numpy.savetxt(open(self.log_file, 'a'), [[self.epoch, self.loss]], fmt="%g")

    def on_batch_end(self, batch, logs={}):
        self.loss += logs.get('loss')

{'fraction_non_alphanumeric': 0.16267510167193855, 'fraction_numerical': 0.02349751468594668, 'mean_word_length': 2.804123711340206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6463911', 'n_tokens_mistral': 822, 'n_tokens_neox': 786, 'n_words': 177}