fn
xlogy
→Tensorxlogy(x: Tensor | Scalar, y: Tensor | Scalar)Compute with the convention .
Frequently used to compute cross-entropy losses where the limit must be honored to avoid NaN contamination from probability values that are exactly zero.
Parameters
xTensor | ScalarLeft operand (multiplier).
yTensor | ScalarArgument of the logarithm. Must be non-negative for a real result.
Returns
TensorElement-wise with the zero-times-zero convention applied.
Notes
Mathematical definition:
Gradient with respect to y is ; with respect to x
is . Both are masked to zero wherever x == 0.
Examples
>>> import lucid
>>> x = lucid.tensor([0.0, 1.0, 2.0])
>>> y = lucid.tensor([0.0, 2.0, 3.0])
>>> lucid.xlogy(x, y)
Tensor([0. , 0.6931, 2.1972])