Exercise

Generating English-French translations

Did you know that HSBC bank once spent $10 million on re-branding its slogan, due to a translation mistake?

We will use the trained model to predict the French translation of an English sentence using model.predict(). You will be provided with the trained model (model). This model has been trained for 50 epochs on 100,000 sentences which achieved around 90% accuracy on a 35000+ word validation set. It might take longer for this exercise to load as the trained model is loaded before the exercise. Furthermore, you will also be provided with a dictionary (fr_id2word) which you can use to convert word indices to words. Finally, you will use the sents2seqs function that you implemented earlier to preprocess the data before feeding it to the model.

You can use help(sents2seqs) to remind yourself what's accepted by the sents2seqs() function.

Instructions

100 XP
  • Preprocess source en_st so that it is converted to a onehot encoded numpy array using the previously defined sents2seqs function.
  • Predict the output for en_seq using the provided trained model.
  • Extract the maximum index for each prediction of fr_pred using np.argmax and assign it to fr_seq.
  • Convert the French sequence IDs to a sentence using list comprehension (remember to ignore 0s) and assign it to fr_sent.