'Builds the sentence encoder.
Inputs:
self.encode_emb
self.encode_mask
Outputs:
self.thought_vectors
Raises:
ValueError: if config.bidirectional_encoder is True and config.encoder_dim
is odd.'

def build_encoder(self):

    with tf.variable_scope('encoder') as scope:
        length = tf.to_int32(tf.reduce_sum(self.encode_mask, 1), name='length')
        if self.config.bidirectional_encoder:
            if (self.config.encoder_dim % 2):
                raise ValueError('encoder_dim    must    be    even    when    using    a    bidirectional    encoder.')
            num_units = (self.config.encoder_dim // 2)
            cell_fw = self._initialize_gru_cell(num_units)
            cell_bw = self._initialize_gru_cell(num_units)
            (_, states) = tf.nn.bidirectional_dynamic_rnn(cell_fw=cell_fw, cell_bw=cell_bw, inputs=self.encode_emb, sequence_length=length, dtype=tf.float32, scope=scope)
            thought_vectors = tf.concat(states, 1, name='thought_vectors')
        else:
            cell = self._initialize_gru_cell(self.config.encoder_dim)
            (_, state) = tf.nn.dynamic_rnn(cell=cell, inputs=self.encode_emb, sequence_length=length, dtype=tf.float32, scope=scope)
            thought_vectors = tf.identity(state, name='thought_vectors')
    self.thought_vectors = thought_vectors
