DLS 1, Week2 Prog Assignment Python Basics and Numpy - Autograder

There are 9 exercises. I completed all and all were correct. Running Validate confirmed that. I can provide ipnb file if required. However, auto-grader grade was less than full score.

What am I misisng?

Can I send my solution? or would that violate some code?

Thanks

Passing the tests in the notebook is not a guarantee of full correctness. There are various ways to “hard-code” things that manage to pass the tests in the notebook, but fail the grader. E.g, one such error is to reference global variables instead of the parameters actually passed in. If they happen to be the same, you pass the tests, but fail the grader.

Publishing your code is against the rules. But you can show us a screenshot of what the grader results say. Please click “Show grader output” first. Does it tell you which functions did not get the full score?

I have tried to be mindful about hard coding, global reference etc. In fact after every test iy says: All tests passed.

This is what the auto-grader says in grader output:

Tests failed on 1 cell(s)! These tests could be hidden. Please check your submission.

Please check your DMs for a message from me about how to proceed here.

Hi @dds,

Your issue lies in Ex 7, which is the softmax function.

For x_sum, you are ignoring a very important instruction:

Create a vector x_sum that sums each row of x_exp. Use np.sum(…, axis = 1, keepdims = True)

You are not passing in the keepdims parameter. So basically, what you are doing is that instead of “retaining” the original dimensions, you are hard-coding the dimensions for x_sum later when you are initialising s.

The assignment unit test and autograder unit tests are different. You have hard-coded to return the answer for the assignment unit test, but since the autograder test uses a different dimension, you are failing it.

Set the keepdims and don’t hard-code your values later in s

Another important thing to mention at this point and we want you to be aware of is that DO NOT use hard-coded values in the coming assignments of this course or the ones after. You will end up failing the autograder tests. If hard-coded values will be required to use, the instructions will specifically mention it. Otherwise, pay close attention to function parameters and use those.

Best,
Mubsi

Thanks @paulinpaloalto, I had already DMed @dds and I have mentioned my findings above.

Hi, Mubsi.

Great! Thanks for taking care of that.

Cheers,
Paul

Hi @Mubsi @paulinpaloalto:

Thank you both. I did not see the instruction that already gave the soloution. Since I was not using the keepdims = True, I went around first figuring out the shapes for both arrays. Somehow I did’nt realize that I was hard coding params in reshape.

Thanks again!

There’s a “meta” lesson there that is worth calling out: if your overall methodology is to “save yourself time” by not reading the instructions carefully, that was pretty clearly not a net savings of time in this case. As you go forward through these courses, notice that the instructions in the notebooks are often pretty detailed and frequently they come within a few characters of actually writing out the solution for you.

2 Likes

Actually maybe there is one other thing worth saying: The problem is not that you used reshape, but that you specified the arguments in a hard-coded way.

Even if you missed the “keepdims” on the sum, you still could have done the reshape in a way that is “general” and not hard-coded. If you want to turn a 1D array x_sum into a column vector, you could have said:

x_sum.reshape(x_sum.shape[0], 1)

But the even better way to do that would be:

x_sum.reshape(-1, 1)

The -1 there is a special “shortcut” that reshape provides which just means “use up whatever is left here”. Well, there are also ways to use len() or size() to do that, but the -1 wins for simplicity.

1 Like