Predicting the translation

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: 

  1. 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  ...

Get Recurrent Neural Networks with Python Quick Start Guide 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.