Hi @pragyan , welcome to Discourse,
Looks like you are conflicting the instruction:
Here again, the delightful @tf.function
decorator steps in and saves you time. All you need to do is specify how to compute the cost, and you can do so in one simple step by using:
tf.reduce_mean(tf.keras.losses.binary_crossentropy(y_true = …, y_pred = …, from_logits=True))
with the reference of how it is calculated in TensorFlow:
Just for reference here is how the Binary Cross entropy is calculated in TensorFlow:
mean_reduce(max(logits, 0) - logits * labels + log(1 + exp(-abs(logits))), axis=-1)
For the exercise you should use the former, specifying y_true
and y_pred
.
Below I add some previous comments on the topic that may be of your interest:
Hi kampamocha
Most obliged. I’d added the mean before I read your email, but the key was changing from False to True!
Thank you, Harry
Update: Please note that after this thread was created, the Course Staff made some significant updates to this assignment, which include switching to using CategoricalCrossEntropy for the loss function in this section.
Because we specify the from_logits = True argument, that means that the loss logic will apply either sigmoid or softmax to the logits to compute the actual \hat{y} values and then will compute the cross entropy loss between the predictions and the labels:
-y_true * log(sigmoid(y…
Hello,
While computing cost using tensorflow we are using tf.reduce_mean(tf.keras.losses.binary_crossentropy(y_true = …, y_pred = …, from_logits=True)). And it is mentioned that this is equivalent to mean_reduce(max(logits, 0) - logits * labels + log(1 + exp(-abs(logits))), axis=-1).
But in notes we have learning that binary cross entropy is sum(y_actual *log(y_pred) + (1-y_actual) * log(1-y_pred)
So why is this different cross entropy used and what is significance of this new cost function
2 Likes