C5-W4 Error in position embedding function call

Function Encoder was throwing an error when self.pos_encoding was invoked in ‘call’. I had to directly use positional_encoding(…) inside ‘call’ to make it work. Please check if there is a genuine error.

hi @Gireesh.Rajendran

Please share a screenshot of the error you are encountering without sharing any part of grade cell codes.

Regards
DP

You should not have to do that, of course. Note that they gave you the code to invoke positional_encoding in the __init__ method to create self.pos_encoding. Please read over the code in __init__ to see what is done there. One thing to keep in mind is the types of the various objects that are created there. self.pos_encoding is a tensor, but self.embedding is a function, right? You must invoke it with an input.

But if the above suggestions don’t help, then the next step is what Deepti just mentioned: please show us the error trace you are getting. Note that we do not have the magic superpower to just look at your notebook. Or if your question is “are the tests broken”, the answer is “they work fine for me”. :nerd_face:

These courses have been in operation for several years and have been taken by literally thousands of students before you, so they are pretty well debugged by this point. It’s not impossible that you’ve discovered some new subtle bug that no-one before you has tripped over, but the probability of that is pretty low. So your first assumption when you hit a problem like this should be “I need to debug my code a bit more”. :smile:

Courtesy of the late, great Rear Admiral Grace Hopper :grin:

2 Likes

Here is the error when self.pos_encoding was invoked in ‘call’. - I was able to work around by directly use positional_encoding(…) inside ‘call’.

I have added the error message above that was flagged when self.pos_encoding was invoked in ‘call’. For now, I directly invoked positional_encoding(…) inside ‘call’ to make it work.

Are you sure you didn’t modify code that was outside the “YOUR CODE HERE” segments?

If you’ve gotten things to work and pass the tests, maybe this isn’t worth spending more mental energy on, but I did not have to make the change that you describe in order to get this to work.

So one strategy is just to cruise ahead and work through the rest of the assignment and hope that there are no other ill effects further down the line from your different implementation strategy.

@Gireesh.Rajendran

we need to see the complete error, not just the header or footer of error description, also as mentioned by other mentor, editing any part outside of marker ###START AND END CODE HERE### might resolve your respective exercise unittest but can cause either failure of further down the test cell or failure of your submission grade.

Regards
DP

@paulinpaloalto, @Deepti_Prasad I did not modify any code outside “START CODE HERE” and “END CODE HERE”.

Yes, I was able to complete the entire programming assignment yesterday itself with the modified strategy to directly invoke positional_encoding(…) inside ‘call’. Thought of posting this error for the benefit of others who may encounter the same.

Happy to see such a helpful community. Gained good insights into deep learning by completing this 5 course series - link

1 Like

That should not be required. Somewhere in your code, you’re making two offsetting mistakes.

Congratulations on completing all 5 courses! It’s great to hear that you found them useful. There is quite a lot of interesting material there and Prof Ng does a really excellent job of presenting it all (IMO anyway).