Training = training in C4W2 lab 1

I saw what I thought was a weird looking piece of code in this lab:

X = BatchNormalization(axis = 3)(X, training = training)

In particular, the part “training = training” seemed weird to me. After looking carefully at the documentation, I realized that “training” is a boolean-valued call input argument to BathNormalization which specifies if the layer should behave in training or inference mode, and can be True (for training) or False (for inference / prediction). What threw me is that the lab used an identical name, “training” for the value of the variable here, which in other languages or contexts would be a nonstandard approach since it can lead to confusion or hard to debug errors.

So, my question: is this “same naming” actually standard practice in Python or TensorFlow? Perhaps because Python allows (or requires) that we specify the argument name when assigning a calling value? If so, perhaps a note in the lab would be useful:
“Note that when you see “training=training” Q that the first “training” refers to the calling argument mentioned in the documentation, and the second “training” refers to the value we set for it, which we also just happen to call “training.” In this particular example, the second training is set to “True” by default in the function defined in this code block.”

Yes, it appears to be. You’ll see variables that duplicate parameter names quite a bit.
Yes, it’s confusing at first glance.

1 Like