I'm learning tensorflow and want to relate tensorflow implementation with Mathematics.
From my knowledge, mathematical cross entropy requires the sum of its input to be 1. In the following code, y_true
is a valid input while y_pred
is not a Mathematically valid input:
y_true = [[0, 1]]
y_pred = [[1.0, 20.0]]
print(tf.keras.losses.CategoricalCrossentropy(from_logits=False).call(y_true, y_pred))
print(tf.keras.losses.CategoricalCrossentropy(from_logits=True).call(y_true, y_pred))
Gives:
tf.Tensor([0.04879016], shape=(1,), dtype=float32)
tf.Tensor([0.], shape=(1,), dtype=float32)
Please find the gist here.
This answer says:
if from_logits=False, means the input is a probability
This answer says:
from_logits=True
means the input to crossEntropy layer is normal tensor/logits
This answer says:
"Another name for
raw_predictions
in the above code islogit
from_logits
, I guess, means the input is raw_predictions
.
Since my input are not probability, I set from_logits=True
, but the result I get is 0.
Can anyone explain?