<commit_before>import os

import numpy as np
from keras.callbacks import Callback, TensorBoard, EarlyStopping, ModelCheckpoint

NONE = 'O'


def get_callbacks(log_dir=None, save_dir=None, valid=()):
    callbacks = []

    if log_dir:
        if not os.path.exists(log_dir):
            print('Successfully made a directory: {}'.format(log_dir))
            os.mkdir(log_dir)
        callbacks.append(TensorBoard(log_dir))

    if valid:
        callbacks.append(F1score(*valid))

    if save_dir:
        if not os.path.exists(save_dir):
            print('Successfully made a directory: {}'.format(save_dir))
            os.mkdir(save_dir)

        file_name = '_'.join(['model_weights', '{epoch:02d}', '{f1:.2f}']) + '.h5'
        save_callback = ModelCheckpoint(os.path.join(save_dir, file_name),
                                        save_weights_only=True)
        callbacks += [save_callback]

    return callbacks<commit_msg>add EarlyStopping to callbacks<commit_after>import os

import numpy as np
from keras.callbacks import Callback, TensorBoard, EarlyStopping, ModelCheckpoint

NONE = 'O'


def get_callbacks(log_dir=None, save_dir=None, valid=(), eary_stopping=True):
    callbacks = []

    if log_dir:
        if not os.path.exists(log_dir):
            print('Successfully made a directory: {}'.format(log_dir))
            os.mkdir(log_dir)
        callbacks.append(TensorBoard(log_dir))

    if valid:
        callbacks.append(F1score(*valid))

    if save_dir:
        if not os.path.exists(save_dir):
            print('Successfully made a directory: {}'.format(save_dir))
            os.mkdir(save_dir)

        file_name = '_'.join(['model_weights', '{epoch:02d}', '{f1:.2f}']) + '.h5'
        save_callback = ModelCheckpoint(os.path.join(save_dir, file_name),
                                        monitor='f1',
                                        save_weights_only=True)
        callbacks.append(save_callback)

    if eary_stopping:
        callbacks.append(EarlyStopping(monitor='f1'))

    return callbacks
{'fraction_non_alphanumeric': 0.11856932876041157, 'fraction_numerical': 0.006859382655560999, 'mean_word_length': 2.5824561403508772, '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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6161124', 'n_tokens_mistral': 638, 'n_tokens_neox': 619, 'n_words': 124}