0 points

python - Custom loss in Keras - slow at compiling and fit - Stack Overflow


dashboard

Sun Jun 21 2020 20:14:12 GMT+0000 (UTC)

Posted by @SwarleyBL #python

def mlm_loss(y_true, y_pred):
loss=float(0)
a = tf.keras.backend.constant(1, dtype='float32')
for s in range(batch_size): # for each sample in batch
    for i in range(L):
        for j in range(L):
            loss=loss + y_true[s][i]*(a-y_true[s][j])*(a-(y_pred[s][i]-y_pred[s][j])) #two conditions
l= tf.keras.backend.constant(L, dtype='float32')            
loss=a/l*loss           
return loss
content_copy Copy

https://stackoverflow.com/questions/62498842/custom-loss-in-keras-slow-at-compiling-and-fit