Next, we will look at the sequence to sequence high-level function that wraps all of this together. This takes the word embeddings of the input text sentence, creates the encoding/decoding layer, and produces the logits as output. The op_tr and op_inf objects represent the predictions during training and inference, respectively:
def seq2seq_model(data_inp, data_summ_tgt, dprob, len_txt, len_summ, max_len_summ,
v_size, rnsize, nlyrs, word2int, batch_size):
inp_emb = word_emb_matrix
word_embs = tf.Variable(inp_emb, name="word_embs")
inp_enc_emb = tf.nn.embedding_lookup(word_embs, data_inp)
op_enc, st_enc = encoding_layer(rnsize, len_txt, nlyrs, inp_enc_emb, dprob)
inp_dec = process_encoding_input(data_summ_tgt, word2int, batch_size)
inp_dec_emb = tf.nn.embedding_lookup(inp_emb, inp_dec)
op_tr, op_inf = decoding_layer(inp_dec_emb,
inp_emb,
op_enc,
st_enc,
v_size,
len_txt,
len_summ,
max_len_summ,
rnsize,
word2int,
dprob,
batch_size,
nlyrs)
return op_tr, op_inf
The output training logits, op_tr, is used (along with the ground truth summary) to compute the cost during training.
We will now look at building the graph.