import tensorflow as tf

      log_r = tf.cond(
          tf.less(t + 1, self.max_seq_len),
          lambda: self.tilt(rnn_out, latent_encoded, self.targets_ta.read(t+1)),
          lambda: 0.)
      # On the last step, log_r = 0.
      log_r *= tf.to_float(t < self.seq_lengths - 1)
      weights += log_r - prev_log_r
    new_state = TrainableVRNNState(rnn_state=next_rnn_state,
                                   rnn_out=rnn_out,
                                   latent_encoded=latent_encoded)
