W2_A2_ graded function model error

New student. I’m working on Week 2 coding assignment and am at the

def model(X_train, Y_train, X_test, Y_test, num_iterations=2000, learning_rate=0.5, print_cost=False): cell

portion of the assignment and I can’t get this cell to run for some reason. I have refreshed the browser, re-run all cells, kernel restart and clear output, and nothing seems to be working. I know the cell isn’t running because I put the simple print command print("checking something prints" + str(1)) and nothing prints out.

As an aside, the cells related to model before the function model cell are throwing errors. I haven’t started solving the function model yet so I would expect it to throw error but perhaps this is related to my issue? Including screen shots for that too.

Thank you

Any ideas? Thank you!

The first problem is that you’ve accidentally changed the cell marked [83] into a code cell, instead of a markup cell. So the parser is trying to run the markup as though it was python, and that makes it crash.

You can fix it by:

  • left-click on that cell.
  • use the Cell menu
  • select Cell Type → Code

Then, use Kernel → Restart & Clear Output, then use Cell → Run all.

Please report back what happens then.

Thank you. I was able to address the markdown running as python issue for the cell [83] in original screen shot, but I’m still not getting the proper print texts for the model function call further down the page to display after following your instructions.

I’m also still getting an error thrown for the cell input right below (see screen shot)…I don’t think this is the same markdown issue (I’m not even able to change it from code to mark down if I wanted to).

As another note, I’m still getting old print text that has since been deleted from other cells. See screen shot. This makes me thing that somehow the new code updates are being registered (though it did update when i changed from code to markdown)

It looks like you must have deleted the code cell containing the model function, which is why you get the first error. You might want to get a fresh clean copy of the notebook and then copy over your previous work. There is a topic about how to do that on the DLS FAQ Thread.

For the second error, please realize that just typing new code in a function cell and then calling it again does nothing: it just runs the old code. You need to click “Shift-Enter” on the actual changed function in order to get the new code interpreted into the runtime image. Now that you realize this is how it works, you can easily demonstrate the effect to yourself.

thank you. is the difference between ‘calling it’ and hitting shift-enter. Isn’t hitting the run button the same as shift-enter. On another note, I was able to fix the issue by creating a clean copy of the notebook. Appreciate your help.

Yes, there are a number of way to execute cells, including using the “Cell → Run …” menu items. But the key point is just that typing code in a cell is not enough to get that code incorporated into the runtime image: you then have to actually execute that cell by one of the methods. And maybe the non-obvious point is that running a different cell that calls the first function does not “recompile” that target cell: it just runs the version of the compiled code that already exists in the runtime image.

Now that you are aware of this point, it’s easy to demonstrate it to yourself: take a function that works and purposely break it by multiplying the return value by 42, but don’t hit “Shift - Enter”. Run the test cell for that function again and it still works, right? Now click “Shift - Enter” on the newly broken function cell and try the test again. “Kaboom!”

Glad to hear you were able to get to a solution!

1 Like

I’m getting this issue again in W3 assignment…where old print commands are still rendering in my sandbox. I’m doing what you say - going through each cell from start to the last cell and it’s still running the old print screens. Sorry you seem to have provided detailed explaination but it’s still not making sense to me. In the new cell I’m preferring to it calls a function from another cell (see screen shot), but I already reran the original function cell AND ALL OTHER CELLS which also calls the original function. Again, I’m starting from the first cell to last and it’s not updating (Cell > Runn All). I also manually go through each cell by hitting SHIFT + ENTER and I’m still getting the old print screens. I’m guess I might be confused that there is a difference between Shift-Enter and the Cell > Rull Cell or if there is a difference going through manually each cell and hitting Shift-Enter versus going to the menu option Cell > Run All

Screen shot I click Run All

And I’m still getting the old print screen

Have you checked to make sure that some earlier cell is not throwing an error? If you get a syntax error from the earlier cell when you do “Cell → Run All”, then the execution stops when the exception is thrown, right? So maybe it doesn’t get as far as actually rerunning the nn_model cell and you’re literally seeing the previous output. One way to confirm that is to first click “Kernel → Restart and Clear Output” and then do “Cell → Run All” and see if your “old print screen” output from the test cell for nn_model still shows up. My bet is that nothing shows up, meaning that the execution doesn’t get that far.

ok thank you. I just created a fresh instance of the assignment and copied over my work but this is a good idea to check and now I know for future. Appreciate the fast reply.