Week 3 Assignment 1 - wrong arguments provided in model class for update_state method?

Please correct me if I’m wrong, but it looks like the arguments passed in the provided code for the model function to train_accuracy.update_state on line 70 and test_accuracy.update_state on line 88 are in the wrong order.

In both cases the prediction values are passed before the label vector, like so: train_accuracy.update_state(tf.transpose(Z3), minibatch_Y).

The TensorFlow documentation provided for the update_state method for the CategoricalAccuracy metric has its signature defined as: update_state(y_true, y_pred, sample_weight=None). They list the arguments here as labels first and predictions afterwards.

1 Like

Interesting! Yes, you are right that the code as written is wrong. But I tried fixing this bug and get the same results. One wonders if maybe the underlying code is clever enough to work either way? Well, the other possibility is that my experiment is somehow flawed. I will investigate in more detail and file a bug against the notebook. Even if it turns out not to matter, it’s bad form to write code that looks wrong.

Just from reading the TF docpage that you point out, they talk about using argmax on the prediction values, so that it doesn’t matter if you pass logits or activation values. Maybe they do argmax on both arguments and then it wouldn’t matter which order you specified the arguments.

Thanks very much for catching this!

Thanks for the reply and checking it out! Like you say about the use of argmax, it’s neat how they constructed this defensively for scenarios like this.