def encode(self, inp, **flags): """ Takes symbolic input sequence, computes initial state :param inp: matrix of input tokens [batch, time] :return: a list of initial decoder state tensors """ inp_lengths = infer_length(inp, self.inp_voc.eos_ix) inp_emb = self.emb_inp(inp) if self.bidirectional: outputs, states = tf.nn.bidirectional_dynamic_rnn( self.enc0, self.enc1, inp_emb, sequence_length=inp_lengths, dtype=inp_emb.dtype) return tf.concat(outputs, 2), tf.concat(states, 1) else: _, enc_last = tf.nn.dynamic_rnn(self.enc0, inp_emb, sequence_length=inp_lengths, dtype=inp_emb.dtype) # dec_start = self.dec_start(enc_last) return _, enc_last
def encode(self, inp, **flags): """ Takes symbolic input sequence, computes initial state and embefings for attention :param inp: matrix of input tokens [batch, time] :return: a list of initial decoder state tensors """ inp_lengths = infer_length(inp, self.inp_voc.eos_ix) inp_emb = self.emb_inp(inp) outputs, final_state = tf.nn.bidirectional_dynamic_rnn( self.encoder_forward_GRU, self.encoder_backward_GRU, inp_emb, sequence_length=inp_lengths, dtype=inp_emb.dtype ) return tf.concat(outputs, 2), tf.concat(final_state, 1)
def encode(self, inp, **flags): """ Takes symbolic input sequence, computes initial state :param inp: matrix of input tokens [batch, time] :return: a list of initial decoder state tensors """ inp_lengths = infer_length(inp, self.inp_voc.eos_ix) inp_emb = self.emb_inp(inp) _, enc_last = tf.nn.dynamic_rnn( self.enc0, inp_emb, sequence_length=inp_lengths, dtype = inp_emb.dtype) dec_start = self.dec_start(enc_last[1]) return [dec_start]