Keyword arguments position in tensorflow

While working on the course 2, week 3 programming assignment, I finally got my compute_total_loss function to work after swapping the position of keyword arguments to the categorical_crossentropy function. But why should this matter? My understanding is that the position of keyword arguments shouldn’t matter. Are y_true and y_pred not actually keyword arguments?

To clarify,
categorical_crossentryop(y_true = foo, y_pred = bar, …)
should be the same as
categorical_crossentryop(y_pred =bar, y_true =foo, …)
Unless y_true and y_pred are not actually keyword arguments in the categorical_crossentropy definition?

Hi, @Doug_Cutrell !

Yes, they are actually keyword arguments as it is explained in the tf docs. Sounds strange, the order should not matter. What was the error you were getting?

I was getting the message “Test does not match”.
However, I just tried swapping it back and now the test works just fine. Very strange… I don’t see how I could have made a mistake before; I had worked on this a long time. But maybe I did.

Anyway, I can’t get the order dependence to make a difference now. Thanks for your rapid response.

1 Like

One thing that could have confused you is that just typing new code and then calling the function again does nothing: it simply runs the old code again. If you want to run the new code, you have to make sure to either click “Shift-Enter” on the function cell to get it interpreted or do “Kernel → Restart and Clear Output” followed by “Cell → Run All” in order to make sure the new code is actually interpreted into the runtime image.

You can easily demonstrate this effect to yourself. Take a working function and type obviously broken code into it. Then call it again. It still works. Now click “Shift-Enter” on the function cell and then call it again. Kaboom!

In other words, one theory is that your experiment that you believe convinced you that order matters was simply not a valid experiment. Kind of like Galileo proving that the speed of light was 300 mph by running an experiment with two guys with shuttered lanterns standing on watchtowers a mile apart. :laughing:

Thanks. In this case I was definitely doing “shift-enter” on the code each time, so maybe I was making some other error. Anyway, everything is working now like I expect it to.