Question: # GRADED CLASS: Encoder class Encoder(tf.keras.layers.Layer): def __init__(self, vocab_size, units): Initializes an instance of this class Args: vocab_size (int): Size of the vocabulary units

# GRADED CLASS: Encoder\ class Encoder(tf.keras.layers.Layer):\ def __init__(self, vocab_size, units):\ """Initializes an instance of this class\ \ Args:\ vocab_size (int): Size of the vocabulary\ units (int): Number of units in the LSTM layer\ """\ super(Encoder, self).__init__()\ \ ### START CODE HERE ###\ \ self.embedding = tf.keras.layers.Embedding( \ input_dim=None,\ output_dim=None,\ mask_zero=None\ ) \ \ self.rnn = tf.keras.layers.Bidirectional( \ merge_mode="sum", \ layer=tf.keras.layers.None(\ units=None,\ return_sequences=None\ ), \ ) \ \ ### END CODE HERE ###\ \ def call(self, context):\ """Forward pass of this layer\ \ Args:\ context (tf.Tensor): The sentence to translate\ \ Returns:\ tf.Tensor: Encoded sentence to translate\ """\ \ ### START CODE HERE ###\ \ # Pass the context through the embedding layer\ x = None\ \ # Pass the output of the embedding through the RNN\ x = None\ \ ### END CODE HERE ###\ \ return x\ \ # Do a quick check of your implementation\ \ # Create an instance of your class\ encoder = Encoder(VOCAB_SIZE, UNITS)\ \ # Pass a batch of sentences to translate from english to portuguese\ encoder_output = encoder(to_translate)\ \ print(f'Tensor of sentences in english has shape: {to_translate.shape}\ ')\ print(f'Encoder output has shape: {encoder_output.shape}')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!