Test and translate
The code for the translation is in the file test_translator.py
.
We start with some imports and the location of the pre-trained model:
import pickle import sys import numpy as np import tensorflow as tf import data_utils from train_translator import (get_seq2seq_model, path_l1_dict, path_l2_dict, build_dataset) model_dir = "/tmp/translate"
Now, let's create a function to decode the output sequence generated by the RNN. Mind that the sequence is multidimensional, and each dimension corresponds to the probability of that word, therefore we will pick the most likely one. With the help of the reverse dictionary, we can then figure out what was the actual word. Finally, we will trim the markings (padding, start, end of string) and print the output.
In this example, we will decode the first five sentences in the training set, starting from the raw corpora. Feel free to insert new strings or use different corpora:
def decode(): with tf.Session() as sess: model = get_seq2seq_model...