TensorFlow model question

I have some questions about the execution of the TensorFlow model. When the forward_propagation function is called as input it sets the transpose of X. Why is that?

Second question. The tf.dataset.batch function when I was testing divides the data set by the rows. Shouldn’t it be because of the columns? So that in this way there are fewer examples in the matrices.

Thank you very much.

Yes, this is a bit confusing. The issue is that TensorFlow always uses “samples” as the first dimension, which is why the “batch” function divides along that axis. But Prof Ng all the way through DLS C1 and up to this point has used the features x samples orientation for the input data and that’s how he does it here in the forward_propagation function. Because of that, we need to do transposes when we get to using TF to compute the loss values.

Here’s another thread which discusses this point a bit more.

1 Like

Thank you very much!

Note that once we get to DLS Course 4 about Convolutional Networks, we will be dealing with input tensors (arrays) in which each sample can have 3 or more dimensions and we’ll be using TensorFlow a lot more heavily. ConvNets can process images in their original 3D form and don’t need the kind of “unrolling” or “flattening” that we do when processing images with the simpler feed forward networks we’ve been learning about up to this point. Once we get to Course 4, Prof Ng will shift to being consistent with the TensorFlow orientation and “samples” will always be the first dimension, so we won’t need to worry about any potential inconsistency anymore.

It’s only an issue in this assignment, where we learn about TF for the very first time and get the collision of our previous methods with the new TF way of doing things.