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 pickleimport sysimport numpy as npimport tensorflow as tfimport data_utilsfrom 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 ...