2
$\begingroup$

Suppose I have this custom loss:

def custom_loss(y_true, y_pred): out = K.clip(y_pred, 1e-8, 1-1e-8) log_lik = y_true*K.log(out) return K.sum(-log_lik*advantages)

How does keras (with TF as backend) know how to differentiate in terms of the input specifically and ignore the 'advantages' simply as coefficient? Does it do it numerically? If so is that the same as with it's own loss functions or only with custom?

$\endgroup$

1 Answer 1

1
$\begingroup$

keras will differentiate automatically by looking at the graph of operations you use as part of your custom loss function. Since you are using only operations that keras "knows about" aka that exist as operations in TensorFlow keras will automatically a graph of operations to backpropagate against.

If you however have a custom loss function that uses an operation TF doesn't know, you'd have to write a custom operation so that TF knows how to backpropagate against it

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.