(self, fw_st, bw_st)
Add to the graph a linear layer to reduce the encoder's final FW and BW state into a single initial state for the decoder. This is needed because the encoder is bidirectional but the decoder is not.

    Args:
      fw_st: LSTMStateTuple with hidden_dim units.
      bw_st: LSTMStateTuple with hidden_dim units.

    Returns:
      state: LSTMStateTuple with hidden_dim units.
Add to the graph a linear layer to reduce the encoder's final FW and BW state into a single initial state for the decoder. This is needed because the encoder is bidirectional but the decoder is not.
Add to the graph a linear layer to reduce the encoder s final FW and BW state into a single initial state for the decoder . This is needed because the encoder is bidirectional but the decoder is not .
def _reduce_states(self, fw_st, bw_st):
    """Add to the graph a linear layer to reduce the encoder's final FW and BW state into a single initial state for the decoder. This is needed because the encoder is bidirectional but the decoder is not.

    Args:
      fw_st: LSTMStateTuple with hidden_dim units.
      bw_st: LSTMStateTuple with hidden_dim units.

    Returns:
      state: LSTMStateTuple with hidden_dim units.
    """
    hidden_dim = self._hps.hidden_dim
    with tf.variable_scope('reduce_final_st'):

      # Define weights and biases to reduce the cell and reduce the state
      w_reduce_c = tf.get_variable('w_reduce_c', [hidden_dim * 2, hidden_dim], dtype=tf.float32, initializer=self.trunc_norm_init)
      w_reduce_h = tf.get_variable('w_reduce_h', [hidden_dim * 2, hidden_dim], dtype=tf.float32, initializer=self.trunc_norm_init)
      bias_reduce_c = tf.get_variable('bias_reduce_c', [hidden_dim], dtype=tf.float32, initializer=self.trunc_norm_init)
      bias_reduce_h = tf.get_variable('bias_reduce_h', [hidden_dim], dtype=tf.float32, initializer=self.trunc_norm_init)

      # Apply linear layer
      old_c = tf.concat(axis=1, values=[fw_st.c, bw_st.c]) # Concatenation of fw and bw cell
      old_h = tf.concat(axis=1, values=[fw_st.h, bw_st.h]) # Concatenation of fw and bw state
      new_c = tf.nn.relu(tf.matmul(old_c, w_reduce_c) + bias_reduce_c) # Get new cell from old cell
      new_h = tf.nn.relu(tf.matmul(old_h, w_reduce_h) + bias_reduce_h) # Get new state from old state
      return tf.contrib.rnn.LSTMStateTuple(new_c, new_h)
def _reduce_states ( self , fw_st , bw_st ) : hidden_dim = self . _hps . hidden_dim with tf . variable_scope ( 'reduce_final_st' ) : # Define weights and biases to reduce the cell and reduce the state w_reduce_c = tf . get_variable ( 'w_reduce_c' , [ hidden_dim * 2 , hidden_dim ] , dtype = tf . float32 , initializer = self . trunc_norm_init ) w_reduce_h = tf . get_variable ( 'w_reduce_h' , [ hidden_dim * 2 , hidden_dim ] , dtype = tf . float32 , initializer = self . trunc_norm_init ) bias_reduce_c = tf . get_variable ( 'bias_reduce_c' , [ hidden_dim ] , dtype = tf . float32 , initializer = self . trunc_norm_init ) bias_reduce_h = tf . get_variable ( 'bias_reduce_h' , [ hidden_dim ] , dtype = tf . float32 , initializer = self . trunc_norm_init ) # Apply linear layer old_c = tf . concat ( axis = 1 , values = [ fw_st . c , bw_st . c ] ) # Concatenation of fw and bw cell old_h = tf . concat ( axis = 1 , values = [ fw_st . h , bw_st . h ] ) # Concatenation of fw and bw state new_c = tf . nn . relu ( tf . matmul ( old_c , w_reduce_c ) + bias_reduce_c ) # Get new cell from old cell new_h = tf . nn . relu ( tf . matmul ( old_h , w_reduce_h ) + bias_reduce_h ) # Get new state from old state return tf . contrib . rnn . LSTMStateTuple ( new_c , new_h )