<commit_before># Setup

import os
import sys
# import gzip

# import math
# import matplotlib
# matplotlib.use('Agg')

# import matplotlib.pyplot as plt

from tensorflow.keras import backend as K
from tensorflow.keras.optimizers import Adam  # RMSprop, SGD
from tensorflow.keras.callbacks import ModelCheckpoint, CSVLogger, ReduceLROnPlateau, EarlyStopping

file_path = os.path.dirname(os.path.realpath(__file__))
lib_path = os.path.abspath(os.path.join(file_path, '..', '..', 'common'))
sys.path.append(lib_path)

import candle
import smiles_transformer as st


def initialize_parameters(default_model='regress_default_model.txt'):

    # Build benchmark object
    sctBmk = st.BenchmarkST(st.file_path, default_model, 'keras',
                            prog='p1b1_baseline',
                            desc='Multi-task (DNN) for data extraction from clinical reports - Pilot 3 Benchmark 1')

    # Initialize parameters
    gParameters = candle.finalize_parameters(sctBmk)

    return gParameters


# Train and Evaluate

def run(params):

    x_train, y_train, x_val, y_val = st.load_data(params)

    model = st.transformer_model(params)

    model.compile(loss='mean_squared_error',
                  optimizer=Adam(lr=0.00001),
                  metrics=['mae', st.r2])

    # set up a bunch of callbacks to do work during model training..

    checkpointer = ModelCheckpoint(filepath='smile_regress.autosave.model.h5', verbose=1, save_weights_only=True, save_best_only=True)<commit_msg>added optimizer param and set_memory_growth<commit_after># Setup

import os
import sys
# import gzip

# import math
# import matplotlib
# matplotlib.use('Agg')

# import matplotlib.pyplot as plt

from tensorflow.keras import backend as K
import tensorflow.keras.optimizers as optimizers
from tensorflow.keras.callbacks import ModelCheckpoint, CSVLogger, ReduceLROnPlateau, EarlyStopping

file_path = os.path.dirname(os.path.realpath(__file__))
lib_path = os.path.abspath(os.path.join(file_path, '..', '..', 'common'))
sys.path.append(lib_path)

import candle
import smiles_transformer as st

import tensorflow.config.experimental
gpus = tensorflow.config.experimental.list_physical_devices('GPU')
try:
    for gpu in gpus:
        print("setting memory growth")
        tensorflow.config.experimental.set_memory_growth(gpu, True)
except RuntimeError as e:
    print(e)


def initialize_parameters(default_model='regress_default_model.txt'):

    # Build benchmark object
    sctBmk = st.BenchmarkST(st.file_path, default_model, 'keras',
                            prog='p1b1_baseline',
                            desc='Multi-task (DNN) for data extraction from clinical reports - Pilot 3 Benchmark 1')

    # Initialize parameters
    gParameters = candle.finalize_parameters(sctBmk)

    return gParameters


# Train and Evaluate

def run(params):

    x_train, y_train, x_val, y_val = st.load_data(params)

    model = st.transformer_model(params)

    optimizer = optimizers.deserialize({'class_name': params['optimizer'], 'config': {}})

    # I don't know why we set base_lr. It doesn't appear to be used.
    if 'base_lr' in params and params['base_lr'] > 0:
        base_lr = params['base_lr']
    else:
        base_lr = K.get_value(optimizer.lr)

    if 'learning_rate' in params and params['learning_rate'] > 0:
        K.set_value(optimizer.lr, params['learning_rate'])
        print('Done setting optimizer {} learning rate to {}'.format(
            params['optimizer'],params['learning_rate']))

    model.compile(loss='mean_squared_error',
                  optimizer=optimizer,
                  metrics=['mae', st.r2])

    # set up a bunch of callbacks to do work during model training..

    checkpointer = ModelCheckpoint(filepath='smile_regress.autosave.model.h5', verbose=1, save_weights_only=True, save_best_only=True)
{'fraction_non_alphanumeric': 0.10239708181344451, 'fraction_numerical': 0.005732152162584679, 'mean_word_length': 3.704656862745098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3859562', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1182, 'n_words': 284}