def noisy_inputs(self) -> tf.Tensor:
"""
Return the input sequence, with noise added according to the `input_noise` parameter.
If the `input_noise` parameter is not set, this method simply returns the input sequence. Otherwise, return a
tensor in which each time step of the input sequence is randomly set to zeros with probability given by the
`input_noise` parameter.
Returns
-------
tf.Tensor
The input sequence, with noise added according to the `input_noise` parameter
"""
if self.input_noise is None:
return self.inputs
# drop entire time steps with probability self.noise
randoms = tf.random_uniform([self.max_step, self.batch_size], minval=0, maxval=1)
randoms = tf.stack([randoms] * self.num_features, axis=2)
result = tf.where(randoms > self.input_noise, self.inputs, tf.zeros_like(self.inputs))
return result
评论列表
文章目录