(hparams, is_training)
return sampling_probability
Returns the sampling probability as a tensor based on the hparams.

  Supports three sampling schedules (`hparams.sampling_schedule`):
    constant: `hparams.sampling_rate` is the sampling probability. Must be in
      the interval [0, 1].
    exponential: `hparams.sampling_rate` is the base of the decay exponential.
      Must be in the interval (0, 1). Larger values imply a slower increase in
      sampling.
    inverse_sigmoid: `hparams.sampling_rate` is in the interval [1, inf).
      Larger values imply a slower increase in sampling.

  A constant value of 0 is returned if `hparams.sampling_schedule` is undefined.

  If not training and a non-0 sampling schedule is defined, a constant value of
  1 is returned since this is assumed to be a test/eval job associated with a
  scheduled sampling trainer.

  Args:
    hparams: An HParams object containing model hyperparameters.
    is_training: Whether or not the model is being used for training.

  Raises:
    ValueError: On an invalid `sampling_schedule` or `sampling_rate` hparam.
Returns the sampling probability as a tensor based on the hparams.
Returns the sampling probability as a tensor based on the hparams .
def get_sampling_probability(hparams, is_training):
  """Returns the sampling probability as a tensor based on the hparams.

  Supports three sampling schedules (`hparams.sampling_schedule`):
    constant: `hparams.sampling_rate` is the sampling probability. Must be in
      the interval [0, 1].
    exponential: `hparams.sampling_rate` is the base of the decay exponential.
      Must be in the interval (0, 1). Larger values imply a slower increase in
      sampling.
    inverse_sigmoid: `hparams.sampling_rate` is in the interval [1, inf).
      Larger values imply a slower increase in sampling.

  A constant value of 0 is returned if `hparams.sampling_schedule` is undefined.

  If not training and a non-0 sampling schedule is defined, a constant value of
  1 is returned since this is assumed to be a test/eval job associated with a
  scheduled sampling trainer.

  Args:
    hparams: An HParams object containing model hyperparameters.
    is_training: Whether or not the model is being used for training.

  Raises:
    ValueError: On an invalid `sampling_schedule` or `sampling_rate` hparam.
  """
  if (not hasattr(hparams, 'sampling_schedule') or
      not hparams.sampling_schedule or
      (hparams.sampling_schedule == 'constant' and hparams.sampling_rate == 0)):
    return tf.constant(0.0)

  if not is_training:
    # This is likely an eval/test job associated with a training job using
    # scheduled sampling.
    tf.logging.warning(
        'Setting non-training sampling schedule from %s:%f to constant:1.0.',
        hparams.sampling_schedule, hparams.sampling_rate)
    hparams.sampling_schedule = 'constant'
    hparams.sampling_rate = 1.0

  schedule = hparams.sampling_schedule
  rate = hparams.sampling_rate
  step = tf.to_float(tf.train.get_global_step())

  if schedule == 'constant':
    if not 0 <= rate <= 1:
      raise ValueError(
          '`constant` sampling rate must be in the interval [0, 1]. Got %f.'
          % rate)
    sampling_probability = tf.to_float(rate)
  elif schedule == 'inverse_sigmoid':
    if rate < 1:
      raise ValueError(
          '`inverse_sigmoid` sampling rate must be at least 1. Got %f.' % rate)
    k = tf.to_float(rate)
    sampling_probability = 1.0 - k / (k + tf.exp(step / k))
  elif schedule == 'exponential':
    if not 0 < rate < 1:
      raise ValueError(
          '`exponential` sampling rate must be in the interval (0, 1). Got %f.'
          % hparams.sampling_rate)
    k = tf.to_float(rate)
    sampling_probability = 1.0 - tf.pow(k, step)
  else:
    raise ValueError('Invalid `sampling_schedule`: %s' % schedule)
  tf.summary.scalar('sampling_probability', sampling_probability)
  return sampling_probability
def get_sampling_probability ( hparams , is_training ) : if ( not hasattr ( hparams , 'sampling_schedule' ) or not hparams . sampling_schedule or ( hparams . sampling_schedule == 'constant' and hparams . sampling_rate == 0 ) ) : return tf . constant ( 0.0 ) if not is_training : # This is likely an eval/test job associated with a training job using # scheduled sampling. tf . logging . warning ( 'Setting non-training sampling schedule from %s:%f to constant:1.0.' , hparams . sampling_schedule , hparams . sampling_rate ) hparams . sampling_schedule = 'constant' hparams . sampling_rate = 1.0 schedule = hparams . sampling_schedule rate = hparams . sampling_rate step = tf . to_float ( tf . train . get_global_step ( ) ) if schedule == 'constant' : if not 0 <= rate <= 1 : raise ValueError ( '`constant` sampling rate must be in the interval [0, 1]. Got %f.' % rate ) sampling_probability = tf . to_float ( rate ) elif schedule == 'inverse_sigmoid' : if rate < 1 : raise ValueError ( '`inverse_sigmoid` sampling rate must be at least 1. Got %f.' % rate ) k = tf . to_float ( rate ) sampling_probability = 1.0 - k / ( k + tf . exp ( step / k ) ) elif schedule == 'exponential' : if not 0 < rate < 1 : raise ValueError ( '`exponential` sampling rate must be in the interval (0, 1). Got %f.' % hparams . sampling_rate ) k = tf . to_float ( rate ) sampling_probability = 1.0 - tf . pow ( k , step ) else : raise ValueError ( 'Invalid `sampling_schedule`: %s' % schedule ) tf . summary . scalar ( 'sampling_probability' , sampling_probability ) return sampling_probability