After we have trained the model, we will use its parameters to translate some sentences from Spanish to English. Let's create a new file called predict.py and write our prediction code there. The logic will work as follows:
- Define exactly the same sequence-to-sequence model architecture as used during training
- Use the already trained weights and biases to produce an output
- Encode a set of Spanish sentences, ready for translation
- Predict the final results and print the equivalent English sentences
As you can see, this flow is pretty straightforward:
- To implement it, we first import two Python libraries together with the neural_machine_translation.py file (used for training):
import tensorflow as tf import ...