예제 #1
0
    def decode_layer(self, input_, dilation, layer_no):
        options = self.options

        # Input dimension
        in_dim = input_.get_shape().as_list()[-1]

        # Reduce dimension
        relu1 = tf.nn.relu(input_, name='dec_relu1_layer{}'.format(layer_no))
        conv1 = ops.conv1d(relu1,
                           in_dim / 2,
                           name='dec_conv1d_1_layer{}'.format(layer_no))

        # 1 x k dilated convolution
        relu2 = tf.nn.relu(conv1, name='enc_relu2_layer{}'.format(layer_no))
        dilated_conv = ops.dilated_conv1d(
            relu2,
            output_channels=in_dim / 2,
            dilation=dilation,
            filter_width=options['decoder_filter_width'],
            causal=True,
            name="dec_dilated_conv_layer{}".format(layer_no))

        # Restore dimension
        relu3 = tf.nn.relu(dilated_conv,
                           name='dec_relu3_layer{}'.format(layer_no))
        conv2 = ops.conv1d(relu3,
                           in_dim,
                           name='dec_conv1d_2_layer{}'.format(layer_no))

        # Residual connection
        return input_ + conv2
예제 #2
0
 def encode_layer(self, input_, dilation, layer_no, last_layer=False):
     options = self.options
     relu1 = tf.nn.relu(input_, name='enc_relu1_layer{}'.format(layer_no))
     conv1 = ops.conv1d(relu1,
                        options['residual_channels'],
                        name='enc_conv1d_1_layer{}'.format(layer_no))
     conv1 = tf.matmul(conv1, self.source_masked_d)
     relu2 = tf.nn.relu(conv1, name='enc_relu2_layer{}'.format(layer_no))
     dilated_conv = ops.dilated_conv1d(
         relu2,
         options['residual_channels'],
         dilation,
         options['encoder_filter_width'],
         causal=False,
         name="enc_dilated_conv_layer{}".format(layer_no))
     dilated_conv = tf.matmul(dilated_conv, self.source_masked_d)
     relu3 = tf.nn.relu(dilated_conv,
                        name='enc_relu3_layer{}'.format(layer_no))
     conv2 = ops.conv1d(relu3,
                        2 * options['residual_channels'],
                        name='enc_conv1d_2_layer{}'.format(layer_no))
     return input_ + conv2
예제 #3
0
    def decode_layer(self, input_, dilation, layer_no):
        options = self.options
        relu1 = tf.nn.relu(input_, name='dec_relu1_layer{}'.format(layer_no))
        conv1 = ops.conv1d(relu1,
                           options['residual_channels'],
                           name='dec_conv1d_1_layer{}'.format(layer_no))

        relu2 = tf.nn.relu(conv1, name='enc_relu2_layer{}'.format(layer_no))
        dilated_conv = ops.dilated_conv1d(
            relu2,
            options['residual_channels'],
            dilation,
            options['decoder_filter_width'],
            causal=True,
            name="dec_dilated_conv_laye{}".format(layer_no))

        relu3 = tf.nn.relu(dilated_conv,
                           name='dec_relu3_layer{}'.format(layer_no))
        conv2 = ops.conv1d(relu3,
                           2 * options['residual_channels'],
                           name='dec_conv1d_2_layer{}'.format(layer_no))

        return input_ + conv2
예제 #4
0
    def decoder(self, input_, encoder_embedding=None):
        options = self.options
        curr_input = input_
        if encoder_embedding is not None:
            # CONDITION WITH ENCODER EMBEDDING FOR THE TRANSLATION MODEL
            curr_input = tf.concat(2, [input_, encoder_embedding])
            print("Decoder Input", curr_input)

        for layer_no, dilation in enumerate(options['decoder_dilations']):
            curr_input = self.decode_layer(curr_input, dilation, layer_no)

        processed_output = ops.conv1d(tf.nn.relu(curr_input),
                                      options['n_target_quant'],
                                      name='decoder_post_processing')

        return processed_output
예제 #5
0
    def encoder(self, input_):
        options = self.options
        curr_input = input_
        for layer_no, dilation in enumerate(self.options['encoder_dilations']):
            layer_output = self.encode_layer(curr_input, dilation, layer_no)

            # ENCODE ONLY TILL THE INPUT LENGTH, conditioning should be 0 beyond that
            layer_output = tf.matmul(layer_output,
                                     self.source_masked,
                                     name='layer_{}_output'.format(layer_no))

            curr_input = layer_output

        # TO BE CONCATENATED WITH TARGET EMBEDDING
        processed_output = tf.nn.relu(
            ops.conv1d(tf.nn.relu(layer_output),
                       options['residual_channels'],
                       name='encoder_post_processing'))

        processed_output = tf.matmul(processed_output,
                                     self.source_masked_d,
                                     name='encoder_processed')

        return processed_output