in model_test(target)
20
21 np.random.seed(10)
—> 22 pred, W, b = model(X, Y, word_to_vec_map, 0.0025, 110)
23
24 assert W.shape == (2, 2), “W must be of shape 2 x 2”

in model(X, Y, word_to_vec_map, learning_rate, num_iterations)
54 # print(a)
55 # Add the cost using the i’th training label’s one hot representation and “A” (the output of the softmax)
—> 56 cost += -np.multiply(Y_oh[i], np.log(a[i]))
57 ### END CODE HERE ###
58

IndexError: index 2 is out of bounds for axis 0 with size 2

Hey @Kavya_Prasad,
Note that Y has a dimensionality of (m, 1), and Y_oh has a dimensionality of (m, n_y). Now, in the for-loop, we are iterating over range(m), i.e., the number of samples, but a has a dimensionality of (n_y,), i.e., the number of classes. That’s why the error.

Moreover, you don’t have to index a. Y_oh[i] is a vector and a is also a vector, and since Y_oh[i] only contains a single one and the rest are zeroes, hence, the rest of the products will be 0 by themselves. Let us know if this helps.

Thanks for the tip! Unfortunately I’m still facing errors, and I’m confused because I’ve gone over my code multiple times and cannot see what is wrong with it. Here’s what I’m using:

in model_test(target)
20
21 np.random.seed(10)
—> 22 pred, W, b = model(X, Y, word_to_vec_map, 0.0025, 110)
23
24 assert W.shape == (2, 2), “W must be of shape 2 x 2”

in model(X, Y, word_to_vec_map, learning_rate, num_iterations)
64 b = b - learning_rate * db
65
—> 66 assert type(cost) == np.float64, “Incorrect implementation of cost”
67 assert cost.shape == (), “Incorrect implementation of cost”
68

Hey @Kavya_Prasad,
The error still resides in your implementation of cost. Try to print what you are adding in the cost variable, and then you can cross-reference it against what should be added (as given in the markdown). Note that np.multiply() only performs element-wise multiplication. Additionally, note that the formulation contains a negative sign, in order to make the values (which are added in the cost) positive. But there is no negative sign in your code, where do you think that should be put? Let us know if these hints help you out.