C4Week1 Encode class #C4W1

While submitting encode (first exercise) I am getting error ‘Encoder’ object has no attribute ‘embedding’. Any ideas?
I am using following code snippet
self.embedding_layer = {code removed by moderator as it is against community guidelines to post codes from grade cell}

Hi @Sanjeev_Jha1

Make sure you run previous cells in your notebook and follow the provided instructions carefully!

If the issue persists, feel free to send your code via private message so we can check for any problems.

Could you share screenshot of the error you are mentioning rather than sharing the codes.

Regards
DP

Hi Deepti,

Below is image of encoder exercise error. While I am getting proper output, running the test gives this error.
![image|690x324](upload://zfHcXynYSxUgZgC2zUQTeCp


SlVT.png)

For exercise 2, getting below error:

For exercise 1 Below error:

Hi @Sanjeev_Jha1

There are probably two issues

  1. First for the embedding layer has not been recalled with right code for mask_zero as per instructions given before the Exercise 1 Grade cell for encoder. See the below instruction and error and make the changes.

For this layer you need to define the appropriate input_dim and output_dim and let it know that you are using ‘0’ as padding, which can be done by using the appropriate value for the mask_zero parameter.

Your error mentions because mask_zero is not equal to zero, caused the error.

  1. Next in the Cross attention grade cell,
    if you notice to create cross attention you are suppose to use tf.keras.layers.MultiheadAttention which I suppose you used, but you didn’t recall this layer as self.mha

then in the same cell, where you forward pass this layer as attn_output, you suppose to use the self.mha recall while defining the cross attention layer, causing this error. I am sharing a screenshot instructions given before the grade cell for cross-attention, where all of these are already given.

Let me know if you need more assistance.

P.S. remember the outputs for this output is very attention to detail, so make sure cross check if your output is exact as expected output.

Regards
DP
Regards
DP

1 Like

Thanks a lot Deepti. It worked with your suggestions.

1 Like