(self, x_input, x_target, x_length, z=None,
                          c_input=None)
return r_loss, metric_map, decode_results
Reconstruction loss calculation.

    Args:
      x_input: Batch of decoder input sequences for teacher forcing, sized
        `[batch_size, max(x_length), output_depth]`.
      x_target: Batch of expected output sequences to compute loss against,
        sized `[batch_size, max(x_length), output_depth]`.
      x_length: Length of input/output sequences, sized `[batch_size]`.
      z: (Optional) Latent vectors. Required if model is conditional. Sized
        `[n, z_size]`.
      c_input: (Optional) Batch of control sequences, sized
          `[batch_size, max(x_length), control_depth]`. Required if conditioning
          on control sequences.

    Returns:
      r_loss: The reconstruction loss for each sequence in the batch.
      metric_map: Map from metric name to tf.metrics return values for logging.
      decode_results: The LstmDecodeResults.
Reconstruction loss calculation.
Reconstruction loss calculation .
def reconstruction_loss(self, x_input, x_target, x_length, z=None,
                          c_input=None):
    """Reconstruction loss calculation.

    Args:
      x_input: Batch of decoder input sequences for teacher forcing, sized
        `[batch_size, max(x_length), output_depth]`.
      x_target: Batch of expected output sequences to compute loss against,
        sized `[batch_size, max(x_length), output_depth]`.
      x_length: Length of input/output sequences, sized `[batch_size]`.
      z: (Optional) Latent vectors. Required if model is conditional. Sized
        `[n, z_size]`.
      c_input: (Optional) Batch of control sequences, sized
          `[batch_size, max(x_length), control_depth]`. Required if conditioning
          on control sequences.

    Returns:
      r_loss: The reconstruction loss for each sequence in the batch.
      metric_map: Map from metric name to tf.metrics return values for logging.
      decode_results: The LstmDecodeResults.
    """
    batch_size = int(x_input.shape[0])

    has_z = z is not None
    z = tf.zeros([batch_size, 0]) if z is None else z
    repeated_z = tf.tile(
        tf.expand_dims(z, axis=1), [1, tf.shape(x_input)[1], 1])

    has_control = c_input is not None
    if c_input is None:
      c_input = tf.zeros([batch_size, tf.shape(x_input)[1], 0])

    sampling_probability_static = tf.get_static_value(
        self._sampling_probability)
    if sampling_probability_static == 0.0:
      # Use teacher forcing.
      x_input = tf.concat([x_input, repeated_z, c_input], axis=2)
      helper = contrib_seq2seq.TrainingHelper(x_input, x_length)
    else:
      # Use scheduled sampling.
      if has_z or has_control:
        auxiliary_inputs = tf.zeros([batch_size, tf.shape(x_input)[1], 0])
        if has_z:
          auxiliary_inputs = tf.concat([auxiliary_inputs, repeated_z], axis=2)
        if has_control:
          auxiliary_inputs = tf.concat([auxiliary_inputs, c_input], axis=2)
      else:
        auxiliary_inputs = None
      helper = contrib_seq2seq.ScheduledOutputTrainingHelper(
          inputs=x_input,
          sequence_length=x_length,
          auxiliary_inputs=auxiliary_inputs,
          sampling_probability=self._sampling_probability,
          next_inputs_fn=self._sample)

    decode_results = self._decode(
        z, helper=helper, input_shape=helper.inputs.shape[2:])
    flat_x_target = flatten_maybe_padded_sequences(x_target, x_length)
    flat_rnn_output = flatten_maybe_padded_sequences(
        decode_results.rnn_output, x_length)
    r_loss, metric_map = self._flat_reconstruction_loss(
        flat_x_target, flat_rnn_output)

    # Sum loss over sequences.
    cum_x_len = tf.concat([(0,), tf.cumsum(x_length)], axis=0)
    r_losses = []
    for i in range(batch_size):
      b, e = cum_x_len[i], cum_x_len[i + 1]
      r_losses.append(tf.reduce_sum(r_loss[b:e]))
    r_loss = tf.stack(r_losses)

    return r_loss, metric_map, decode_results
def reconstruction_loss ( self , x_input , x_target , x_length , z = None , c_input = None ) : batch_size = int ( x_input . shape [ 0 ] ) has_z = z is not None z = tf . zeros ( [ batch_size , 0 ] ) if z is None else z repeated_z = tf . tile ( tf . expand_dims ( z , axis = 1 ) , [ 1 , tf . shape ( x_input ) [ 1 ] , 1 ] ) has_control = c_input is not None if c_input is None : c_input = tf . zeros ( [ batch_size , tf . shape ( x_input ) [ 1 ] , 0 ] ) sampling_probability_static = tf . get_static_value ( self . _sampling_probability ) if sampling_probability_static == 0.0 : # Use teacher forcing. x_input = tf . concat ( [ x_input , repeated_z , c_input ] , axis = 2 ) helper = contrib_seq2seq . TrainingHelper ( x_input , x_length ) else : # Use scheduled sampling. if has_z or has_control : auxiliary_inputs = tf . zeros ( [ batch_size , tf . shape ( x_input ) [ 1 ] , 0 ] ) if has_z : auxiliary_inputs = tf . concat ( [ auxiliary_inputs , repeated_z ] , axis = 2 ) if has_control : auxiliary_inputs = tf . concat ( [ auxiliary_inputs , c_input ] , axis = 2 ) else : auxiliary_inputs = None helper = contrib_seq2seq . ScheduledOutputTrainingHelper ( inputs = x_input , sequence_length = x_length , auxiliary_inputs = auxiliary_inputs , sampling_probability = self . _sampling_probability , next_inputs_fn = self . _sample ) decode_results = self . _decode ( z , helper = helper , input_shape = helper . inputs . shape [ 2 : ] ) flat_x_target = flatten_maybe_padded_sequences ( x_target , x_length ) flat_rnn_output = flatten_maybe_padded_sequences ( decode_results . rnn_output , x_length ) r_loss , metric_map = self . _flat_reconstruction_loss ( flat_x_target , flat_rnn_output ) # Sum loss over sequences. cum_x_len = tf . concat ( [ ( 0 , ) , tf . cumsum ( x_length ) ] , axis = 0 ) r_losses = [ ] for i in range ( batch_size ) : b , e = cum_x_len [ i ] , cum_x_len [ i + 1 ] r_losses . append ( tf . reduce_sum ( r_loss [ b : e ] ) ) r_loss = tf . stack ( r_losses ) return r_loss , metric_map , decode_results