def model_wrapper(): model = Sequential() model.add( Dense( dense_width, input_dim=vector_size, kernel_regularizer=regularizers.l2(regularization), activity_regularizer=regularizers.l1(regularization), activation='relu', )) # add Dense layer with relu activation model.add( Dense( dense_width, kernel_regularizer=regularizers.l2(regularization), activity_regularizer=regularizers.l1(regularization), activation='relu', )) # add Dense layer model.add(Dense(1, activation='sigmoid')) optimizer_fn = _get_optimizer(optimizer, learn_rate_mult) # Compile model model.compile(loss='binary_crossentropy', optimizer=optimizer_fn, metrics=['acc']) if verbose >= 1: model.summary() return model
def model_wrapper(): model = Sequential() # add first embedding layer with pretrained wikipedia weights model.add( Embedding( embedding_matrix.shape[0], embedding_matrix.shape[1], weights=[embedding_matrix], input_length=max_sequence_length, trainable=False ) ) # add LSTM layer model.add( LSTM( lstm_out_width, input_shape=(max_sequence_length, ), go_backwards=backwards, dropout=dropout, recurrent_dropout=dropout, return_sequences=True, kernel_constraint=MaxNorm(), ) ) model.add( MaxPooling1D( pool_size=lstm_pool_size, ) ) model.add( Flatten() ) # Add output layer model.add( Dense( 1, activation='sigmoid' ) ) optimizer_fn = _get_optimizer(optimizer, learn_rate) # Compile model model.compile( loss='binary_crossentropy', optimizer=optimizer_fn, metrics=['acc']) if verbose >= 1: model.summary() return model