NMT example
This exercise aims to build on the sneak peek you got of NMT at the beginning of the course. You will continue to translate Portuguese small phrases into English.
Some sample sentences are available on the sentences
variable and are printed on the console.
Also, a pre-trained model is available on the model
variable and you will use two custom functions to simplify some steps:
encode_sequences()
: Change texts into sequence of numerical indexes and pad them.translate_many()
: Uses the pre-trained model to translate a list of sentences from Portuguese into English. Later you will code this function yourself.
For more details on the functions, use help()
. The package pandas
is loaded as pd
.
This exercise is part of the course
Recurrent Neural Networks (RNNs) for Language Modeling with Keras
Exercise instructions
- Use the
encode_sequences()
function to pre-process the texts and save the results in theX
variable. - Translate the
sentences
using thetranslate_many()
function by passingX
as a parameter. - Create a
pd.DataFrame()
with the original and translated lists as columns. - Print the data frame.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Transform text into sequence of indexes and pad
X = ____(sentences)
# Print the sequences of indexes
print(X)
# Translate the sentences
translated = translate_many(model, ____)
# Create pandas DataFrame with original and translated
df = pd.DataFrame({'Original': ____, 'Translated': ____})
# Print the DataFrame
print(____)