Function dfdx::losses::binary_cross_entropy_with_logits_loss
source · [−]pub fn binary_cross_entropy_with_logits_loss<T: Reduce<AllAxes>>(
logits: T,
target_probs: T::NoTape
) -> T::Reduced
Expand description
Binary Cross Entropy With Logits in numerically stable way.
Computes target_probs * log(sigmoid(logits)) + (1 - target_probs) * log(1 - sigmoid(logits))
as (1 - target_probs) * logits + log(1 + exp(-logits))
.
Inputs
logits
- unnormalized inputs. NOT output of sigmoidtarget_probs
- target values between 0 and 1.
Example
let logits = Tensor1D::new([-1.0, -0.5]);
let target_probs = Tensor1D::new([1.0, 0.25]);
let loss = binary_cross_entropy_with_logits_loss(logits.traced(), target_probs);
Numerically Stable Derivation
See https://www.tensorflow.org/api_docs/python/tf/nn/sigmoid_cross_entropy_with_logits for more information on this.