Inference

We will load the model from the checkpoint file and test the translation on the set of sample data:

with tf.Session(graph=loaded_graph) as sess:    loader = tf.train.import_meta_graph(checkpoint + '.meta')    loader.restore(sess, checkpoint)    input_data = loaded_graph.get_tensor_by_name('input_data:0')    logits = loaded_graph.get_tensor_by_name('predictions:0')    fr_length = loaded_graph.get_tensor_by_name('fr_len:0')    en_length = loaded_graph.get_tensor_by_name('en_len:0')    dropout_prob = loaded_graph.get_tensor_by_name('dropout_probs:0')    result_logits = sess.run(logits, {input_data: [fr_text]*batch_size,                     en_length: [len(fr_text)],                     fr_length: [len(fr_text)]*batch_size,                    dropout_prob: 1.0})[0]pad = en_word2int[TOKEN_PAD] print('\nFrench Text') ...

Get Hands-On Natural Language Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.