Fit() function dimensional error

This is with ref to Course “Training Feed Forward Networks”
While implementing the final python exercise,
While training FFNNs we provide inputs in which each example is a row vector
dimensions are:
i.e a single example -> (1,2)
N examples -> ( N,2)

But what if I try giving each example as a column vector i.e
single example -> (2,1)
N examples -> (2,N)

Then also changed the o/p from row vector -> column vector
(N,4) -> (4,N)

I have made all necessary changes in the forward_pass function changing formulas and orders to keep the dimensions correct as per the changes in input and output

But I am unable to understand what changes do I need to make in order to overcome this error
Maybe I need to make changes in the way input is read i.e the zip(X,Y) function
Please provide insights

Link to notebook if required:

To be very precise how to let the function know that it needs to access each column for a particular example rather than rows

1 Like

If you dont transpose, ZIP will pick up x values correctly (x1 and x2). You don’t need to transpose the data.

X_train = X_train.T
X_val = X_val.T
Y_OH_train = Y_OH_train.T
Y_OH_val = Y_OH_val.T

self.Z1 = np.matmul(self.W1, x) + self.B1                     #  (2 , 2) * (2 , N) + (2 , N) -> (2 , N)
self.A1 = self.sigmoid(self.Z1)                               # g(2 , N)                     -> (2 , N)
self.Z2 = np.matmul(self.W2, self.A1) + self.B2               #  (4 , 2) * (2 , N) + (4 , N) -> (4 , N)
self.A2 = self.softmax(self.Z2)                               # g(4 , N)                     -> (4 , N)

I need to transpose the data

I even tried it without applying transpose but that too does not seem to work :frowning:

In the original post (containing the error screenshot), there is this code:

  dw1, dw2, dw3, dw4, dw5, dw6, dw7, dw8, dw9, dw10, dw11, dw12, db1, db2, db3, db4, db5, db6  = [0]*18
  for x, y in zip(X, Y):
    self.grad(x, y)

This is in fit function which is basically the entry point. Here zip function is iterating over rows of X( containg x1 and x2) and Y. If you transpose X, zip` can not longer pick x1 and x2 as required(row in original x).

These errors will need to be handled separately. If you need transpose to resolve these new errors, you can do it there itelf in the associated equation (where it is needed).

1 Like

Yes got it I think this should do it , thank you ! xD