Aan de slagGa gratis aan de slag

Part 1: Defining the full model

Here you will be implementing the last few layers of the encoder-decoder model. You will be using Dense and TimeDistributed layers to get the final predictions (i.e. predicted French word probabilities) of the encoder-decoder model.

You are provided with the encoder and decoder (without the top-part) you implemented so far. The decoder GRU layer's output de_out is provided. We use the prefix en (e.g. en_gru) to indicate anything encoder related and de to indicate decoder related things (e.g. de_gru).

Deze oefening maakt deel uit van de cursus

Machine Translation with Keras

Cursus bekijken

Oefeninstructies

  • Import Dense and TimeDistributed layers from Keras.
  • Define a Dense layer with softmax activation which has fr_vocab outputs.
  • Wrap the Dense layer in a TimeDistributed layer.
  • Get the final prediction of the model by passing de_out to the de_dense_time layer.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import Dense and TimeDistributed layers
from tensorflow.keras.____ import ____, ____
# Define a softmax dense layer that has fr_vocab outputs
de_dense = ____(____, ____)
# Wrap the dense layer in a TimeDistributed layer
de_dense_time = ____(de_dense)
# Get the final prediction of the model
de_pred = ____(de_out)
print("Prediction shape: ", de_pred.shape)
Code bewerken en uitvoeren