C5_W3_A1 Ex. 2

Hello everyone, this is actually not a question, but rather sharing an answer.

It regards the function post_activation_LSTM_cell(inputs=..., initial_state=[..., ...]) , I kept getting a ValueError about inputs. It turns out that all I needed to do was restart the kernel.

I must have made an error early on, and then after fixing it, some of the objects kept updating since the first run of the code. At that point there was no help without restarting the kernel, but I didn’t know that so I went a bit crazy trying to figure out what was wrong with a perfectly good code :slight_smile:

Anyway, to whom it may concern, I hope this helps you.

2 Likes

Hi @Torp

Welcome to the community.

Thanks for your report.

best regards
elirod

1 Like

What that probably means is that you had changed one of the cells, but had not executed it by actually running that cell. If you type new code into a function cell and then call that function without actually running that cell, it simply runs the old code. You have to actually click “Shift-Enter” on the changed cell or use the “Cell → Run” menu to get the new changed code added to the runtime image. Simply calling the function again runs the old code. Doing “Kernel → Restart” is one way to force things back into a consistent state, since you then need to run all the cells again. The other way would just be to click “Cell → Run All”.

You can easily demonstrate this phenomenon to yourself. Pick a function that you know is correct. Then purposely break it: multiply one of the output values by 42 before the return statement. But DO NOT click “Shift-Enter” on the cell. Now run the test cell that checks that function and it still works, right? Then click “Shift-Enter” on the newly broken cell and then run the test cell again. Kaboom!

So the point is that you always need to be conscious of the current runtime state of the notebook. Doing “Kernel → Restart and Clear Output” followed by “Cell → Run All” or “Cell → Run All Above” is one good way to get everything back into a consistent state.

2 Likes