I am training a neural network with concrete dropout with the weighted negative log-likelihood as a loss function.
#!pip install concretedropout
from concretedropout.tensorflow import ConcreteDenseDropout, get_weight_regularizer, get_dropout_regularizer
def create_concrete_dropout_bnn_model(train_size):
Ns = X_train.shape[0]
wr = get_weight_regularizer(Ns, l=1e-2, tau=1.0)
dr = get_dropout_regularizer(Ns, tau=1.0, cross_entropy_loss=False)
def normal_sp(params):
return tfd.Normal(loc=params[:,0:1], scale=1e-3 + tf.math.softplus(0.05 * params[:,1:2]))
inputs = Input(shape=(1,),name="input layer")
dense1 = Dense(50)
x = dense1(inputs)
x = tf.keras.layers.Activation("relu", name="activation_1")(x)
dense2 = Dense(50)
x = ConcreteDenseDropout(dense2, is_mc_dropout=True, weight_regularizer=wr, dropout_regularizer=dr)(x)
x = tf.keras.layers.Activation("relu", name="activation_2")(x)
dense3 = Dense(50)
x = ConcreteDenseDropout(dense3, is_mc_dropout=True, weight_regularizer=wr, dropout_regularizer=dr)(x)
x = tf.keras.layers.Activation("relu", name="activation_3")(x)
params_mc = Dense(2,activation="relu")(x)
dist_mc = tfp.layers.DistributionLambda(normal_sp, name='normal_sp')(params_mc)
modello = Model(inputs=inputs, outputs=dist_mc)
return modello
optimizer = tf.optimizers.Adam(learning_rate=0.0002)
concrete_dropout_BNN = create_concrete_dropout_bnn_model(train_size=train_size)
concrete_dropout_BNN.compile(optimizer=optimizer,
loss=NLL,loss_weights=pesi_train
)
concrete_dropout_BNN.build((None,1))
history_concrete_dropout_BNN = concrete_dropout_BNN.fit(X_train, y_train, epochs=30000, verbose=0, batch_size=batch_size,validation_data=(X_val,y_val) )
The validation loss after a certain number of epochs reach the level of the training loss which is stuck at around 40 and refuses to go down no matter the number of neurons per layer
if I remove the weights from .compile the loss goes to zero, but I don't understand why they should affect the loss in such a negative way when applied. what does this mean? and what can i do to lower the training/validation loss?
