Confusion over the for loop function call in C5W4A1 EX-7

Hi dear mentors and the DeepLearning.AI team,

I would like to point out a small problem with Exercise 7, in the last coding part inside the for loop.


This is how the notebook appeared for me at the time of posting. There are five “None” placeholders. However, only four variables (including the input) are expected as per this output when I pass only the input for the arguments:

When I provided the four arguments, with the last three as specified in the error message, then I got all tests passed.
So I guess there is an extra “None” placeholder there, which is confusing. I request the team to remove it.
One more note: It seems unclear what all arguments to pass into the function call until that error message came. Some questions I faced were: “Do I have to pass only the look_ahead_mask or the padding_mask? Or both?” Plus, due to the five “None”'s I also thought “Do I need to pass the enc_output twice (for the key and value arguments) or only once?”

However, it gets weirder. When I reach Exercise 8, I get similar fault and thanks to the error message in this post , I am able to get the correct arguments. Oddly enough, he has put all five arguments. I notice an extra “training” argument. So I ran two implementations - one where self.decoder(...) has got four arguments by excluding the training and other where self.decoder(...) has got all five arguments by including the training variable. And both implementations give “All tests passed”! I went back to Exercise 7 and tried similar thing with the self.dec_layers[i](...) and same thing happens!

I guess that the tests do not take into account whether the training parameter has been passed or not.

Do these hints help?

  1. When you invoke layer(…), the corresponding layer.call instance method gets invoked.
  2. Each of self.dec_layers[i] is an instance of DecoderLayer class.

Yeah they do. But were these hints mentioned in the notebook?

Plus, shouldn’t the tests make it compulsory for the training parameter to be set?

Thanks for bringing this up.
I don’t see the explanation inside the notebook about call. The staff have now been asked to add a note about this.

Please don’t worry about the tests not having full coverage of your code. If you have the training flag available as a function parameter, pass it to layers where applicable.

2 Likes

The “call” method is an essential part of Python objects. The course doesn’t teach that, it just emerges by surprise in Week 4.

It’s a good idea to have some additional background references added to the notebook.

1 Like