Skip to content

MaskedBinaryCrossEntropy

Source code

Bases: tf.keras.losses.Loss

Compute Binary Cross-Entropy with masking.

Parameters:

Name Type Description Default
mask_value int

value in y_true to be masked.

None
name str

name of the loss function.

'masked_binary_crossentropy'
reduction str

reduction method for the loss.

'none'

call(y_true, y_pred)

Calculate masked binary cross-entropy.

Define as:

Hp(q)=1Mi=1Nmi(yilog(p(yi))+(1yi)log(1p(yi))) H_p(q) = - \frac{1}{M} \sum_{i=1}^{N} m_i \cdot (y_i \cdot \log(p(y_i)) + (1-y_i) \cdot \log(1-p(y_i)))

where yiy_i is the target, and p(yi)p(y_i) is the prediction mim_i is the mask, and MM is the number of unmasked units.

Warning

"\cdot" is element-wise multiplication.

Parameters:

Name Type Description Default
y_true tf.Tensor

target y with shape (batch_size, seq_len, feature)

required
y_pred tf.Tensor

predicted y with shape (batch_size, seq_len, feature)

required

Returns:

Name Type Description
Loss tf.Tensor

Loss values with shape (batch_size)