'What does self._compute_output_and_mask_jointly = True do in tf.keras.layers.Masking layer?
tf.keras.layers.Masking layer has _compute_output_and_mask_jointly set to True in its __init__(...), what does this attribute do other than telling what it is doing in its call(...)?
def __init__(self, mask_value=0., **kwargs):
...
self._compute_output_and_mask_jointly = True
In addition, the mask has been created and applied in call(...). What is the purpose of compute_mask(...)? Seems redundant.
def compute_mask(self, inputs, mask=None):
return tf.reduce_any(tf.not_equal(inputs, self.mask_value), axis=-1)
def call(self, inputs):
boolean_mask = tf.reduce_any(
tf.not_equal(inputs, self.mask_value), axis=-1, keepdims=True)
outputs = inputs * tf.cast(boolean_mask, inputs.dtype)
# Compute the mask and outputs simultaneously.
outputs._keras_mask = tf.squeeze(boolean_mask, axis=-1) # pylint: disable=protected-access
return outputs
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
